Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix synchronization in ContextState test [13.0.x] #40864

Merged
merged 1 commit into from
Feb 24, 2023
Merged
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
39 changes: 25 additions & 14 deletions HeterogeneousCore/CUDACore/test/test_ScopedContext.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "catch.hpp"

#include "CUDADataFormats/Common/interface/Product.h"
#include "FWCore/Concurrency/interface/FinalWaitingTask.h"
#include "FWCore/Concurrency/interface/WaitingTask.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
Expand All @@ -16,6 +17,9 @@

#include "test_ScopedContextKernels.h"

#include "oneapi/tbb/task_arena.h"
#include "oneapi/tbb/task_group.h"

namespace cms::cudatest {
class TestScopedContext {
public:
Expand Down Expand Up @@ -71,20 +75,27 @@ TEST_CASE("Use of cms::cuda::ScopedContext", "[CUDACore]") {
}

SECTION("Storing state in cms::cuda::ContextState") {
cms::cuda::ContextState ctxstate;
{ // acquire
std::unique_ptr<cms::cuda::Product<int>> dataPtr = ctx.wrap(10);
const auto& data = *dataPtr;
tbb::task_group group;
edm::WaitingTaskWithArenaHolder dummy{group, edm::make_waiting_task([](std::exception_ptr const* iPtr) {})};
cms::cuda::ScopedContextAcquire ctx2{data, std::move(dummy), ctxstate};
}

{ // produce
cms::cuda::ScopedContextProduce ctx2{ctxstate};
REQUIRE(cms::cuda::currentDevice() == ctx.device());
REQUIRE(ctx2.stream() == ctx.stream());
}
oneapi::tbb::task_arena arena(1);
arena.execute([&ctx]() {
cms::cuda::ContextState ctxstate;
{ // acquire
std::unique_ptr<cms::cuda::Product<int>> dataPtr = ctx.wrap(10);
const auto& data = *dataPtr;
oneapi::tbb::task_group group;
edm::FinalWaitingTask waitTask{group};
{
edm::WaitingTaskWithArenaHolder dummy{group, &waitTask};
cms::cuda::ScopedContextAcquire ctx2{data, dummy, ctxstate};
}
waitTask.wait();
}

{ // produce
cms::cuda::ScopedContextProduce ctx2{ctxstate};
REQUIRE(cms::cuda::currentDevice() == ctx.device());
REQUIRE(ctx2.stream() == ctx.stream());
}
});
}

SECTION("Joining multiple CUDA streams") {
Expand Down