* Allocate an SVM pointer. * * If the allocator is coarse-grained, this will take ownership to allow * containers to correctly construct data in place. */
| 3887 | * containers to correctly construct data in place. |
| 3888 | */ |
| 3889 | pointer allocate( |
| 3890 | size_type size, |
| 3891 | typename cl::SVMAllocator<void, SVMTrait>::const_pointer = 0) |
| 3892 | { |
| 3893 | // Allocate memory with default alignment matching the size of the type |
| 3894 | void* voidPointer = |
| 3895 | clSVMAlloc( |
| 3896 | context_(), |
| 3897 | SVMTrait::getSVMMemFlags(), |
| 3898 | size*sizeof(T), |
| 3899 | 0); |
| 3900 | pointer retValue = reinterpret_cast<pointer>( |
| 3901 | voidPointer); |
| 3902 | #if defined(CL_HPP_ENABLE_EXCEPTIONS) |
| 3903 | if (!retValue) { |
| 3904 | std::bad_alloc excep; |
| 3905 | throw excep; |
| 3906 | } |
| 3907 | #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS) |
| 3908 | |
| 3909 | // If allocation was coarse-grained then map it |
| 3910 | if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) { |
| 3911 | cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T)); |
| 3912 | if (err != CL_SUCCESS) { |
| 3913 | std::bad_alloc excep; |
| 3914 | throw excep; |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | // If exceptions disabled, return null pointer from allocator |
| 3919 | return retValue; |
| 3920 | } |
| 3921 | |
| 3922 | void deallocate(pointer p, size_type) |
| 3923 | { |
nothing calls this directly
no test coverage detected