From b96e6ee98d0f33b781f2524c0e3338d4077ab666 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Mon, 3 Dec 2018 07:28:44 -0800 Subject: [PATCH] Delete defunct DynamicCUDAInterface (#14621) Summary: Signed-off-by: Edward Z. Yang Pull Request resolved: https://github.com/pytorch/pytorch/pull/14621 Differential Revision: D13276723 Pulled By: ezyang fbshipit-source-id: b666b2cdf4c45ccec7c802e268878eb2f3e028aa --- aten/src/ATen/cuda/detail/CUDAHooks.cpp | 38 ----------------------------- aten/src/ATen/detail/CUDAHooksInterface.cpp | 24 ------------------ aten/src/ATen/detail/CUDAHooksInterface.h | 12 --------- 3 files changed, 74 deletions(-) diff --git a/aten/src/ATen/cuda/detail/CUDAHooks.cpp b/aten/src/ATen/cuda/detail/CUDAHooks.cpp index 52b32bb..d00aff4 100644 --- a/aten/src/ATen/cuda/detail/CUDAHooks.cpp +++ b/aten/src/ATen/cuda/detail/CUDAHooks.cpp @@ -25,44 +25,6 @@ namespace at { namespace cuda { namespace detail { -namespace { - -void check_status(int32_t status) { - AT_CHECK( - static_cast(status) == cudaSuccess, - "CUDA error (", - static_cast(status), - "): ", - cudaGetErrorString(static_cast(status))); -} - -void set_device(int32_t device) { - check_status(cudaSetDevice(device)); -} - -void get_device(int32_t* device) { - check_status(cudaGetDevice(device)); -} - -void unchecked_set_device(int32_t device) { - const auto return_code = cudaSetDevice(device); - (void)return_code; -} - -struct DynamicCUDAInterfaceSetter { - DynamicCUDAInterfaceSetter() { - using at::detail::DynamicCUDAInterface; - DynamicCUDAInterface::set_device = set_device; - DynamicCUDAInterface::get_device = get_device; - DynamicCUDAInterface::unchecked_set_device = unchecked_set_device; - } -}; - -// Single, global, static (because of the anonymous namespace) instance, whose -// constructor will set the static members of `DynamicCUDAInterface` to CUDA -// functions when the ATen CUDA library is loaded. -DynamicCUDAInterfaceSetter _; -} // namespace // NB: deleter is dynamic, because we need it to live in a separate // compilation unit (alt is to have another method in hooks, but diff --git a/aten/src/ATen/detail/CUDAHooksInterface.cpp b/aten/src/ATen/detail/CUDAHooksInterface.cpp index cbbd90b..0451c74 100644 --- a/aten/src/ATen/detail/CUDAHooksInterface.cpp +++ b/aten/src/ATen/detail/CUDAHooksInterface.cpp @@ -9,30 +9,6 @@ namespace at { namespace detail { -void default_set_device(int32_t) { - AT_ERROR( - "DynamicCUDAInterface::set_device called " - "before CUDA library was loaded"); -} - -void default_get_device(int32_t*) { - AT_ERROR( - "DynamicCUDAInterface::get_device called " - "before CUDA library was loaded"); -} - -void default_unchecked_set_device(int32_t) { - AT_ERROR( - "DynamicCUDAInterface::unchecked_set_device called " - "before CUDA library was loaded"); -} - -// Default the static members of DynamicCUDAInterface. -void (*DynamicCUDAInterface::set_device)(int32_t) = default_set_device; -void (*DynamicCUDAInterface::get_device)(int32_t*) = default_get_device; -void (*DynamicCUDAInterface::unchecked_set_device)(int32_t) = - default_unchecked_set_device; - const CUDAHooksInterface& getCUDAHooks() { static std::unique_ptr cuda_hooks; // NB: The once_flag here implies that if you try to call any CUDA diff --git a/aten/src/ATen/detail/CUDAHooksInterface.h b/aten/src/ATen/detail/CUDAHooksInterface.h index 4942fc2..c72b94a 100644 --- a/aten/src/ATen/detail/CUDAHooksInterface.h +++ b/aten/src/ATen/detail/CUDAHooksInterface.h @@ -138,17 +138,5 @@ C10_DECLARE_REGISTRY(CUDAHooksRegistry, CUDAHooksInterface, CUDAHooksArgs); namespace detail { CAFFE2_API const CUDAHooksInterface& getCUDAHooks(); - -/// This class exists to let us access `cudaSetDevice`, `cudaGetDevice` and CUDA -/// error handling functions, when CUDA is available. These functions will first -/// default to no-ops. When the `ATen` GPU library is loaded, they will be set to -/// the `cudaSetDevice`/`cudaGetDevice` functions. This allows us to access them -/// with only a single pointer indirection, while virtual dispatch would require -/// two (one for the virtual call, one for `cudaSetDevice`/`cudaGetDevice`). -struct CAFFE2_API DynamicCUDAInterface { - static void (*set_device)(int32_t); - static void (*get_device)(int32_t*); - static void (*unchecked_set_device)(int32_t); -}; } // namespace detail } // namespace at -- 2.7.4