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 4 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
28 changes: 22 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,26 @@ 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()
{
static auto runtime_version{[] {
Copy link
Member

Choose a reason for hiding this comment

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

Convince me that this isn't sufficient.

Suggested change
static auto runtime_version{[] {
static bool is_supported()
{
#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());
return result == cudaSuccess and cuda_pool_supported;
#else
return false;
#endif
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can compile with a newer cuda toolkit but run in an older runtime, then you'd get a symbol not found error.

Copy link
Member

Choose a reason for hiding this comment

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

Which symbol would not be found? cudaDeviceAttribute will exist on all CUDA versions we support.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cudaDevAttrMemoryPoolsSupported

Copy link
Member

Choose a reason for hiding this comment

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

Once compiled that would be a value compiled into our binary that would get passed to the API, wouldn't it? Not a symbol.

Copy link
Member

Choose a reason for hiding this comment

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

Pretty sure this code already works in the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm actually I think it's just the check doesn't work (build with cuda 11.6, run with 11.0):

./gtests/CUDA_ASYNC_MR_TEST: symbol lookup error: ./gtests/CUDA_ASYNC_MR_TEST: undefined symbol: cudaMemPoolCreate, version libcudart.so.11.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I printed out the value of cuda_pool_supported, it's actually 1 when running under 11.0.

int runtime_version{};
RMM_CUDA_TRY(cudaRuntimeGetVersion(&runtime_version));
return runtime_version;
}()};
static auto driver_version{[] {
int driver_version{};
RMM_CUDA_TRY(cudaDriverGetVersion(&driver_version));
return driver_version;
}()};
constexpr auto min_async_version{11020};
return runtime_version >= min_async_version && driver_version >= min_async_version;
}

/**
* @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
4 changes: 4 additions & 0 deletions tests/mr/device/mr_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ struct mr_factory {
struct mr_test : public ::testing::TestWithParam<mr_factory> {
void SetUp() override
{
if (GetParam().name == "CUDA_Async" && !rmm::mr::cuda_async_memory_resource::is_supported()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be more robust to put it in the make_async factory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would it return?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is better, but please take a look.

GTEST_SKIP() << "Skipping tests since cudaMallocAsync not supported with this CUDA "
<< "driver/runtime version";
}
auto factory = GetParam().factory;
mr = factory();
}
Expand Down