<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>CUDA入门到入土 on moyutianzun's blog</title><link>https://moyutianzun.cn/en/categories/cuda%E5%85%A5%E9%97%A8%E5%88%B0%E5%85%A5%E5%9C%9F/</link><description>Recent content in CUDA入门到入土 on moyutianzun's blog</description><generator>Hugo</generator><language>en</language><copyright>moyutianzun</copyright><lastBuildDate>Mon, 20 Oct 2025 15:18:01 +0800</lastBuildDate><atom:link href="https://moyutianzun.cn/en/categories/cuda%E5%85%A5%E9%97%A8%E5%88%B0%E5%85%A5%E5%9C%9F/index.xml" rel="self" type="application/rss+xml"/><item><title>CUDA profile 大全 —— nsight computer &amp; nsys &amp; pytorch</title><link>https://moyutianzun.cn/en/blog/cuda-profile/</link><pubDate>Mon, 20 Oct 2025 15:18:01 +0800</pubDate><guid>https://moyutianzun.cn/en/blog/cuda-profile/</guid><description>&lt;h1 style="" id="cuda-api"&gt;Cuda API&lt;/h1&gt;&lt;p style=""&gt;创建对象：&lt;/p&gt;&lt;pre&gt;&lt;code&gt;#include &amp;lt;cuda_runtime.h&amp;gt;
#include &amp;lt;cuda.h&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
&lt;p&gt;// 获取当前机器的GPU数量
cudaError_t error_id = cudaGetDeviceCount(&amp;amp;deviceCount);&lt;/p&gt;
&lt;p&gt;for (int dev = 0; dev &amp;lt; deviceCount; ++dev) {
cudaSetDevice(dev);
// 初始化当前device的属性获取对象
cudaDeviceProp deviceProp;
cudaGetDeviceProperties(&amp;amp;deviceProp, dev);&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;printf(&amp;quot;\nDevice %d: \&amp;quot;%s\&amp;quot;\n&amp;quot;, dev, deviceProp.name);&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;p style=&amp;quot;&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;p style=&amp;quot;&amp;quot;&amp;gt;拿到数据后可以查看对应feature&amp;lt;/p&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;printf(&amp;quot; Total amount of shared memory per block: %zu bytes\n&amp;quot;, deviceProp.sharedMemPerBlock);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;printf(&amp;quot; Total shared memory per multiprocessor: %zu bytes\n&amp;quot;, deviceProp.sharedMemPerMultiprocessor);
printf(&amp;quot; Total number of registers available per block: %d\n&amp;quot;, deviceProp.regsPerBlock);
printf(&amp;quot; Warp size: %d\n&amp;quot;, deviceProp.warpSize);
printf(&amp;quot; Maximum number of threads per multiprocessor: %d\n&amp;quot;, deviceProp.maxThreadsPerMultiProcessor);
printf(&amp;quot; Maximum number of threads per block: %d\n&amp;quot;, deviceProp.maxThreadsPerBlock);
printf(&amp;quot; Max dimension size of a block size (x,y,z): (%d, %d, %d)\n&amp;quot;, deviceProp.maxThreadsDim[0], deviceProp.maxThreadsDim[1],
deviceProp.maxThreadsDim[2]);
printf(&amp;quot; Max dimension size of a grid size (x,y,z): (%d, %d, %d)\n&amp;quot;, deviceProp.maxGridSize[0], deviceProp.maxGridSize[1],
deviceProp.maxGridSize[2]);&lt;/code&gt;&lt;/pre&gt;&lt;p style=""&gt;&lt;/p&gt;</description></item><item><title>【CUDA从入门到入土】四、矩阵乘法</title><link>https://moyutianzun.cn/en/blog/cudacong-ru-men-dao-ru-tu-si-ju-zhen-cheng-fa/</link><pubDate>Wed, 03 Sep 2025 14:50:37 +0800</pubDate><guid>https://moyutianzun.cn/en/blog/cudacong-ru-men-dao-ru-tu-si-ju-zhen-cheng-fa/</guid><description>&lt;p style="text-indent: 2em"&gt;矩阵乘法跟之前不同，之前一维可以直接写一个kernel，或者多个kernel线性的排布来并行计算，那么矩阵乘法就是由一维向二维转变的关键。这时候一维的kernel排布也变成了二维排布。&lt;/p&gt;</description></item><item><title>【CUDA从入门到入土】三、reduce算子及其优化</title><link>https://moyutianzun.cn/en/blog/cudacong-ru-men-dao-ru-tu-san-reducesuan-zi-ji-qi-you-hua/</link><pubDate>Sat, 23 Aug 2025 08:46:59 +0800</pubDate><guid>https://moyutianzun.cn/en/blog/cudacong-ru-men-dao-ru-tu-san-reducesuan-zi-ji-qi-you-hua/</guid><description>&lt;p style="text-indent: 2em"&gt;该项目代码参考&lt;a href="https://space.bilibili.com/1822828582" target="_self" rel=""&gt;傅哥的课程&lt;/a&gt;，很有用的课程，请多多支持他。&lt;/p&gt;&lt;hr&gt;&lt;p style="text-indent: 2em"&gt;&lt;/p&gt;&lt;p style="text-indent: 2em"&gt;&lt;/p&gt;&lt;p style="text-indent: 2em"&gt;reduce 规约求和是cuda中一个经典的问题，其本质是将输入的序列进行求和。&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style="text-indent: 2em"&gt;在CUDA的多线程中，我们清楚数据被分为一个一个的block中进行运行，每个block通过warp来并发32个线程进行运算。&lt;/p&gt;</description></item><item><title>【CUDA从入门到入土】二、CUDA调试和必知必会 &amp; Nsight Computer 入门</title><link>https://moyutianzun.cn/en/blog/cudacong-ru-men-dao-ru-tu-er-cudabi-zhi-bi-hui/</link><pubDate>Sun, 17 Aug 2025 17:09:02 +0800</pubDate><guid>https://moyutianzun.cn/en/blog/cudacong-ru-men-dao-ru-tu-er-cudabi-zhi-bi-hui/</guid><description>&lt;p style="text-indent: 2em"&gt;上文中，我们运行了一个简单的cuda函数，并且一次过的将其运行了起来，这次，我们需要补充一些基础的概念，通过概念和框架的建立，我们才能走的更远，高屋建瓴的认识更多。&lt;/p&gt;</description></item><item><title>【CUDA从入门到入土】五、cuda_kernel_和_cuda_attention详解</title><link>https://moyutianzun.cn/en/blog/cudacong-ru-men-dao-ru-tu-er-cuda_kernel_he_cuda_attentionxiang-jie/</link><pubDate>Sun, 17 Aug 2025 15:14:21 +0800</pubDate><guid>https://moyutianzun.cn/en/blog/cudacong-ru-men-dao-ru-tu-er-cuda_kernel_he_cuda_attentionxiang-jie/</guid><description>&lt;p style=""&gt;从cuda kernel出发，看懂人生第一个cuda attention&lt;/p&gt;</description></item><item><title>【CUDA从入门到入土】一、丝滑的CUDA入门</title><link>https://moyutianzun.cn/en/blog/cudacong-ru-men-dao-ru-tu-yi-si-hua-de-cudaru-men/</link><pubDate>Thu, 14 Aug 2025 16:27:54 +0800</pubDate><guid>https://moyutianzun.cn/en/blog/cudacong-ru-men-dao-ru-tu-yi-si-hua-de-cudaru-men/</guid><description>&lt;p style=""&gt;&lt;strong&gt;CUDA是什么&lt;/strong&gt;&lt;/p&gt;&lt;p style=""&gt;cuda是一种gpu编程组件，是一种原生支持GPU软硬件的架构，使得开发者可以直接在 GPU 上编写和执行通用计算程序。&lt;/p&gt;&lt;h2 style="" id="gpu%E6%9E%B6%E6%9E%84"&gt;&lt;strong&gt;GPU架构&lt;/strong&gt;&lt;/h2&gt;&lt;p style=""&gt;&lt;img src="https://moyublog-picture.oss-cn-guangzhou.aliyuncs.com/images/20250807194901764.png" alt="" width="100%" height="100%" style="display: inline-block"&gt;&lt;/p&gt;&lt;p style=""&gt;上图是H100白皮书中，H100 GPU带满了144个SM的架构图&lt;/p&gt;&lt;p style=""&gt;&lt;img src="https://moyublog-picture.oss-cn-guangzhou.aliyuncs.com/images/20250807195051758.png" alt="" width="991px" height="1379px" style="display: inline-block"&gt;&lt;/p&gt;&lt;p style=""&gt;上图是H100中，1个SM的架构图&lt;/p&gt;&lt;h3 style="" id="sm%E6%9E%B6%E6%9E%84%E8%AF%A6%E8%A7%A3"&gt;&lt;strong&gt;SM架构详解&lt;/strong&gt;&lt;/h3&gt;&lt;p style=""&gt;由此，我们可以高屋建瓴的看懂GPU，这里不雕琢细节，只直白的说明白GPU怎么工作的：&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p style=""&gt;PCIE 就是负责数据从显卡和主板之间进出的数据传输协议，理解为传递数据的就对了&lt;/p&gt;</description></item></channel></rss>