]>
Commit | Line | Data |
---|---|---|
1 | //---------------------------------------------------------------------------// | |
2 | // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com> | |
3 | // | |
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 | |
7 | // | |
8 | // See http://boostorg.github.com/compute for more information. | |
9 | //---------------------------------------------------------------------------// | |
10 | ||
11 | #ifndef BOOST_COMPUTE_EXPERIMENTAL_MALLOC_HPP | |
12 | #define BOOST_COMPUTE_EXPERIMENTAL_MALLOC_HPP | |
13 | ||
14 | #include <boost/compute/buffer.hpp> | |
15 | #include <boost/compute/system.hpp> | |
16 | #include <boost/compute/context.hpp> | |
17 | #include <boost/compute/detail/device_ptr.hpp> | |
18 | ||
19 | namespace boost { | |
20 | namespace compute { | |
21 | namespace experimental { | |
22 | ||
23 | // bring device_ptr into the experimental namespace | |
24 | using detail::device_ptr; | |
25 | ||
26 | template<class T> | |
27 | inline device_ptr<T> | |
28 | malloc(std::size_t size, const context &context = system::default_context()) | |
29 | { | |
30 | buffer buf(context, size * sizeof(T)); | |
31 | clRetainMemObject(buf.get()); | |
32 | return device_ptr<T>(buf); | |
33 | } | |
34 | ||
35 | inline device_ptr<char> | |
36 | malloc(std::size_t size, const context &context = system::default_context()) | |
37 | { | |
38 | return malloc<char>(size, context); | |
39 | } | |
40 | ||
41 | template<class T> | |
42 | inline void free(device_ptr<T> &ptr) | |
43 | { | |
44 | clReleaseMemObject(ptr.get_buffer().get()); | |
45 | } | |
46 | ||
47 | } // end experimental namespace | |
48 | } // end compute namespace | |
49 | } // end boost namespace | |
50 | ||
51 | #endif // BOOST_COMPUTE_EXPERIMENTAL_MALLOC_HPP |