I am having an issue with image processing involving CUDALink
.
Needs["CUDALink`"]
CUDAQ[]
images = FileNames["*.jpg", "C:\\Users\\rwheatley\\Desktop\\All Folders\\Pics\\"];
count = 1;
Do[imagevar[count++] = Import[image], {image, images}];
Length[images]
start = SessionTime[];
For[i = 1, i < Length[images], i++, CUDAImageConvolve[imagevar[i], {{-1, -2, 3}}]]
CUDATime = SessionTime[] - start;
start1 = SessionTime[];
For[i = 1, i < Length[images], i++, ImageConvolve[imagevar[i], {{-1, -2, 3}}]]
Regular = SessionTime[] - start1;
CUDATime
Regular
With 34 iPhone6+ HDR photos, this always has CUDA taking longer by a factor of 4. Does anyone see what is wrong with my code?
In[43]:= CUDAInformation[]
Out[43]= {1 -> {"Name" -> "NVS 5200M", "Clock Rate" -> 1344000,
"Compute Capabilities" -> 2.1, "GPU Overlap" -> 1,
"Maximum Block Dimensions" -> {1024, 1024, 64},
"Maximum Grid Dimensions" -> {65535, 65535, 65535},
"Maximum Threads Per Block" -> 1024, "Maximum Shared Memory Per Block" -> 49152,
"Total Constant Memory" -> 65536, "Warp Size" -> 32, "Maximum Pitch" -> 2147483647,
"Maximum Registers Per Block" -> 32768, "Texture Alignment" -> 512,
"Multiprocessor Count" -> 2, "Core Count" -> 64, "Execution Timeout" -> 1,
"Integrated" -> False, "Can Map Host Memory" -> True, "Compute Mode" -> "Default",
"Texture1D Width" -> 65536, "Texture2D Width" -> 65536, "Texture2D Height" -> 65535,
"Texture3D Width" -> 2048, "Texture3D Height" -> 2048, "Texture3D Depth" -> 2048,
"Texture2D Array Width" -> 16384, "Texture2D Array Height" -> 16384,
"Texture2D Array Slices" -> 2048, "Surface Alignment" -> 512,
"Concurrent Kernels" -> True, "ECC Enabled" -> False, "TCC Enabled" -> False,
"Total Memory" -> 1073741824}}
Thanks to @MarcoB I have modified my code to be more Mathematica-Like as follows:
ClearAll["Global*"]
Needs["CUDALink
"]
CUDAQ[]
images = FileNames["*.jpg", "C:\\Users\\rwheatley\\Desktop\\All Folders\\Pics\\"];
imagevar = Import /@ images;
Clear[images]
MemoryInUse[]
CUDAImageConvolve[#, {{-1, -2, 3}}] & /@ imagevar; // AbsoluteTiming
ImageConvolve[#, {{-1, -2, 3}}] & /@ imagevar; // AbsoluteTiming
The issue still remains for CUDA being slower, though. I have even tried the following to no avail:
mem = CUDAMemoryLoad[#] & /@ imagevar;
CUDAImageConvolve[#, {{-1, -2, 3}}] & /@ mem; // AbsoluteTiming
images = FileNames["*.jpg", "C:\\Users\\rwheatley\\Desktop\\All Folders\\Pics\\"];
imagevar = Import /@ images;
Union[ImageType /@ imagevar]
Union[ImageColorSpace /@ imagevar]
Union[ImageDimensions /@ imagevar]
{"Byte"} {"RGB"} {{369, 100}, {381, 325}, {390, 231}, {400, 400}, {620, 620}, {678, 592}, {850, 540}, {1200, 1199}, {1836, 3264}, {2448, 3264}, {3264, 2448}} $\endgroup$