Commit 20ddd2b5 by ghostplant Committed by Tianqi Chen

Avoid using heavy API to query single attribution (#3179)

parent 605b5e60
...@@ -84,12 +84,13 @@ std::string NVRTCCompile(const std::string& code, bool include_path = false) { ...@@ -84,12 +84,13 @@ std::string NVRTCCompile(const std::string& code, bool include_path = false) {
std::vector<std::string> compile_params; std::vector<std::string> compile_params;
std::vector<const char*> param_cstrings{}; std::vector<const char*> param_cstrings{};
nvrtcProgram prog; nvrtcProgram prog;
cudaDeviceProp device_prop;
std::string cc = "30"; 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) { if (e1 == cudaSuccess && e2 == cudaSuccess) {
cc = std::to_string(device_prop.major) + std::to_string(device_prop.minor); cc = std::to_string(major) + std::to_string(minor);
} else { } else {
LOG(WARNING) << "cannot detect compute capability from your device, " LOG(WARNING) << "cannot detect compute capability from your device, "
<< "fall back to compute_30."; << "fall back to compute_30.";
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <dmlc/thread_local.h> #include <dmlc/thread_local.h>
#include <tvm/runtime/registry.h> #include <tvm/runtime/registry.h>
#include <cuda.h>
#include <cuda_runtime.h> #include <cuda_runtime.h>
#include "cuda_common.h" #include "cuda_common.h"
...@@ -73,9 +74,10 @@ class CUDADeviceAPI final : public DeviceAPI { ...@@ -73,9 +74,10 @@ class CUDADeviceAPI final : public DeviceAPI {
return; return;
} }
case kDeviceName: { case kDeviceName: {
cudaDeviceProp props; std::string name(256, 0);
CUDA_CALL(cudaGetDeviceProperties(&props, ctx.device_id)); CUDA_DRIVER_CALL(cuDeviceGetName(&name[0], name.size(), ctx.device_id));
*rv = std::string(props.name); name.resize(strlen(name.c_str()));
*rv = std::move(name);
return; return;
} }
case kMaxClockRate: { case kMaxClockRate: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment