Question: CPU vs GPU matrix calculations

Hello,

I found this sample code that determine the time to do matrix multiplications using cpus and gpus. I was surprised that the speedup factor was less than one.  I also did a similar speed test using python pytorch code on the same computer. The speedup factor was remarkable. Please find my mistakes, thanks.

MAPLE CODE:

kernelopts(version);
with(LinearAlgebra);
with(CUDA);
n := 4000;
M1 := RandomMatrix(n, n, datatype = float[8]);
M2 := RandomMatrix(n, n, datatype = float[8]);
printf("CUDA enabled? %a\n", IsEnabled());
tNoCUDA := time[real](M1 . M2);
printf("Time without CUDA: %.3f seconds\n", tNoCUDA);
prevSetting := Enable(true);
printf("Previous CUDA setting: %a\n", prevSetting);
printf("CUDA enabled now? %a\n", IsEnabled());
tCUDA := time[real](M1 . M2);
printf("Time with CUDA: %.3f seconds\n", tCUDA);
printf("Speedup factor: %.2f\n", evalf(tNoCUDA/tCUDA));
props := Properties();
printf("CUDA Device Properties:\n");
props;
Enable(false);
printf("CUDA enabled after disabling? %a\n", IsEnabled());

 

RESULTS:

  Maple 2026.0, X86 64 WINDOWS, Mar 05 2026, Build ID 2001916

CUDA enabled? false
Time without CUDA: 0.288 seconds
Previous CUDA setting: false
CUDA enabled now? true
Time with CUDA: 0.439 seconds
Speedup factor: 0.66
CUDA Device Properties:

[TABLE(["Clock Rate" = 2692000, "Resisters Per Block" = 65536, 

  "ID" = 0, "Texture Alignment" = 512, 

  "Max Grid Size" = [2147483647, 65535, 65535], 

  "Memory Pitch" = 2147483647, "Major" = 12, 

  "MultiProcessor Count" = 36, "Shared Memory Per Block" = 49152, 

  "Minor" = 0, "Name" = "NVIDIA GeForce RTX 5060 Ti", 

  "Max Threads Dimensions" = [1024, 1024, 64], "Warp Size" = 32, 

  "Total Global Memory" = 4294967295, 

  "Max Threads Per Block" = 1024, "Device Overlap" = 1, 

  "Total Constant Memory" = 65536, 

  "Kernel Exec Timeout Enabled" = true])]


CUDA enabled after disabling? false
 

Please Wait...