|
| 1 | +# This file is not included from `runtests.jl` nor run in CI. |
| 2 | +# |
| 3 | +# Run it with `julia tests/test_cuda_extension.jl`. This requires that |
| 4 | +# Julia is installed with juliaup and will involve downloading of a |
| 5 | +# lot of big artifacts. The output will contain lots of error messages |
| 6 | +# from caught errors; what matters is that all testsets pass. |
| 7 | + |
| 8 | +using Test |
| 9 | + |
| 10 | +juliaup_found = false |
| 11 | +try run(pipeline(`juliaup --version`, stdout = devnull, stderr = devnull)) |
| 12 | + global juliaup_found = true |
| 13 | +catch e |
| 14 | +end |
| 15 | + |
| 16 | +if !juliaup_found |
| 17 | + error("`juliaup` needs to be installed for the CUDA extension tests") |
| 18 | +end |
| 19 | + |
| 20 | +wait(run(`juliaup add 1.6`, wait = false)) |
| 21 | +wait(run(`juliaup add 1.9`, wait = false)) |
| 22 | + |
| 23 | +package_path = dirname(@__DIR__) |
| 24 | +onnx_path = joinpath(@__DIR__, "data", "copy2d.onnx") |
| 25 | + |
| 26 | +function with_environment(f::Function; cuda_runtime_version) |
| 27 | + mktempdir() do env |
| 28 | + write(joinpath(env, "LocalPreferences.toml"), |
| 29 | + """ |
| 30 | + [CUDA_Runtime_jll] |
| 31 | + version = "$(cuda_runtime_version)" |
| 32 | + """) |
| 33 | + write(joinpath(env, "Project.toml"), |
| 34 | + """ |
| 35 | + [extras] |
| 36 | + CUDA_Runtime_jll = "76a88914-d11a-5bdc-97e0-2f5a05c973a2" |
| 37 | + """) |
| 38 | + f(env) |
| 39 | + end |
| 40 | +end |
| 41 | + |
| 42 | +@testset "Julia 1.6 CUDA 3" begin |
| 43 | + with_environment(cuda_runtime_version = "11.8") do env |
| 44 | + install_script = """ |
| 45 | + using Pkg |
| 46 | + Pkg.develop(path = "$(package_path)") |
| 47 | + Pkg.add(name = "CUDA", version = "3") |
| 48 | + """ |
| 49 | + @test success(run(`julia +1.6 --project=$(env) -e "$(install_script)"`)) |
| 50 | + # Correct dependency for :cuda. |
| 51 | + test_script = """ |
| 52 | + using ONNXRunTime, CUDA |
| 53 | + load_inference("$(onnx_path)", execution_provider = :cuda) |
| 54 | + """ |
| 55 | + @test success(run(`julia +1.6 --project=$(env) -e "$(test_script)"`)) |
| 56 | + # CUDA not loaded. |
| 57 | + test_script = """ |
| 58 | + using ONNXRunTime |
| 59 | + load_inference("$(onnx_path)", execution_provider = :cuda) |
| 60 | + """ |
| 61 | + @test_throws ProcessFailedException run(`julia +1.6 --project=$(env) -e "$(test_script)"`) |
| 62 | + # CUDA not loaded but running on CPU, so it's fine. |
| 63 | + test_script = """ |
| 64 | + using ONNXRunTime |
| 65 | + load_inference("$(onnx_path)", execution_provider = :cpu) |
| 66 | + """ |
| 67 | + @test success(run(`julia +1.6 --project=$(env) -e "$(test_script)"`)) |
| 68 | + end |
| 69 | +end |
| 70 | + |
| 71 | +@testset "Julia 1.9 CUDA 3" begin |
| 72 | + with_environment(cuda_runtime_version = "11.8") do env |
| 73 | + install_script = """ |
| 74 | + using Pkg |
| 75 | + Pkg.develop(path = "$(package_path)") |
| 76 | + Pkg.add(name = "CUDA", version = "3") |
| 77 | + """ |
| 78 | + # CUDA 3 is not possible to install together with ONNXRunTime |
| 79 | + # on Julia 1.9 due to Compat requirements. |
| 80 | + @test_throws ProcessFailedException run(`julia +1.9 --project=$(env) -e "$(install_script)"`) |
| 81 | + end |
| 82 | +end |
| 83 | + |
| 84 | +@testset "Julia 1.9 CUDA.jl $(cuda_version) CUDA runtime 11.8" for cuda_version in (4, 5) |
| 85 | + with_environment(cuda_runtime_version = "11.8") do env |
| 86 | + install_script = """ |
| 87 | + using Pkg |
| 88 | + Pkg.develop(path = "$(package_path)") |
| 89 | + Pkg.add(name = "CUDA", version = "$(cuda_version)") |
| 90 | + Pkg.add(name = "cuDNN") |
| 91 | + """ |
| 92 | + @test success(run(`julia +1.9 --project=$(env) -e "$(install_script)"`)) |
| 93 | + # Correct dependencies for :cuda. |
| 94 | + test_script = """ |
| 95 | + using ONNXRunTime, CUDA, cuDNN |
| 96 | + load_inference("$(onnx_path)", execution_provider = :cuda) |
| 97 | + """ |
| 98 | + @test success(run(`julia +1.9 --project=$(env) -e "$(test_script)"`)) |
| 99 | + # Neither CUDA nor cuDNN loaded. |
| 100 | + test_script = """ |
| 101 | + using ONNXRunTime |
| 102 | + load_inference("$(onnx_path)", execution_provider = :cuda) |
| 103 | + """ |
| 104 | + @test_throws ProcessFailedException run(`julia +1.9 --project=$(env) -e "$(test_script)"`) |
| 105 | + # Neither CUDA nor cuDNN loaded but running on CPU, so it's fine. |
| 106 | + test_script = """ |
| 107 | + using ONNXRunTime |
| 108 | + load_inference("$(onnx_path)", execution_provider = :cpu) |
| 109 | + """ |
| 110 | + # CUDA not loaded. Well, cuDNN pulls in CUDA so this passes anyway. |
| 111 | + test_script = """ |
| 112 | + using ONNXRunTime |
| 113 | + using cuDNN |
| 114 | + load_inference("$(onnx_path)", execution_provider = :cuda) |
| 115 | + """ |
| 116 | + @test success(run(`julia +1.9 --project=$(env) -e "$(test_script)"`)) |
| 117 | + # CUDA not loaded but running on CPU, so it's fine. |
| 118 | + test_script = """ |
| 119 | + using ONNXRunTime |
| 120 | + using cuDNN |
| 121 | + load_inference("$(onnx_path)", execution_provider = :cpu) |
| 122 | + """ |
| 123 | + @test success(run(`julia +1.9 --project=$(env) -e "$(test_script)"`)) |
| 124 | + # cuDNN not loaded. |
| 125 | + test_script = """ |
| 126 | + using ONNXRunTime |
| 127 | + using CUDA |
| 128 | + load_inference("$(onnx_path)", execution_provider = :cuda) |
| 129 | + """ |
| 130 | + @test_throws ProcessFailedException run(`julia +1.9 --project=$(env) -e "$(test_script)"`) |
| 131 | + # cuDNN not loaded but running on CPU, so it's fine. |
| 132 | + test_script = """ |
| 133 | + using ONNXRunTime |
| 134 | + using CUDA |
| 135 | + load_inference("$(onnx_path)", execution_provider = :cpu) |
| 136 | + """ |
| 137 | + @test success(run(`julia +1.9 --project=$(env) -e "$(test_script)"`)) |
| 138 | + end |
| 139 | +end |
| 140 | + |
| 141 | +@testset "Julia 1.9 CUDA.jl $(cuda_version) CUDA runtime 11.6" for cuda_version in (4, 5) |
| 142 | + with_environment(cuda_runtime_version = "11.6") do env |
| 143 | + install_script = """ |
| 144 | + using Pkg |
| 145 | + Pkg.develop(path = "$(package_path)") |
| 146 | + Pkg.add(name = "CUDA", version = "$(cuda_version)") |
| 147 | + Pkg.add(name = "cuDNN") |
| 148 | + """ |
| 149 | + @test success(run(`julia +1.9 --project=$(env) -e "$(install_script)"`)) |
| 150 | + # Correct dependencies for :cuda. CUDA runtime version is |
| 151 | + # lower than officially supported but close enough to at least |
| 152 | + # load so there will be a warning but no error. |
| 153 | + test_script = """ |
| 154 | + using ONNXRunTime, CUDA, cuDNN |
| 155 | + load_inference("$(onnx_path)", execution_provider = :cuda) |
| 156 | + """ |
| 157 | + @test success(run(`julia +1.9 --project=$(env) -e "$(test_script)"`)) |
| 158 | + end |
| 159 | +end |
| 160 | + |
| 161 | +@testset "Julia 1.9 CUDA.jl $(cuda_version) CUDA runtime 12.1" for cuda_version in (4, 5) |
| 162 | + with_environment(cuda_runtime_version = "12.1") do env |
| 163 | + install_script = """ |
| 164 | + using Pkg |
| 165 | + Pkg.develop(path = "$(package_path)") |
| 166 | + Pkg.add(name = "CUDA", version = "$(cuda_version)") |
| 167 | + Pkg.add(name = "cuDNN") |
| 168 | + """ |
| 169 | + @test success(run(`julia +1.9 --project=$(env) -e "$(install_script)"`)) |
| 170 | + # Correct dependencies for :cuda but fails due to bad version |
| 171 | + # of CUDA runtime. |
| 172 | + test_script = """ |
| 173 | + using ONNXRunTime, CUDA, cuDNN |
| 174 | + load_inference("$(onnx_path)", execution_provider = :cuda) |
| 175 | + """ |
| 176 | + @test_throws ProcessFailedException run(`julia +1.9 --project=$(env) -e "$(test_script)"`) |
| 177 | + end |
| 178 | +end |
0 commit comments