CUDA C++ Debugging: Safer GPU Kernel Programming (Generative AI Programming in C++) by Spuler David
Author:Spuler, David
Language: eng
Format: epub
Publisher: Aussie AI Labs
Published: 2024-10-15T00:00:00+00:00
Letâs examine these issues in turn.
Threads-per-Block Multiple of 32
The number of threads per block (aka the âblock sizeâ) should be a multiple of the warp size, which is 32 threads. Hence, it can be as low as 32, but commonly recommended block sizes in real-world kernels are often 256 or 512. The maximum permitted by CUDA is 1024 threads per block.
This is not good:
float v[54];
...
int blocks = 2;
mykernel<<<blocks, 27>>>(v,n); // BAD
This might actually work, but itâs very inefficient, and offends the sensibilities of any experienced CUDA programmer, for reasons discussed below.
But first, note that this is worse:
float v[54];
...
int blocks = 54;
mykernel<<<blocks, 1>>>(v,n); // BAD
If the threads per block is not 32, or a multiple of 32, there will be odd threads in a warp that arenât properly utilized (or might be doing the wrong thing). The reason is that CUDA allows threads in âwarpsâ that contain exactly 32 threads. With the threads per block of 27, there were 5 extra threads, and for 1 thread per block, there were 31 wasted threads. So, instead, you want something more like this:
float v[64];
int n = 64;
...
int blocks = 2;
mykernel<<<blocks,32>>>(v,n); // BETTER
Or you can do this:
float v[64];
int n = 64;
...
int blocks = 1;
mykernel<<<blocks,64>>>(v,n); // BETTER
CUDA can only schedule 32 threads (a warp) at a time, and if you try to schedule less than that, the rest of the threads in that warp still run, which is a bug or a slug, or are unavailable to run, which is a slug.
Too Few Blocks
You donât always know the incoming size N of your vector data structure (well, actually, you often do in AI engines, because they have static dimensions, but anyway). Letâs try to generalize our computation of how many blocks with each having a fixed number of threads. Thereâs a few basic points:
Each block has the same number of threads (i.e., the threads-per-block)
You canât run half a block (all its threads will run, even if you donât need that many).
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Personalized inhaled bacteriophage therapy for treatment of multidrug-resistant Pseudomonas aeruginosa in cystic fibrosis by unknow(208890)
CONSORT 2025 statement: updated guideline for reporting randomized trials by unknow(102477)
Critical evaluation of the ProfiLER-02 study design and outcomes by Vivek Subbiah & Razelle Kurzrock(102013)
Cardiac gene therapy makes a comeback by Oliver J. Müller & Susanne Hille & Anca Kliesow Remes(101805)
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(74596)
Unveiling the design rules for tunable emission in graphene quantum dots: A high-throughput TDDFT and machine learning perspective by Şener Özönder & Mustafa Coşkun Özdemir & Caner Ünlü(50986)
A yeast-based oral therapeutic delivers immune checkpoint inhibitors to reduce intestinal tumor burden by unknow(40363)
Covalent hitchhikers guide proteins to the nucleus by Alexander F. Russell & Madeline F. Currie & Champak Chatterjee(40284)
Meet the Authors: Christopher R. Mansfield and Emily R. Derbyshire by Christopher R. Mansfield & Emily R. Derbyshire(40187)
Alkaline-earth metals promote propane dehydrogenation with carbon dioxide through geometric effects: Altering the reaction pathway by unknow(32806)
Induced iron vacancies boosting FeOOH loaded on sustainable Fenton-like collagen fiber membrane for efficient removal of emerging contaminants by unknow(32602)
Efficient electric-field-assisted photochemical conversion of methane to n-propanol exclusively over penetrated TiO2Ti hollow fibers by Guanghui Feng(32520)
Bi2SiO5 nanosheets as piezo-photocatalyst for efficient degradation of 2,4-Dichlorophenol by Hangyu Shi & Yifu Li & Lishan Zhang & Guoguan Liu & Qian Zhang & Xuan Ru & Shan Zhong(32459)
A novel NDIPTA organic heterojunction photocatalyst with built-in electric field for efficient hydrogen production by Jiahui Yang & Baojun Ma & Yongfa Zhu(32432)
Enhanced conversion of methane to liquid-phase oxygenates via hollow ferrite nanotube@horseradish peroxidase based photoenzymatic catalysis by Jun Duan & Shiying Fan & Xinyong Li & Shaomin Liu(32397)
Ordered macroporous superstructure of defective carbon adorned with tiny cobalt sulfide for selective electrocatalytic hydrogenation of cinnamaldehyde by Xiao-Shi Yuan & Sheng-Hua Zhou & San-Mei Wang & Wenbo Wei & Xiaofang Li & Xin-Tao Wu & Qi-Long Zhu(32321)
What's Done in Darkness by Kayla Perrin(27236)
Topological analysis of non-conjugated ethylene oxide cored dendrimers decorated with tetraphenylethylene: Insights from degree-based descriptors using the polynomial approach by A Theertha Nair & D Antony Xavier & Annmaria Baby & S Akhila(26617)
Investigation of mechanical and self-healing properties of hydroxyl-terminated polybutadiene functionalized with 2-ureido-4-pyrimidinone by Mohsen Kazazi & Mehran Hayaty & Ali Mousaviazar(26546)