CUDA basics

Hello everyone
I currently working on a CUDA project and can’t figure out how to modifie varibles. SInce theres no global varibles how am i able to modify information in a CUDA funtion and then use it somewhere else?

You never learned how to pass a pointer to a function to get it to return data? Global variables are not the only method. What are they teaching kids in C class these days…

Thats y u have “cudaMemcpy” function… Store your CUDA result in global variables or arrays and use “cudaMemcpy” function to do so…

cudaMemcpy works fine if you have used “cudaMalloc” to allocate global memory. However, if u have automatic global variables, you need to do cudaMemcpyToSymbol() or some API like that to copy in and out…



I dont think pointers will work. Not sure what you were hinting at,.

Best Regards,


Thanks that helps and to answer the first responces answer,
No we were not taught this and it is our first semester using C, the prof just decided that our final would be a cuda project and told us to view source code to learn it. Its been a very frustrating experince since were still pretty inexperinced programmers.

so… out of curiosity, what school is this?

Sorry id rather not say, but its not the whole school this is a new prof and i dont think he understood what level of programmer we were at.

wow. I can’t tell if your professor is crazy or crazy awesome. (Maybe he’d be great if he did more than tell you to learn the language on your own.)

Anyway, read through the Programming Guide, at least the beginning. It’s easy-going reading, and it has small code examples that demonstrate such things. Also take a look at the SDK samples. (It does help.)

Do you already know a different programming language?

Take a look at this advice:

Thanks Alex and I’ve had a year of Java but thats it.

That’s not bad. So basically you have to study up on pointers, since they’re the heart of C and CUDA programming. Just do a google search, print out the webpages, cozy up somewhere warm, and read.