Last active
February 21, 2020 15:52
-
-
Save sschaetz/155de719c8822698d554bafe687a65f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boost::aura::environment e; | |
boost::aura::device d(AURA_UNIT_TEST_DEVICE, e); | |
boost::aura::feed f(d); | |
boost::aura::library l( | |
boost::aura::path( | |
get_kernel_dir() + "/kernels.al" | |
), | |
d); | |
boost::aura::kernel k("add", l); | |
const std::size_t num_el = 128; | |
std::vector<float> a(num_el, 2.0f); | |
std::vector<float> b(num_el, 3.0f); | |
std::vector<float> c(num_el, 0.0f); | |
std::vector<float> expected(num_el, 2.0f + 3.0f); | |
boost::aura::device_array<float> a_device(num_el, d); | |
boost::aura::device_array<float> b_device(num_el, d); | |
boost::aura::device_array<float> c_device(num_el, d); | |
boost::aura::copy(a.begin(), a.end(), a_device.begin(), f); | |
boost::aura::copy(b.begin(), b.end(), b_device.begin(), f); | |
boost::aura::copy(c.begin(), c.end(), c_device.begin(), f); | |
auto kernel_instance = boost::aura::kernel_instance<3>( | |
k, | |
boost::aura::mesh({{num_el, 1, 1}}), | |
boost::aura::bundle({{1, 1, 1}}), | |
f | |
); | |
kernel_instance.invoke( | |
boost::aura::args( | |
a_device.get_base_ptr(), | |
b_device.get_base_ptr(), | |
c_device.get_base_ptr() | |
) | |
); | |
boost::aura::copy(c_device.begin(), c_device.end(), c.begin(), f); | |
boost::aura::wait_for(f); | |
assert(std::equal(expected.begin(), expected.end(), c.begin())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment