You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2017/12/14 10:02:31 UTC

[GitHub] KellenSunderland closed pull request #8406: Fixed rtc error on Tesla / Jetson TX2

KellenSunderland closed pull request #8406: Fixed rtc error on Tesla / Jetson TX2
URL: https://github.com/apache/incubator-mxnet/pull/8406
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/common/rtc.cc b/src/common/rtc.cc
index cd26f0e05a..c89a02de94 100644
--- a/src/common/rtc.cc
+++ b/src/common/rtc.cc
@@ -18,6 +18,10 @@
  */
 
 #include <mxnet/rtc.h>
+#include <algorithm>
+#include <cassert>
+#include <locale>
+#include <sstream>
 #include <typeinfo>
 
 #include "../common/cuda_utils.h"
@@ -28,6 +32,43 @@
 namespace mxnet {
 namespace rtc {
 
+namespace {
+
+  const char* gpu_arch_prefix = "--gpu-architecture=compute_";
+  const std::locale locale;
+
+  bool FindGpuArchOption(std::string option) {
+    auto lower = [&](char c) { return std::tolower(c, locale); };
+    std::transform(option.begin(), option.end(), option.begin(), lower);
+    return option.find(gpu_arch_prefix) != std::string::npos;
+  }
+
+  void SetGpuArch(std::vector<const char *>* c_options, std::string* arch_string) {
+    assert(c_options != nullptr);
+    assert(arch_string != nullptr);
+
+    // Check options for explicit device architecture information.
+    for (const auto& option : *c_options) {
+      if (FindGpuArchOption(option)) {
+        return;
+      }
+    }
+
+    // If not present, use the first gpu device present for architecture information.
+    int num_devices;
+    CUDA_CALL(cudaGetDeviceCount(&num_devices));
+
+    if (num_devices > 0) {
+      cudaDeviceProp prop;
+      CUDA_CALL(cudaGetDeviceProperties(&prop, 0));
+      std::stringstream arch_stream;
+      arch_stream << gpu_arch_prefix << prop.major << prop.minor;
+      *arch_string = arch_stream.str();
+      c_options->push_back(arch_string->c_str());
+    }
+  }
+}  // namespace
+
 CudaModule::Chunk::Chunk(
     const char* source,
     const std::vector<std::string>& options,
@@ -46,6 +87,9 @@ CudaModule::Chunk::Chunk(
 #endif
   std::vector<const char*> c_options;
   for (const auto& i : options) c_options.push_back(i.c_str());
+  std::string arch_string;
+  SetGpuArch(&c_options, &arch_string);
+
   nvrtcResult compile_res = nvrtcCompileProgram(prog_, c_options.size(), c_options.data());
   if (compile_res != NVRTC_SUCCESS) {
     size_t err_size;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services