| 338 | CudnnSupport::CudnnSupport(GpuExecutor* parent) : parent_(parent) {} |
| 339 | |
| 340 | port::Status CudnnSupport::Init() { |
| 341 | ScopedActivateExecutorContext context(parent_); |
| 342 | |
| 343 | // Peek at the last error to give more information in cases of errors. |
| 344 | cudaError_t cerr = cudaPeekAtLastError(); |
| 345 | if (cerr != cudaSuccess) { |
| 346 | LOG(WARNING) << "There was an error before creating cudnn handle: " |
| 347 | << cudaGetErrorName(cerr) << " : " << cudaGetErrorString(cerr); |
| 348 | } |
| 349 | |
| 350 | cudnnHandle_t cudnn_handle = nullptr; |
| 351 | const auto status = cudnnCreate(&cudnn_handle); |
| 352 | if (status == CUDNN_STATUS_SUCCESS) { |
| 353 | CudnnVersion source_version(CUDNN_MAJOR, CUDNN_MINOR, CUDNN_PATCHLEVEL); |
| 354 | |
| 355 | CudnnVersion loaded_version; |
| 356 | TF_RETURN_IF_ERROR(GetLoadedCudnnVersion(&loaded_version)); |
| 357 | if (!IsSourceCompatibleWithCudnnLibrary(source_version, loaded_version)) { |
| 358 | const string error = absl::StrCat( |
| 359 | "Loaded runtime CuDNN library: ", loaded_version.ToString(), |
| 360 | " but source was compiled with: ", source_version.ToString(), |
| 361 | ". CuDNN library major and minor version needs to match or have " |
| 362 | "higher minor version in case of CuDNN 7.0 or later version. If " |
| 363 | "using a binary install, upgrade your CuDNN library. If building " |
| 364 | "from sources, make sure the library loaded at runtime is " |
| 365 | "compatible " |
| 366 | "with the version specified during compile configuration."); |
| 367 | LOG(ERROR) << error; |
| 368 | cudnnDestroy(cudnn_handle); |
| 369 | return port::Status(port::error::INTERNAL, error); |
| 370 | } |
| 371 | |
| 372 | cudnn_.reset(new CudnnAccess(cudnn_handle)); |
| 373 | return port::Status::OK(); |
| 374 | } |
| 375 | |
| 376 | CHECK_EQ(cudnn_handle, nullptr); |
| 377 | LOG(ERROR) << "Could not create cudnn handle: " << ToString(status); |
| 378 | if (status == CUDNN_STATUS_NOT_INITIALIZED) { |
| 379 | auto result = gpu::Diagnostician::FindKernelDriverVersion(); |
| 380 | if (!result.ok()) { |
| 381 | LOG(ERROR) << "Error retrieving driver version: " |
| 382 | << cuda::DriverVersionStatusToString(result); |
| 383 | } else { |
| 384 | const auto& version = result.ValueOrDie(); |
| 385 | LOG(ERROR) << "Possibly insufficient driver version: " |
| 386 | << cuda::DriverVersionToString(version); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | return port::Status(port::error::INTERNAL, |
| 391 | absl::StrCat("cudnn library could not create a handle: ", |
| 392 | ToString(status))); |
| 393 | } |
| 394 | |
| 395 | port::StatusOr<perftools::gputools::dnn::VersionInfo> |
| 396 | CudnnSupport::GetVersion() { |