Skip to content

Commit c71b031

Browse files
committed
Do not pool failed CUDA streams
1 parent f91f636 commit c71b031

3 files changed

Lines changed: 63 additions & 1 deletion

File tree

include/nvexec/stream/common.cuh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,13 @@ namespace nv::execution
358358
{
359359
if (!borrows_stream)
360360
{
361-
std::tie(own_stream_, status_) = context_.borrow_stream();
361+
cudaStream_t stream{};
362+
std::tie(stream, status_) = context_.borrow_stream();
363+
364+
if (status_ == cudaSuccess)
365+
{
366+
own_stream_ = stream;
367+
}
362368
}
363369
}
364370

test/nvexec/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
set(nvexec_test_sources
1818
continues_on.cpp
1919
device_allocate.cpp
20+
stream_pool.cpp
2021
bulk.cpp
2122
ensure_started.cpp
2223
start_detached.cpp

test/nvexec/stream_pool.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <cuda_runtime_api.h>
2+
3+
static int test_stream_pool_create_calls{};
4+
static int test_stream_pool_destroy_calls{};
5+
6+
static cudaError_t test_stream_pool_cudaStreamCreate(cudaStream_t* stream) noexcept
7+
{
8+
++test_stream_pool_create_calls;
9+
*stream = nullptr;
10+
return cudaErrorMemoryAllocation;
11+
}
12+
13+
static cudaError_t test_stream_pool_cudaStreamDestroy(cudaStream_t) noexcept
14+
{
15+
++test_stream_pool_destroy_calls;
16+
return cudaSuccess;
17+
}
18+
19+
#define cudaStreamCreate test_stream_pool_cudaStreamCreate
20+
#define cudaStreamDestroy test_stream_pool_cudaStreamDestroy
21+
#include "nvexec/stream/common.cuh"
22+
#undef cudaStreamDestroy
23+
#undef cudaStreamCreate
24+
25+
#include <test_common/catch2.hpp>
26+
27+
namespace
28+
{
29+
TEST_CASE("stream provider does not pool a failed stream", "[cuda][stream][stream_pool]")
30+
{
31+
test_stream_pool_create_calls = 0;
32+
test_stream_pool_destroy_calls = 0;
33+
34+
{
35+
nvexec::_strm::stream_pools_t stream_pools;
36+
nvexec::_strm::context context{nullptr, nullptr, &stream_pools, nullptr};
37+
38+
{
39+
nvexec::_strm::stream_provider provider{context};
40+
REQUIRE(provider.status_ == cudaErrorMemoryAllocation);
41+
CHECK_FALSE(provider.own_stream_.has_value());
42+
}
43+
44+
{
45+
nvexec::_strm::stream_provider provider{context};
46+
CHECK(provider.status_ == cudaErrorMemoryAllocation);
47+
CHECK_FALSE(provider.own_stream_.has_value());
48+
}
49+
50+
CHECK(test_stream_pool_create_calls == 2);
51+
}
52+
53+
CHECK(test_stream_pool_destroy_calls == 0);
54+
}
55+
} // namespace

0 commit comments

Comments
 (0)