From 315e8f3def4c3a502ef9966ad66f0e252f260f4e Mon Sep 17 00:00:00 2001 From: AI agent Date: Mon, 6 Apr 2026 15:15:42 +0000 Subject: [PATCH] Add first integration queue round-trip test --- test/CMakeLists.txt | 2 +- .../queueBufferRoundTrip.cpp | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/integ/queueBufferRoundTrip/queueBufferRoundTrip.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2994311b0..786c93c46 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -83,4 +83,4 @@ function(alpaka_add_test_target target_prefix folder) endfunction() alpaka_add_test_target(unit_test_ ${CMAKE_CURRENT_SOURCE_DIR}/unit/**) -#alpaka_add_test_target(integ_test_ ${CMAKE_CURRENT_SOURCE_DIR}/integ/**) +alpaka_add_test_target(integ_test_ ${CMAKE_CURRENT_SOURCE_DIR}/integ/**) diff --git a/test/integ/queueBufferRoundTrip/queueBufferRoundTrip.cpp b/test/integ/queueBufferRoundTrip/queueBufferRoundTrip.cpp new file mode 100644 index 000000000..2cded9e31 --- /dev/null +++ b/test/integ/queueBufferRoundTrip/queueBufferRoundTrip.cpp @@ -0,0 +1,65 @@ +/* Copyright 2026 OpenAI + * SPDX-License-Identifier: MPL-2.0 + */ + +#include + +#include +#include + +#include + +using namespace alpaka; + +using TestApis = std::decay_t; + +struct AddOffsetKernel +{ + ALPAKA_FN_ACC void operator()(auto const& acc, alpaka::concepts::IMdSpan auto data, std::uint32_t offset) const + { + for(auto idx : onAcc::makeIdxMap(acc, onAcc::worker::threadsInGrid, onAcc::range::totalFrameSpecExtent)) + data[idx.x()] += offset; + } +}; + +TEMPLATE_LIST_TEST_CASE("queue + memcpy + kernel round trip", "", TestApis) +{ + auto cfg = TestType::makeDict(); + auto deviceSpec = cfg[object::deviceSpec]; + auto exec = cfg[object::exec]; + + auto devSelector = onHost::makeDeviceSelector(deviceSpec); + if(!devSelector.isAvailable()) + { + std::cout << "No device available for " << deviceSpec.getName() << std::endl; + return; + } + + onHost::Device device = devSelector.makeDevice(0); + onHost::Queue queue = device.makeQueue(queueKind::blocking); + + constexpr Vec extent = Vec{32u}; + constexpr auto frameExtent = CVec{}; + constexpr std::uint32_t offset = 7u; + + auto hostInput = onHost::alloc(onHost::makeHostDevice(), extent); + auto deviceBuffer = onHost::alloc(device, extent); + auto hostOutput = onHost::allocHostLike(deviceBuffer); + + // This test intentionally keeps the data flow obvious: + // fill on host, copy to device, run one kernel, copy back, then validate the final values. + for(std::uint32_t i = 0; i < extent.x(); ++i) + hostInput[i] = i; + onHost::fill(queue, deviceBuffer, 99u); + + onHost::memcpy(queue, deviceBuffer, hostInput); + queue.enqueue(exec, onHost::FrameSpec{extent / frameExtent, frameExtent}, KernelBundle{AddOffsetKernel{}, deviceBuffer, offset}); + onHost::memcpy(queue, hostOutput, deviceBuffer); + onHost::wait(queue); + + for(std::uint32_t i = 0; i < extent.x(); ++i) + { + CAPTURE(i); + CHECK(hostOutput[i] == i + offset); + } +}