File indexing completed on 2025-01-18 09:30:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_EXPERIMENTAL_MALLOC_HPP
0012 #define BOOST_COMPUTE_EXPERIMENTAL_MALLOC_HPP
0013
0014 #include <boost/compute/buffer.hpp>
0015 #include <boost/compute/system.hpp>
0016 #include <boost/compute/context.hpp>
0017 #include <boost/compute/detail/device_ptr.hpp>
0018
0019 namespace boost {
0020 namespace compute {
0021 namespace experimental {
0022
0023
0024 using detail::device_ptr;
0025
0026 template<class T>
0027 inline device_ptr<T>
0028 malloc(std::size_t size, const context &context = system::default_context())
0029 {
0030 buffer buf(context, size * sizeof(T));
0031 clRetainMemObject(buf.get());
0032 return device_ptr<T>(buf);
0033 }
0034
0035 inline device_ptr<char>
0036 malloc(std::size_t size, const context &context = system::default_context())
0037 {
0038 return malloc<char>(size, context);
0039 }
0040
0041 template<class T>
0042 inline void free(device_ptr<T> &ptr)
0043 {
0044 clReleaseMemObject(ptr.get_buffer().get());
0045 }
0046
0047 }
0048 }
0049 }
0050
0051 #endif