|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, NVIDIA CORPORATION. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include <rmm/cuda_stream_pool.hpp> |
| 18 | +#include <rmm/detail/error.hpp> |
| 19 | +#include <rmm/device_uvector.hpp> |
| 20 | + |
| 21 | +#include <gtest/gtest.h> |
| 22 | + |
| 23 | +#include <cuda_runtime_api.h> |
| 24 | + |
| 25 | +struct CudaStreamPoolTest : public ::testing::Test { |
| 26 | + rmm::cuda_stream_pool pool{}; |
| 27 | +}; |
| 28 | + |
| 29 | +TEST_F(CudaStreamPoolTest, Unequal) |
| 30 | +{ |
| 31 | + auto const stream_a = this->pool.get_stream(); |
| 32 | + auto const stream_b = this->pool.get_stream(); |
| 33 | + |
| 34 | + EXPECT_NE(stream_a, stream_b); |
| 35 | +} |
| 36 | + |
| 37 | +TEST_F(CudaStreamPoolTest, Nondefault) |
| 38 | +{ |
| 39 | + auto const stream_a = this->pool.get_stream(); |
| 40 | + auto const stream_b = this->pool.get_stream(); |
| 41 | + |
| 42 | + // pool streams are explicit, non-default streams |
| 43 | + EXPECT_FALSE(stream_a.is_default()); |
| 44 | + EXPECT_FALSE(stream_a.is_per_thread_default()); |
| 45 | +} |
| 46 | + |
| 47 | +TEST_F(CudaStreamPoolTest, ValidStreams) |
| 48 | +{ |
| 49 | + auto const stream_a = this->pool.get_stream(); |
| 50 | + auto const stream_b = this->pool.get_stream(); |
| 51 | + |
| 52 | + // Operations on the streams should work correctly and without throwing exceptions |
| 53 | + auto v = rmm::device_uvector<std::uint8_t>{100, stream_a}; |
| 54 | + RMM_CUDA_TRY(cudaMemsetAsync(v.data(), 0xcc, 100, stream_a.value())); |
| 55 | + stream_a.synchronize(); |
| 56 | + |
| 57 | + auto v2 = rmm::device_uvector<uint8_t>{v, stream_b}; |
| 58 | + auto x = v2.front_element(stream_b); |
| 59 | + EXPECT_EQ(x, 0xcc); |
| 60 | +} |
0 commit comments