Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:28

0001 #include "catch.hpp"
0002 
0003 #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
0004 #include "HeterogeneousCore/CUDAUtilities/interface/device_unique_ptr.h"
0005 #include "HeterogeneousCore/CUDAUtilities/interface/requireDevices.h"
0006 
0007 TEST_CASE("device_unique_ptr", "[cudaMemTools]") {
0008   if (not cms::cudatest::testDevices()) {
0009     return;
0010   }
0011 
0012   cudaStream_t stream;
0013   cudaCheck(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
0014 
0015   SECTION("Single element") {
0016     auto ptr = cms::cuda::make_device_unique<int>(stream);
0017     REQUIRE(ptr != nullptr);
0018   }
0019 
0020   SECTION("Reset") {
0021     auto ptr = cms::cuda::make_device_unique<int>(stream);
0022     REQUIRE(ptr != nullptr);
0023     cudaCheck(cudaStreamSynchronize(stream));
0024 
0025     ptr.reset();
0026     REQUIRE(ptr.get() == nullptr);
0027   }
0028 
0029   SECTION("Multiple elements") {
0030     auto ptr = cms::cuda::make_device_unique<int[]>(10, stream);
0031     REQUIRE(ptr != nullptr);
0032     cudaCheck(cudaStreamSynchronize(stream));
0033 
0034     ptr.reset();
0035     REQUIRE(ptr.get() == nullptr);
0036   }
0037 
0038   SECTION("Allocating too much") {
0039     constexpr size_t maxSize = 1 << 30;  // 8**10
0040     auto ptr = cms::cuda::make_device_unique<char[]>(maxSize, stream);
0041     ptr.reset();
0042     REQUIRE_THROWS(ptr = cms::cuda::make_device_unique<char[]>(maxSize + 1, stream));
0043   }
0044 
0045   cudaCheck(cudaStreamDestroy(stream));
0046 }