1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_STREAM_EXECUTOR_GPU_GPU_DIAGNOSTICS_H_ 17 #define TENSORFLOW_STREAM_EXECUTOR_GPU_GPU_DIAGNOSTICS_H_ 18 19 #include <tuple> 20 #include "tensorflow/stream_executor/platform/port.h" 21 22 #include "tensorflow/stream_executor/lib/statusor.h" 23 #include "tensorflow/stream_executor/platform/port.h" 24 25 namespace stream_executor { 26 namespace gpu { 27 28 // e.g. DriverVersion{346, 3, 4} 29 using DriverVersion = std::tuple<int, int, int>; 30 31 // FIXME: These functions are in stream_executor::cuda namespaces for now 32 // Will move to stream_executor::gpu namespace in the near future 33 // 34 //// Converts a parsed driver version to string form. 35 // string DriverVersionToString(DriverVersion version); 36 // 37 //// Converts a parsed driver version or status value to natural string form. 38 // string DriverVersionStatusToString(port::StatusOr<DriverVersion> version); 39 // 40 //// Converts a string of a form like "331.79" to a DriverVersion{331, 79}. 41 // port::StatusOr<DriverVersion> StringToDriverVersion(const string& value); 42 43 class Diagnostician { 44 public: 45 // Logs diagnostic information when CUDA appears to be misconfigured (e.g. is 46 // not initializing). 47 // 48 // Note: if we're running on a machine that has no GPUs, we don't want to 49 // produce very much log spew beyond saying, "looks like there's no CUDA 50 // kernel 51 // module running". 52 // 53 // Note: we use non-Google-File:: API here because we may be called before 54 // InitGoogle has completed. 55 static void LogDiagnosticInformation(); 56 57 // Given the driver version file contents, finds the kernel module version and 58 // returns it as a string. 59 // 60 // This is solely used for more informative log messages when the user is 61 // running on a machine that happens to have a libcuda/kernel driver mismatch. 62 static port::StatusOr<DriverVersion> FindKernelModuleVersion( 63 const std::string& driver_version_file_contents); 64 65 // Extracts the kernel driver version from the current host. 66 static port::StatusOr<DriverVersion> FindKernelDriverVersion(); 67 68 // Iterates through loaded DSOs with DlIteratePhdrCallback to find the 69 // driver-interfacing DSO version number. Returns it as a string. 70 static port::StatusOr<DriverVersion> FindDsoVersion(); 71 72 // Logs information about the kernel driver version and userspace driver 73 // library version. 74 static void LogDriverVersionInformation(); 75 76 private: 77 // Given the DSO version number and the driver version file contents, extracts 78 // the driver version and compares, warning the user in the case of 79 // incompatibility. 80 // 81 // This is solely used for more informative log messages when the user is 82 // running on a machine that happens to have a libcuda/kernel driver mismatch. 83 static void WarnOnDsoKernelMismatch( 84 port::StatusOr<DriverVersion> dso_version, 85 port::StatusOr<DriverVersion> kernel_version); 86 87 // Logs information about the dev nodes present on this machine: their 88 // existence, permissions, accessibility from this uid/gid. 89 static void LogDevNodeDiagnosticInformation(); 90 91 static std::string GetDevNodePath(int dev_node_ordinal); 92 93 SE_DISALLOW_COPY_AND_ASSIGN(Diagnostician); 94 }; 95 96 } // namespace gpu 97 } // namespace stream_executor 98 99 #endif // TENSORFLOW_STREAM_EXECUTOR_GPU_GPU_DIAGNOSTICS_H_ 100