Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:05

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
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 // svm functions require OpenCL 2.0
0019 #if defined(BOOST_COMPUTE_CL_VERSION_2_0) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
0020 
0021 namespace boost {
0022 namespace compute {
0023 
0024 /// Allocates a shared virtual memory (SVM) buffer.
0025 //
0026 /// \opencl_version_warning{2,0}
0027 ///
0028 /// \see_opencl2_ref{clSVMAlloc}
0029 ///
0030 /// \see svm_free()
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 /// Deallocates a shared virtual memory (SVM) buffer.
0048 ///
0049 /// \opencl_version_warning{2,0}
0050 ///
0051 /// \see_opencl2_ref{clSVMFree}
0052 ///
0053 /// \see svm_alloc(), command_queue::enqueue_svm_free()
0054 template<class T>
0055 inline void svm_free(svm_ptr<T> ptr)
0056 {
0057     clSVMFree(ptr.get_context(), ptr.get());
0058 }
0059 
0060 /// \overload
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 } // end compute namespace
0068 } // end boost namespace
0069 
0070 #endif // BOOST_COMPUTE_CL_VERSION_2_0
0071 
0072 #endif // BOOST_COMPUTE_PIPE_HPP