Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/**)
65 changes: 65 additions & 0 deletions test/integ/queueBufferRoundTrip/queueBufferRoundTrip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Copyright 2026 OpenAI
* SPDX-License-Identifier: MPL-2.0
*/

#include <alpaka/alpaka.hpp>

#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>

#include <iostream>

using namespace alpaka;

using TestApis = std::decay_t<decltype(onHost::allBackends(onHost::enabledApis, exec::enabledExecutors))>;

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<std::uint32_t, 8u>{};
constexpr std::uint32_t offset = 7u;

auto hostInput = onHost::alloc<std::uint32_t>(onHost::makeHostDevice(), extent);
auto deviceBuffer = onHost::alloc<std::uint32_t>(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);
}
}