1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_SVM_HPP
12 #define BOOST_COMPUTE_SVM_HPP
14 #include <boost/compute/config.hpp>
15 #include <boost/compute/context.hpp>
16 #include <boost/compute/memory/svm_ptr.hpp>
18 // svm functions require OpenCL 2.0
19 #if defined(CL_VERSION_2_0) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
24 /// Allocates a shared virtual memory (SVM) buffer.
26 /// \opencl_version_warning{2,0}
28 /// \see_opencl2_ref{clSVMAlloc}
32 inline svm_ptr<T> svm_alloc(const context &context,
34 cl_svm_mem_flags flags = CL_MEM_READ_WRITE,
35 unsigned int alignment = 0)
38 clSVMAlloc(context.get(), flags, size * sizeof(T), alignment),
42 BOOST_THROW_EXCEPTION(opencl_error(CL_MEM_OBJECT_ALLOCATION_FAILURE));
47 /// Deallocates a shared virtual memory (SVM) buffer.
49 /// \opencl_version_warning{2,0}
51 /// \see_opencl2_ref{clSVMFree}
53 /// \see svm_alloc(), command_queue::enqueue_svm_free()
55 inline void svm_free(svm_ptr<T> ptr)
57 clSVMFree(ptr.get_context(), ptr.get());
62 inline void svm_free(const context &context, svm_ptr<T> ptr)
64 clSVMFree(context.get(), ptr.get());
67 } // end compute namespace
68 } // end boost namespace
70 #endif // CL_VERSION_2_0
72 #endif // BOOST_COMPUTE_PIPE_HPP