File indexing completed on 2025-01-18 09:30:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_SVM_HPP
0012 #define BOOST_COMPUTE_SVM_HPP
0013
0014 #include <boost/compute/config.hpp>
0015 #include <boost/compute/context.hpp>
0016 #include <boost/compute/memory/svm_ptr.hpp>
0017
0018
0019 #if defined(BOOST_COMPUTE_CL_VERSION_2_0) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
0020
0021 namespace boost {
0022 namespace compute {
0023
0024
0025
0026
0027
0028
0029
0030
0031 template<class T>
0032 inline svm_ptr<T> svm_alloc(const context &context,
0033 size_t size,
0034 cl_svm_mem_flags flags = CL_MEM_READ_WRITE,
0035 unsigned int alignment = 0)
0036 {
0037 svm_ptr<T> ptr(
0038 clSVMAlloc(context.get(), flags, size * sizeof(T), alignment),
0039 context
0040 );
0041 if(!ptr.get()){
0042 BOOST_THROW_EXCEPTION(opencl_error(CL_MEM_OBJECT_ALLOCATION_FAILURE));
0043 }
0044 return ptr;
0045 }
0046
0047
0048
0049
0050
0051
0052
0053
0054 template<class T>
0055 inline void svm_free(svm_ptr<T> ptr)
0056 {
0057 clSVMFree(ptr.get_context(), ptr.get());
0058 }
0059
0060
0061 template<class T>
0062 inline void svm_free(const context &context, svm_ptr<T> ptr)
0063 {
0064 clSVMFree(context.get(), ptr.get());
0065 }
0066
0067 }
0068 }
0069
0070 #endif
0071
0072 #endif