|
23 | 23 | #include <boost/compute/type_traits/type_definition.hpp>
|
24 | 24 | #include <boost/compute/utility/source.hpp>
|
25 | 25 |
|
| 26 | +#include "check_macros.hpp" |
| 27 | + |
26 | 28 | namespace compute = boost::compute;
|
27 | 29 |
|
28 | 30 | // example code defining an atom class
|
@@ -131,6 +133,37 @@ BOOST_AUTO_TEST_CASE(custom_kernel)
|
131 | 133 | queue.enqueue_1d_range_kernel(custom_kernel, 0, atoms.size(), 1);
|
132 | 134 | }
|
133 | 135 |
|
| 136 | +BOOST_AUTO_TEST_CASE(custom_kernel_set_struct_by_value) |
| 137 | +{ |
| 138 | + std::string source = BOOST_COMPUTE_STRINGIZE_SOURCE( |
| 139 | + __kernel void custom_kernel(Atom atom, |
| 140 | + __global float *position, |
| 141 | + __global int *number) |
| 142 | + { |
| 143 | + position[0] = atom.x; |
| 144 | + position[1] = atom.y; |
| 145 | + position[2] = atom.z; |
| 146 | + number[0] = atom.number; |
| 147 | + } |
| 148 | + ); |
| 149 | + source = compute::type_definition<chemistry::Atom>() + "\n" + source; |
| 150 | + compute::program program = |
| 151 | + compute::program::build_with_source(source, context); |
| 152 | + compute::kernel custom_kernel = program.create_kernel("custom_kernel"); |
| 153 | + |
| 154 | + chemistry::Atom atom(1.0f, 2.0f, 3.0f, 4); |
| 155 | + compute::vector<float> position(3); |
| 156 | + compute::vector<int> number(1); |
| 157 | + |
| 158 | + custom_kernel.set_arg(0, atom); |
| 159 | + custom_kernel.set_arg(1, position); |
| 160 | + custom_kernel.set_arg(2, number); |
| 161 | + queue.enqueue_task(custom_kernel); |
| 162 | + |
| 163 | + CHECK_RANGE_EQUAL(float, 3, position, (1.0f, 2.0f, 3.0f)); |
| 164 | + BOOST_CHECK_EQUAL(number.at(0), 4); |
| 165 | +} |
| 166 | + |
134 | 167 | // Creates a StructWithArray containing 'x', 'y', 'z'.
|
135 | 168 | StructWithArray make_struct_with_array(int x, int y, int z)
|
136 | 169 | {
|
|
0 commit comments