Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip async mr tests when cuda runtime/driver < 11.2 #986

Merged
merged 8 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/gpu/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ else

gpuci_logger "Running googletests"
# run gtests from librmm_tests package
for gt in "$CONDA_PREFIX/bin/gtests/librmm/*" ; do
for gt in "$CONDA_PREFIX/bin/gtests/librmm/"* ; do
${gt} --gtest_output=xml:${TESTRESULTS_DIR}/
exitcode=$?
if (( ${exitcode} != 0 )); then
Expand Down
34 changes: 28 additions & 6 deletions include/rmm/mr/device/cuda_async_memory_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,15 @@ class cuda_async_memory_resource final : public device_memory_resource {
{
#ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
// Check if cudaMallocAsync Memory pool supported
auto const device = rmm::detail::current_device();
int cuda_pool_supported{};
auto result =
cudaDeviceGetAttribute(&cuda_pool_supported, cudaDevAttrMemoryPoolsSupported, device.value());
RMM_EXPECTS(result == cudaSuccess && cuda_pool_supported,
RMM_EXPECTS(is_supported(),
"cudaMallocAsync not supported with this CUDA driver/runtime version");

// Construct explicit pool
cudaMemPoolProps pool_props{};
pool_props.allocType = cudaMemAllocationTypePinned;
pool_props.handleTypes = cudaMemHandleTypePosixFileDescriptor;
pool_props.location.type = cudaMemLocationTypeDevice;
pool_props.location.id = device.value();
pool_props.location.id = rmm::detail::current_device().value();
RMM_CUDA_TRY(cudaMemPoolCreate(&cuda_pool_handle_, &pool_props));

auto const [free, total] = rmm::detail::available_device_memory();
Expand Down Expand Up @@ -115,6 +111,32 @@ class cuda_async_memory_resource final : public device_memory_resource {
cuda_async_memory_resource& operator=(cuda_async_memory_resource const&) = delete;
cuda_async_memory_resource& operator=(cuda_async_memory_resource&&) = delete;

/**
* @brief Is cudaMallocAsync supported with this cuda runtime/driver version?
* @return true if both the cuda runtime and driver are newer than 11.2
*/
static bool is_supported()
{
#if defined(RMM_CUDA_MALLOC_ASYNC_SUPPORT)
static auto runtime_supports_pool{[] {
int runtime_version{};
RMM_CUDA_TRY(cudaRuntimeGetVersion(&runtime_version));
constexpr auto min_async_version{11020};
return runtime_version >= min_async_version;
}()};
static auto driver_supports_pool{[] {
int cuda_pool_supported{};
RMM_CUDA_TRY(cudaDeviceGetAttribute(&cuda_pool_supported,
cudaDevAttrMemoryPoolsSupported,
rmm::detail::current_device().value()));
return cuda_pool_supported == 1;
}()};
return runtime_supports_pool and driver_supports_pool;
#else
return false;
#endif
}

/**
* @brief Query whether the resource supports use of non-null CUDA streams for
* allocation/deallocation. `cuda_memory_resource` does not support streams.
Expand Down
19 changes: 15 additions & 4 deletions tests/mr/device/cuda_async_mr_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ namespace {

using cuda_async_mr = rmm::mr::cuda_async_memory_resource;

TEST(AsyncMRTest, ThrowIfNotSupported)
class AsyncMRTest : public ::testing::Test {
protected:
void SetUp() override
{
if (!rmm::mr::cuda_async_memory_resource::is_supported()) {
GTEST_SKIP() << "Skipping tests since cudaMallocAsync not supported with this CUDA "
<< "driver/runtime version";
}
}
};

TEST_F(AsyncMRTest, ThrowIfNotSupported)
{
auto construct_mr = []() { cuda_async_mr mr; };
#ifndef RMM_CUDA_MALLOC_ASYNC_SUPPORT
Expand All @@ -35,7 +46,7 @@ TEST(AsyncMRTest, ThrowIfNotSupported)
}

#if defined(RMM_CUDA_MALLOC_ASYNC_SUPPORT)
TEST(AsyncMRTest, ExplicitInitialPoolSize)
TEST_F(AsyncMRTest, ExplicitInitialPoolSize)
{
const auto pool_init_size{100};
cuda_async_mr mr{pool_init_size};
Expand All @@ -44,7 +55,7 @@ TEST(AsyncMRTest, ExplicitInitialPoolSize)
RMM_CUDA_TRY(cudaDeviceSynchronize());
}

TEST(AsyncMRTest, ExplicitReleaseThreshold)
TEST_F(AsyncMRTest, ExplicitReleaseThreshold)
{
const auto pool_init_size{100};
const auto pool_release_threshold{1000};
Expand All @@ -54,7 +65,7 @@ TEST(AsyncMRTest, ExplicitReleaseThreshold)
RMM_CUDA_TRY(cudaDeviceSynchronize());
}

TEST(AsyncMRTest, DifferentPoolsUnequal)
TEST_F(AsyncMRTest, DifferentPoolsUnequal)
{
const auto pool_init_size{100};
const auto pool_release_threshold{1000};
Expand Down
12 changes: 11 additions & 1 deletion tests/mr/device/mr_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ struct mr_test : public ::testing::TestWithParam<mr_factory> {
{
auto factory = GetParam().factory;
mr = factory();
if (mr == nullptr) {
GTEST_SKIP() << "Skipping tests since the memory resource is not supported with this CUDA "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting the GTEST_SKIP directly in the make_cuda_async doesn't work? I'm not sure what GTEST_SKIP actually does or what scope it needs to be used in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a macro that only works in a test method or SetUp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I thought it might throw an exception that gtest knows to catch or something.

<< "driver/runtime version";
}
}

std::shared_ptr<rmm::mr::device_memory_resource> mr; ///< Pointer to resource to use in tests
Expand All @@ -246,7 +250,13 @@ struct mr_allocation_test : public mr_test {
/// MR factory functions
inline auto make_cuda() { return std::make_shared<rmm::mr::cuda_memory_resource>(); }

inline auto make_cuda_async() { return std::make_shared<rmm::mr::cuda_async_memory_resource>(); }
inline auto make_cuda_async()
{
if (rmm::mr::cuda_async_memory_resource::is_supported()) {
return std::make_shared<rmm::mr::cuda_async_memory_resource>();
}
return std::shared_ptr<rmm::mr::cuda_async_memory_resource>{};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit subtle since the only difference is () vs. {}. Maybe use an explicit nullptr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

inline auto make_managed() { return std::make_shared<rmm::mr::managed_memory_resource>(); }

Expand Down