|
| 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