| 178 | } |
| 179 | |
| 180 | void CUDADevice::init() |
| 181 | { |
| 182 | cudaDeviceProp prop{}; |
| 183 | checkError(cudaGetDeviceProperties(&prop, deviceID)); |
| 184 | maxWorkGroupSize = prop.maxThreadsPerBlock; |
| 185 | subgroupSize = prop.warpSize; |
| 186 | smArch = prop.major * 10 + prop.minor; |
| 187 | |
| 188 | // Check required hardware features |
| 189 | if (!isSupported(prop)) |
| 190 | throw Exception(Error::UnsupportedHardware, "unsupported CUDA device"); |
| 191 | |
| 192 | // Print device info |
| 193 | if (isVerbose()) |
| 194 | { |
| 195 | std::cout << " Device : " << prop.name << std::endl; |
| 196 | std::cout << " Type : CUDA" << std::endl; |
| 197 | std::cout << " Arch : SM " << prop.major << "." << prop.minor << std::endl; |
| 198 | std::cout << " SMs : " << prop.multiProcessorCount << std::endl; |
| 199 | } |
| 200 | |
| 201 | #if defined(OIDN_DEVICE_CUDA_API_DRIVER) |
| 202 | // Initialize the CUDA context and make it current |
| 203 | checkError(cuDeviceGet(&deviceHandle, deviceID)); |
| 204 | checkError(cuDevicePrimaryCtxRetain(&context, deviceHandle)); |
| 205 | checkError(cuCtxPushCurrent(context)); // between enter/leave, context will be popped in leave() |
| 206 | checkError(curtn::initContext()); |
| 207 | #else |
| 208 | // Save the current CUDA device and switch to ours |
| 209 | checkError(cudaGetDevice(&prevDeviceID)); |
| 210 | if (deviceID != prevDeviceID) |
| 211 | checkError(cudaSetDevice(deviceID)); |
| 212 | #endif |
| 213 | |
| 214 | // Set device properties |
| 215 | tensorDataType = DataType::Float16; |
| 216 | weightDataType = DataType::Float16; |
| 217 | tensorLayout = TensorLayout::hwc; |
| 218 | weightLayout = TensorLayout::ohwi; |
| 219 | tensorBlockC = 8; // required by Tensor Core operations |
| 220 | |
| 221 | systemMemorySupported = prop.pageableMemoryAccess; |
| 222 | managedMemorySupported = prop.managedMemory; |
| 223 | |
| 224 | #if defined(_WIN32) |
| 225 | externalMemoryTypes = ExternalMemoryTypeFlag::OpaqueWin32 | |
| 226 | ExternalMemoryTypeFlag::OpaqueWin32KMT | |
| 227 | ExternalMemoryTypeFlag::D3D11Texture | |
| 228 | ExternalMemoryTypeFlag::D3D11TextureKMT | |
| 229 | ExternalMemoryTypeFlag::D3D11Resource | |
| 230 | ExternalMemoryTypeFlag::D3D11ResourceKMT | |
| 231 | ExternalMemoryTypeFlag::D3D12Heap | |
| 232 | ExternalMemoryTypeFlag::D3D12Resource; |
| 233 | |
| 234 | externalSemaphoreTypes = ExternalSemaphoreTypeFlag::OpaqueWin32 | |
| 235 | ExternalSemaphoreTypeFlag::OpaqueWin32KMT | |
| 236 | ExternalSemaphoreTypeFlag::D3D11Fence | |
| 237 | ExternalSemaphoreTypeFlag::D3D12Fence | |
nothing calls this directly
no test coverage detected