Skip to content

Commit d8a004c

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

3 files changed

Lines changed: 75 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ set(nvexec_test_sources
4747

4848
if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC"))
4949
set_source_files_properties(${nvexec_test_sources} PROPERTIES LANGUAGE CUDA)
50+
set_source_files_properties(stream_pool.cpp PROPERTIES LANGUAGE CUDA)
5051
endif()
5152

5253
add_executable(test.nvexec ${nvexec_test_sources})
@@ -61,6 +62,18 @@ target_link_libraries(test.nvexec STDEXEC::nvexec stdexec_executable_flags
6162

6263
catch_discover_tests(test.nvexec PROPERTIES TIMEOUT 30)
6364

65+
add_executable(test.nvexec.stream_pool stream_pool.cpp test_main.cpp)
66+
set_target_properties(
67+
test.nvexec.stream_pool
68+
PROPERTIES CXX_STANDARD 20
69+
CXX_STANDARD_REQUIRED ON
70+
CXX_EXTENSIONS OFF)
71+
target_include_directories(test.nvexec.stream_pool PRIVATE ${CMAKE_CURRENT_LIST_DIR}/..)
72+
target_link_libraries(test.nvexec.stream_pool STDEXEC::nvexec stdexec_executable_flags
73+
Catch2::Catch2WithMain nvexec_executable_flags)
74+
75+
catch_discover_tests(test.nvexec.stream_pool PROPERTIES TIMEOUT 30)
76+
6477
icm_add_build_failure_test(
6578
NAME
6679
when_all_fail

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)