From 20ddd2b58d15e0da3de2840fc83215658203a18f Mon Sep 17 00:00:00 2001 From: ghostplant Date: Wed, 15 May 2019 01:22:33 +0800 Subject: [PATCH] Avoid using heavy API to query single attribution (#3179) --- src/codegen/opt/build_cuda_on.cc | 9 +++++---- src/runtime/cuda/cuda_device_api.cc | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/codegen/opt/build_cuda_on.cc b/src/codegen/opt/build_cuda_on.cc index fda239f0766f..e2a788f1bbd4 100644 --- a/src/codegen/opt/build_cuda_on.cc +++ b/src/codegen/opt/build_cuda_on.cc @@ -84,12 +84,13 @@ std::string NVRTCCompile(const std::string& code, bool include_path = false) { std::vector compile_params; std::vector param_cstrings{}; nvrtcProgram prog; - cudaDeviceProp device_prop; std::string cc = "30"; - cudaError_t e = cudaGetDeviceProperties(&device_prop, 0); + int major, minor; + cudaError_t e1 = cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, 0); + cudaError_t e2 = cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, 0); - if (e == cudaSuccess) { - cc = std::to_string(device_prop.major) + std::to_string(device_prop.minor); + if (e1 == cudaSuccess && e2 == cudaSuccess) { + cc = std::to_string(major) + std::to_string(minor); } else { LOG(WARNING) << "cannot detect compute capability from your device, " << "fall back to compute_30."; diff --git a/src/runtime/cuda/cuda_device_api.cc b/src/runtime/cuda/cuda_device_api.cc index f812156f1999..f5d660c56816 100644 --- a/src/runtime/cuda/cuda_device_api.cc +++ b/src/runtime/cuda/cuda_device_api.cc @@ -26,6 +26,7 @@ #include #include +#include #include #include "cuda_common.h" @@ -73,9 +74,10 @@ class CUDADeviceAPI final : public DeviceAPI { return; } case kDeviceName: { - cudaDeviceProp props; - CUDA_CALL(cudaGetDeviceProperties(&props, ctx.device_id)); - *rv = std::string(props.name); + std::string name(256, 0); + CUDA_DRIVER_CALL(cuDeviceGetName(&name[0], name.size(), ctx.device_id)); + name.resize(strlen(name.c_str())); + *rv = std::move(name); return; } case kMaxClockRate: {