-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore errors from alpaka::enqueue() in CachingAllocator::free()
- Loading branch information
Showing
3 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
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
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
91 changes: 91 additions & 0 deletions
91
HeterogeneousCore/AlpakaInterface/test/alpaka/testBuffer.dev.cc
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include <alpaka/alpaka.hpp> | ||
|
||
#define CATCH_CONFIG_MAIN | ||
#include <catch.hpp> | ||
|
||
#include "FWCore/Utilities/interface/stringize.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/config.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h" | ||
|
||
// each test binary is built for a single Alpaka backend | ||
using namespace ALPAKA_ACCELERATOR_NAMESPACE; | ||
|
||
namespace { | ||
constexpr size_t SIZE = 32; | ||
|
||
void testDeviceSideError(Device const& device) { | ||
auto queue = Queue(device); | ||
auto buf_h = cms::alpakatools::make_host_buffer<int[]>(queue, SIZE); | ||
auto buf_d = cms::alpakatools::make_device_buffer<int[]>(queue, SIZE); | ||
alpaka::memset(queue, buf_h, 0); | ||
alpaka::memcpy(queue, buf_d, buf_h); | ||
// On the host device I don't know how to fabricate a device-side | ||
// error for which the Alpaka API calls would then throw an | ||
// exception. Therefore I just throw the std::runtime_error to | ||
// keep the caller side the same for all backends. At least the | ||
// test ensures the buffer destructors won't throw exceptions | ||
// during the stack unwinding of the thrown runtime_error. | ||
if constexpr (std::is_same_v<Device, alpaka::DevCpu>) { | ||
throw std::runtime_error("assert"); | ||
} else { | ||
auto div = cms::alpakatools::make_workdiv<Acc1D>(1, 1); | ||
alpaka::exec<Acc1D>( | ||
queue, | ||
div, | ||
[] ALPAKA_FN_ACC(Acc1D const& acc, int* data, size_t size) { | ||
for (auto index : cms::alpakatools::uniform_elements(acc, size)) { | ||
assert(data[index] != 0); | ||
} | ||
}, | ||
buf_d.data(), | ||
SIZE); | ||
alpaka::wait(queue); | ||
} | ||
} | ||
} // namespace | ||
|
||
TEST_CASE("Test alpaka buffers for the " EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE) " backend", | ||
"[" EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE) "]") { | ||
// get the list of devices on the current platform | ||
auto const& devices = cms::alpakatools::devices<Platform>(); | ||
if (devices.empty()) { | ||
FAIL("No devices available for the " EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE) " backend, " | ||
"the test will be skipped."); | ||
} | ||
|
||
SECTION("Single device buffer") { | ||
for (auto const& device : devices) { | ||
auto queue = Queue(device); | ||
auto buf = cms::alpakatools::make_device_buffer<int[]>(queue, SIZE); | ||
alpaka::memset(queue, buf, 0); | ||
alpaka::wait(queue); | ||
} | ||
} | ||
|
||
SECTION("Single host buffer") { | ||
for (auto const& device : devices) { | ||
auto queue = Queue(device); | ||
auto buf = cms::alpakatools::make_host_buffer<int[]>(queue, SIZE); | ||
buf[0] = 0; | ||
alpaka::wait(queue); | ||
} | ||
} | ||
|
||
SECTION("Host and device buffers") { | ||
for (auto const& device : devices) { | ||
auto queue = Queue(device); | ||
auto buf_h = cms::alpakatools::make_host_buffer<int[]>(queue, SIZE); | ||
auto buf_d = cms::alpakatools::make_device_buffer<int[]>(queue, SIZE); | ||
alpaka::memset(queue, buf_h, 0); | ||
alpaka::memcpy(queue, buf_d, buf_h); | ||
alpaka::wait(queue); | ||
} | ||
} | ||
|
||
SECTION("Buffer destruction after a device-side error") { | ||
for (auto const& device : devices) { | ||
REQUIRE_THROWS_AS(testDeviceSideError(device), std::runtime_error); | ||
} | ||
} | ||
} |