From 8c2c3ae2cb710341c85e87aa44868d649c05a51d Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Fri, 7 Jun 2024 00:06:46 -0700 Subject: [PATCH] Add tests for gpu_backend! --- test/misc.jl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/misc.jl b/test/misc.jl index 6d59372..b8a5590 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -106,3 +106,26 @@ end @test get_device(x) isa LuxCPUDevice @test get_device(x_view) isa LuxCPUDevice end + +@testset "loaded and functional" begin + @test LuxDeviceUtils.loaded(LuxCPUDevice) + @test LuxDeviceUtils.functional(LuxCPUDevice) +end + +@testset "writing to preferences" begin + @test_logs (:info, + "Deleted the local preference for `gpu_backend`. Restart Julia to use the new backend.") gpu_backend!() + + for backend in (:CUDA, :AMDGPU, :oneAPI, :Metal, LuxAMDGPUDevice(), + LuxCUDADevice(), LuxMetalDevice(), LuxoneAPIDevice()) + backend_name = backend isa Symbol ? string(backend) : + LuxDeviceUtils._get_device_name(backend) + @test_logs (:info, + "GPU backend has been set to $(backend_name). Restart Julia to use the new backend.") gpu_backend!(backend) + end + + gpu_backend!(:CUDA) + @test_logs (:info, "GPU backend is already set to CUDA. No action is required.") gpu_backend!(:CUDA) + + @test_throws ArgumentError gpu_backend!("my_backend") +end