Skip to content

Commit

Permalink
Since we require CUDART 11.2+ remove all conditional usages
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmaynard committed Oct 31, 2024
1 parent baf6257 commit 5f17e74
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 324 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ static void benchmark_range(benchmark::internal::Benchmark* bench)
MRFactoryFunc get_mr_factory(std::string const& resource_name)
{
if (resource_name == "cuda") { return &make_cuda; }
#ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
if (resource_name == "cuda_async") { return &make_cuda_async; }
#endif
if (resource_name == "pool") { return &make_pool; }
if (resource_name == "arena") { return &make_arena; }
if (resource_name == "binning") { return &make_binning; }
Expand All @@ -153,13 +151,11 @@ void declare_benchmark(std::string const& name)
return;
}

#ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
if (name == "cuda_async") {
BENCHMARK_CAPTURE(BM_MultiStreamAllocations, cuda_async, &make_cuda_async) //
->Apply(benchmark_range);
return;
}
#endif

if (name == "pool") {
BENCHMARK_CAPTURE(BM_MultiStreamAllocations, pool_mr, &make_pool) //
Expand Down Expand Up @@ -248,9 +244,7 @@ int main(int argc, char** argv)
resource_names.emplace_back(args["resource"].as<std::string>());
} else {
resource_names.emplace_back("cuda");
#ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
resource_names.emplace_back("cuda_async");
#endif
resource_names.emplace_back("pool");
resource_names.emplace_back("arena");
resource_names.emplace_back("binning");
Expand Down
6 changes: 0 additions & 6 deletions benchmarks/random_allocations/random_allocations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,7 @@ int main(int argc, char** argv)
std::map<std::string, MRFactoryFunc> const funcs({{"arena", &make_arena},
{"binning", &make_binning},
{"cuda", &make_cuda},
#ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
{"cuda_async", &make_cuda_async},
#endif
{"pool", &make_pool}});
auto resource = args["resource"].as<std::string>();

Expand All @@ -340,11 +338,7 @@ int main(int argc, char** argv)
std::string mr_name = args["resource"].as<std::string>();
declare_benchmark(mr_name);
} else {
#ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT
std::vector<std::string> mrs{"pool", "binning", "arena", "cuda_async", "cuda"};
#else
std::vector<std::string> mrs{"pool", "binning", "arena", "cuda"};
#endif
std::for_each(
std::cbegin(mrs), std::cend(mrs), [](auto const& mr) { declare_benchmark(mr); });
}
Expand Down
198 changes: 0 additions & 198 deletions include/rmm/detail/dynamic_load_runtime.hpp

This file was deleted.

85 changes: 85 additions & 0 deletions include/rmm/detail/runtime_async_alloc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2022-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <rmm/cuda_device.hpp>
#include <rmm/detail/export.hpp>

#include <cuda_runtime_api.h>

#include <dlfcn.h>

#include <memory>
#include <optional>

namespace RMM_NAMESPACE {
namespace detail {

/**
* @brief Determine at runtime if the CUDA driver supports the stream-ordered
* memory allocator functions.
*
* This allows RMM users to compile/link against CUDA 11.2+ and run with
* older drivers.
*/

struct runtime_async_alloc {
static bool is_supported()
{
static auto driver_supports_pool{[] {
int cuda_pool_supported{};
auto result = cudaDeviceGetAttribute(&cuda_pool_supported,
cudaDevAttrMemoryPoolsSupported,
rmm::get_current_cuda_device().value());
return result == cudaSuccess and cuda_pool_supported == 1;
}()};
return driver_supports_pool;
}

/**
* @brief Check whether the specified `cudaMemAllocationHandleType` is supported on the present
* CUDA driver/runtime version.
*
* @note This query was introduced in CUDA 11.3 so on CUDA 11.2 this function will only return
* true for `cudaMemHandleTypeNone`.
*
* @param handle_type An IPC export handle type to check for support.
* @return true if supported
* @return false if unsupported
*/
static bool is_export_handle_type_supported(cudaMemAllocationHandleType handle_type)
{
int supported_handle_types_bitmask{};
#if CUDART_VERSION >= 11030 // 11.3 introduced cudaDevAttrMemoryPoolSupportedHandleTypes
if (cudaMemHandleTypeNone != handle_type) {
auto const result = cudaDeviceGetAttribute(&supported_handle_types_bitmask,
cudaDevAttrMemoryPoolSupportedHandleTypes,
rmm::get_current_cuda_device().value());

// Don't throw on cudaErrorInvalidValue
auto const unsupported_runtime = (result == cudaErrorInvalidValue);
if (unsupported_runtime) return false;
// throw any other error that may have occurred
RMM_CUDA_TRY(result);
}
#endif
return (supported_handle_types_bitmask & handle_type) == handle_type;
}

};

} // namespace detail
} // namespace RMM_NAMESPACE
Loading

0 comments on commit 5f17e74

Please sign in to comment.