forked from NVIDIA/stdexec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice_allocate.cpp
More file actions
43 lines (34 loc) · 1.02 KB
/
Copy pathdevice_allocate.cpp
File metadata and controls
43 lines (34 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <cstddef>
#include <cuda_runtime_api.h>
static int test_device_allocate_free_calls{};
static cudaError_t
test_device_allocate_cudaMemcpy(void*, void const *, std::size_t, cudaMemcpyKind) noexcept
{
return cudaErrorInvalidValue;
}
static cudaError_t test_device_allocate_cudaFree(void* ptr) noexcept
{
++test_device_allocate_free_calls;
return ::cudaFree(ptr);
}
#define cudaMemcpy test_device_allocate_cudaMemcpy
#define cudaFree test_device_allocate_cudaFree
#include "nvexec/detail/memory.cuh"
#undef cudaFree
#undef cudaMemcpy
#include <test_common/catch2.hpp>
namespace
{
TEST_CASE("device allocation frees storage when cudaMemcpy fails",
"[cuda][stream][memory][device_allocate]")
{
test_device_allocate_free_calls = 0;
cudaError_t status = cudaSuccess;
{
auto ptr = nvexec::_strm::device_allocate<int>(status, 42);
REQUIRE(status == cudaErrorInvalidValue);
REQUIRE(ptr == nullptr);
}
REQUIRE(test_device_allocate_free_calls == 1);
}
} // namespace