![]() In this post, I would like to explain a basic but confusing concept of CUDA programming: Thread Hierarchies. We will not cover all aspects, but it could be a nice first step. ![]() ![]() If you are starting with CUDA and want to know how to setup your environment, using VS2017, I recommend you to read this post. To get started, let’s write something straightforward to run on the CPU. Now, let’s change this code to run on the GPU. Let’s remember some concepts we learned in a previous post: The cudaDeviceSyncronize function determines that all the processing on the GPU must be done before continuing. The _global_ keyword indicates that the following function will run on the GPU.The code executed on the CPU is referred to as host code, and code executed on the GPU is referred to as device code.It is required that functions defined with the _global_ keyword return type void. where earlier in the host code for a 1D grid you have something like dim3 gridDim ( TotalBlocks ) dim3 blockDim ( ThreadsPerBlock ) // I usually define ThreadsPerBlock or for a 2D grid you might have dim3 gridDim ( 10, 20 ) dim3 blockDim ( 16,32 ) (see CUDA Programming Guide, In version 2.3 its Appendix B.12.When calling a function to run on the GPU, we call this function a kernel (In the example, printHelloGPU is the kernel).When launching a kernel, we must provide an execution configuration, which is done by using the > syntax.Īt a high level, the execution configuration allows programmers to specify the thread hierarchy for a kernel launch, which defines the number of thread blocks, as well as.How many threads to execute in each block. Notice, in the previous example, the kernel is launching with 1 block of threads (the first execution configuration argument) which contains 1 thread (the second configuration argument). The execution configuration allows programmers to specify details about launching the kernel to run in parallel on multiple GPU threads. Question: The CUDA built-in dim3 variable grid Dim tells you This blocks indexes within this grid The dimensions of the blocks in this grid This threads. The CUDA interfaces use global state that is initialized during host program initiation and destroyed during host program termination. Thus, under the assumption that a kernel called printHelloGPU has been defined, the following are true: The syntax for this is:Ī kernel is executed once for every thread in every thread block configured when the kernel is launched.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |