Check if the device driver version is recent enough to run the cuda libs linked with afcuda:
| 501 | // Check if the device driver version is recent enough to run the cuda libs |
| 502 | // linked with afcuda: |
| 503 | void DeviceManager::checkCudaVsDriverVersion() { |
| 504 | const std::string driverVersionString = getDriverVersion(); |
| 505 | |
| 506 | int driver = 0; |
| 507 | int runtime = 0; |
| 508 | CUDA_CHECK(cudaDriverGetVersion(&driver)); |
| 509 | CUDA_CHECK(cudaRuntimeGetVersion(&runtime)); |
| 510 | |
| 511 | AF_TRACE("CUDA Driver supports up to CUDA {} ArrayFire CUDA Runtime {}", |
| 512 | fromCudaVersion(driver), fromCudaVersion(runtime)); |
| 513 | |
| 514 | debugRuntimeCheck(getLogger(), runtime, driver); |
| 515 | |
| 516 | int runtime_major = runtime / 1000; |
| 517 | int driver_major = driver / 1000; |
| 518 | |
| 519 | if (runtime_major > driver_major) { |
| 520 | string msg = |
| 521 | "ArrayFire was built with CUDA {} which requires GPU driver " |
| 522 | "version {} or later. Please download and install the latest " |
| 523 | "drivers from https://www.nvidia.com/drivers for your GPU. " |
| 524 | "Alternatively, you could rebuild ArrayFire with CUDA Toolkit " |
| 525 | "version {} to use the current drivers."; |
| 526 | |
| 527 | auto runtime_it = |
| 528 | find_if(begin(CudaToDriverVersion), end(CudaToDriverVersion), |
| 529 | [runtime](ToolkitDriverVersions ver) { |
| 530 | return runtime == ver.version; |
| 531 | }); |
| 532 | |
| 533 | constexpr size_t buf_size = 1024; |
| 534 | // If the runtime version is not part of the CudaToDriverVersion |
| 535 | // array, display a message in the trace. Do not throw an error |
| 536 | // unless this is a debug build |
| 537 | if (runtime_it == end(CudaToDriverVersion)) { |
| 538 | char buf[buf_size]; |
| 539 | char err_msg[] = |
| 540 | "CUDA runtime version(%s) not recognized. Please create an " |
| 541 | "issue or a pull request on the ArrayFire repository to " |
| 542 | "update the CudaToDriverVersion variable with this " |
| 543 | "version of the CUDA Toolkit."; |
| 544 | snprintf(buf, buf_size, err_msg, |
| 545 | fmt::format("{}", fromCudaVersion(runtime)).c_str()); |
| 546 | AF_TRACE("{}", buf); |
| 547 | return; |
| 548 | } |
| 549 | |
| 550 | float minimumDriverVersion = |
| 551 | #ifdef OS_WIN |
| 552 | runtime_it->windows_min_version; |
| 553 | #else |
| 554 | runtime_it->unix_min_version; |
| 555 | #endif |
| 556 | |
| 557 | char buf[buf_size]; |
| 558 | fmt::format_to_n(buf, buf_size, msg, fromCudaVersion(runtime), |
| 559 | minimumDriverVersion, fromCudaVersion(driver)); |
| 560 |
nothing calls this directly
no test coverage detected