Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013 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_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 // bring device_ptr into the experimental namespace
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 } // end experimental namespace
0048 } // end compute namespace
0049 } // end boost namespace
0050 
0051 #endif // BOOST_COMPUTE_EXPERIMENTAL_MALLOC_HPP