In the end, in our case, the following allowed us to get CUDA
to work.
export NVIDIA_DRIVER_LIBRARY_PATH /usr/lib64/libnvidia-tls.so.418.116.00
(adapt to your usage).
Then in mathematica
Needs["CUDALink`"]
and
CUDAQ[]
launches the download of about 4.3 GBytes (!!) of data in .Mathematica
(most of it in Paclets/Repository/CUDAResources-Lin64-12.0.346/CUDAToolkit
), so be patient, but eventually it returns
(* True *)
Note incidentally that the machine obviously needs to be able to access the internet.
Then the sky is the limit :0)
width = 1024; height = 768;
iconfig = {width, height, 1, 0, 1, 6};
config = {0.001, 0.0, 0.0, 0.0, 8.0, 15.0, 10.0, 5.0};
camera = {{2.0, 2.0, 2.0}, {0.0, 0.0, 0.0}}; AppendTo[camera,
Normalize[camera[[2]] - camera[[1]]]]; AppendTo[camera,
0.75*Normalize[
Cross[camera[[3]], {0.0, 1.0, 0.0}]]]; AppendTo[camera,
0.75*Normalize[Cross[camera[[4]], camera[[3]]]]];
config = Join[{config, Flatten[camera]}];
pixelsMem = CUDAMemoryAllocate["Float", {height, width, 3}];
srcf =
FileNameJoin[{$CUDALinkPath, "SupportFiles", "mandelbulb.cu"}];
mandelbulb =
CUDAFunctionLoad[{srcf},
"MandelbulbGPU", {{"Float", _, "Output"}, {"Float", _,
"Input"}, {"Integer32", _, "Input"}, "Integer32", "Float",
"Float"}, {16}, "UnmangleCode" -> False];
mandelbulb[pixelsMem,
Flatten[config], iconfig, 0, 0.0, 0.0, {width*height*3}];
pixels = CUDAMemoryGet[pixelsMem];Image[pixels]
And, following @Fortsaint 's comment:
data = Flatten@Table[{x, y} -> Exp[-Norm[{x, y}]], {x,-3,3,.005}, {y,-3,3,.005}];
net = NetChain[{32, Tanh, 1}];
trained = NetTrain[net, data, BatchSize -> 1024, "TargetDevice" -> "GPU"]
Starting training.
Optimization Method: ADAM
Device: GPU
Batch Size: 1024
Batches Per Round: 1409
Training Examples: 1442401
....
Training complete.
which is 16 times faster with the GPU.
nvidia-smi
while `NetTrain[ .. , Target -> "GPU"] and you'll see the wolfram kernel using the GPU $\endgroup$