Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to CUDA, and CUDALink. I see how CUDAFunctionLoad allows one to set the block dimensions. On calling the function, you can also either pass as argument or have MMA automatically select the number of threads to be launched as the max length of the arguments passed. However, I don't see how I can set the grid dimensions if I want a bidimensional grid. It should be possible, right?

share|improve this question
up vote 8 down vote accepted

You cannot specify the grid dimensions, you can specify how many threads to launch. This is done by passing an extra argument when calling the CUDAFunciton, so

colorNegate = CUDAFunctionLoad[{srcf}, "imageColorNegate",
 {{_Integer, _, "InputOutput"},_Integer, _Integer, _Integer}, {16, 16}]

this will figure out the number of threads automatically:

colorNegate[img, 512, 512, 3]

this will force CUDALink to launch {256, 256} threads

colorNegate[img, 512, 512, 3, {256, 256}]
share|improve this answer
Thanks, hadn't realised you could get bidimensional with the extra argument of the number of threads to launch – Rojo Feb 4 '12 at 18:14

I think you can use a list {nX, nY} like in this example from the documentation (where nX = nY = 16) :

colorNegate = CUDAFunctionLoad[{srcf}, "imageColorNegate",
 {{_Integer, _, "InputOutput"},_Integer, _Integer, _Integer}, {16, 16}]

I would recommend the two free seminars :

S70 CUDA Computation

S71 CUDA Programming

You can also download the presentation notebooks.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.