| 108 | |
| 109 | #ifdef WITH_CUDNN |
| 110 | unique_handle<cudnnHandle_t> *nnManager(const int deviceId) { |
| 111 | thread_local unique_handle<cudnnHandle_t> |
| 112 | cudnnHandles[DeviceManager::MAX_DEVICES]; |
| 113 | thread_local once_flag initFlags[DeviceManager::MAX_DEVICES]; |
| 114 | |
| 115 | auto *handle = &cudnnHandles[deviceId]; |
| 116 | cudnnStatus_t error = CUDNN_STATUS_SUCCESS; |
| 117 | call_once(initFlags[deviceId], [handle, &error] { |
| 118 | auto getLogger = [&] { return spdlog::get("platform"); }; |
| 119 | AF_TRACE("Initializing cuDNN"); |
| 120 | error = static_cast<cudnnStatus_t>(handle->create()); |
| 121 | |
| 122 | // Not throwing an AF_ERROR here because we are in a lambda that could |
| 123 | // be executing on another thread; |
| 124 | if (!(*handle)) { getLogger()->error("Error initalizing cuDNN"); } |
| 125 | }); |
| 126 | if (error) { |
| 127 | string error_msg = fmt::format( |
| 128 | "Error initializing cuDNN({}): {}.", |
| 129 | static_cast<std::underlying_type<cudnnStatus_t>::type>(error), |
| 130 | errorString(error)); |
| 131 | AF_ERROR(error_msg, AF_ERR_RUNTIME); |
| 132 | } |
| 133 | CUDNN_CHECK(getCudnnPlugin().cudnnSetStream(cudnnHandles[deviceId], |
| 134 | getStream(deviceId))); |
| 135 | |
| 136 | return handle; |
| 137 | } |
| 138 | #endif |
| 139 | |
| 140 | unique_ptr<PlanCache> &cufftManager(const int deviceId) { |
no test coverage detected