<?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>算子 on moyutianzun 的博客</title><link>https://moyutianzun.com/tags/%E7%AE%97%E5%AD%90/</link><description>Recent content in 算子 on moyutianzun 的博客</description><generator>Hugo</generator><language>zh-cn</language><copyright>moyutianzun</copyright><lastBuildDate>Mon, 20 Oct 2025 15:18:01 +0800</lastBuildDate><atom:link href="https://moyutianzun.com/tags/%E7%AE%97%E5%AD%90/index.xml" rel="self" type="application/rss+xml"/><item><title>CUDA profile 大全 —— nsight computer &amp; nsys &amp; pytorch</title><link>https://moyutianzun.com/blog/cuda-profile/</link><pubDate>Mon, 20 Oct 2025 15:18:01 +0800</pubDate><guid>https://moyutianzun.com/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>算子进阶 —— 通信算子</title><link>https://moyutianzun.com/blog/suan-zi-jin-jie------tong-xin-suan-zi/</link><pubDate>Mon, 22 Sep 2025 09:00:54 +0800</pubDate><guid>https://moyutianzun.com/blog/suan-zi-jin-jie------tong-xin-suan-zi/</guid><description>&lt;p style=""&gt;随着LLM业务的不断发展，我们发现单机单卡无法承载一个模型的训练和推理，故此出现了单机多卡和多机多卡的训练推理算子，这时候每个机和卡之间都需要通信，所以通信算子十分的重要。&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;h1 style="" id="%E5%88%86%E5%B8%83%E5%BC%8F%E5%B9%B6%E8%A1%8C"&gt;分布式并行&lt;/h1&gt;&lt;p style="text-indent: 2em"&gt;下面是传统的四种并行处理架构，常用于大模型训练。&lt;/p&gt;&lt;p style="text-align: center"&gt;&lt;img src="https://moyublog-picture.oss-cn-guangzhou.aliyuncs.com/images/20250921122900313.png" width="991px" height="415px" style="display: inline-block"&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;h2 style="" id="dp"&gt;DP&lt;/h2&gt;&lt;p style="text-align: center"&gt;&lt;img src="https://moyublog-picture.oss-cn-guangzhou.aliyuncs.com/images/20250921142712073.png" width="70%" height="100%" style="display: inline-block"&gt;&lt;/p&gt;&lt;p style="text-indent: 2em"&gt;每张卡拷贝相同的模型结构，仅对数据做切分。每张卡计算完的梯度也是针对各自数据的，需要做一次allreduce，然后使用优化器更新模型，进入下一次迭代。&lt;/p&gt;</description></item><item><title>算子进阶 —— 通算融合</title><link>https://moyutianzun.com/blog/suan-zi-jin-jie------tong-suan-rong-he/</link><pubDate>Fri, 19 Sep 2025 08:16:51 +0800</pubDate><guid>https://moyutianzun.com/blog/suan-zi-jin-jie------tong-suan-rong-he/</guid><description>&lt;p style=""&gt;（施工ing）&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;h1 style="" id="%E6%A6%82%E8%BF%B0"&gt;概述&lt;/h1&gt;&lt;p style=""&gt;我们知道，算子的作用是计算，那在整个体系中，我们的核心目标是拉满GPU的利用率。&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;在现代分布式体系中，多GPU之间同时存在着计算、内存访问和通信这三种基本活动，为了服务于我们的核心目标，我们需要尽可能的将通信时间和访存时间放在计算时间内，使得GPU不存在运算时间的泡泡。&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;大模型分布式系统执行的核心组件是并行的GPU。提升GPU运算的最佳方法，是通过计算与通信的重叠来实现。这种重叠可以通过两种方式达成：算子分解或通信内核融合。虽然算子分解实现起来简单，但往往导致性能欠佳。而将通信内核与计算内核融合，则需要更多的思考和计算。&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;故此最原始的想法就是用计算时间掩盖通信时间，通过大批量的数据直接发送到GPU，减少kernel开启和关闭、通信的开销。&lt;/p&gt;&lt;p style="text-align: center"&gt;&lt;img src="https://moyublog-picture.oss-cn-guangzhou.aliyuncs.com/images/20250917234340532.png" width="100%" height="100%" style="display: inline-block"&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;h1 style="" id="triton-distributed"&gt;Triton-distributed&lt;/h1&gt;&lt;p style="text-indent: 2em"&gt;Triton-distributed是字节seed团队开发的Triton 编译器的扩展。对于 LLM 来说，分布式优化的关键要求是计算通信重叠。以前，在小规模分布式训练/推理中，通信开销并不是一个关键的成本问题。然而，随着集群数量呈指数级增长，计算与通信重叠变得至关重要。&lt;/p&gt;</description></item><item><title>AMD 2025 分布式推理算子优化挑战赛 —— lect 9/16 note</title><link>https://moyutianzun.com/blog/amd-2025-fen-bu-shi-tui-li-suan-zi-you-hua-tiao-zhan-sai------lect-9-16-note/</link><pubDate>Fri, 19 Sep 2025 02:57:25 +0800</pubDate><guid>https://moyutianzun.com/blog/amd-2025-fen-bu-shi-tui-li-suan-zi-you-hua-tiao-zhan-sai------lect-9-16-note/</guid><description>&lt;p style=""&gt;&lt;/p&gt;&lt;h1 style="" id="rocm-%E5%85%A5%E9%97%A8"&gt;ROCm 入门&lt;/h1&gt;&lt;p style=""&gt;&lt;img src="https://moyublog-picture.oss-cn-guangzhou.aliyuncs.com/images/20250916190914403.png" width="100%" height="100%" style="display: inline-block"&gt;&lt;/p&gt;&lt;p style="text-indent: 2em"&gt;首先就是amd官方的命名跟nv的区别，其实区别并不大，只是AMD在cuda的基础上做了更多的优化，比如说一个wavefront有64个work-item，相当于一个warp有64个threads。其次就是有两种register，在&lt;/p&gt;</description></item><item><title>Triton is all you need —— Triton 源码、编译和调试</title><link>https://moyutianzun.com/blog/triton-is-all-you-need------triton-yuan-ma-bian-yi-he-diao-shi/</link><pubDate>Thu, 18 Sep 2025 07:35:21 +0800</pubDate><guid>https://moyutianzun.com/blog/triton-is-all-you-need------triton-yuan-ma-bian-yi-he-diao-shi/</guid><description>&lt;p style="text-align: left"&gt;（施工ing）&lt;/p&gt;&lt;p style="text-align: left"&gt;&lt;/p&gt;&lt;p style="text-align: center"&gt;&lt;a href="https://moyublog-picture.oss-cn-guangzhou.aliyuncs.com/images/20250918010843097.png"&gt;&lt;img src="https://moyublog-picture.oss-cn-guangzhou.aliyuncs.com/images/20250918010843097.png" width="100%" height="100%" style="display: inline-block"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p style="text-align: left"&gt;&lt;/p&gt;&lt;p style="text-align: left"&gt;&lt;img src="https://moyutianzun.com/upload/image.png" width="100%" height="100%" style="display: inline-block"&gt;&lt;/p&gt;&lt;p style="text-align: left"&gt;include日录主要存放了编译器核心功能的.h头文件，提供约定和规范&lt;/p&gt;&lt;p style="text-align: left"&gt;lib是.c和.cpp，主要是功能的实现，和include一一对应&lt;/p&gt;</description></item><item><title>AMD 2025 分布式推理算子优化挑战赛——笔记</title><link>https://moyutianzun.com/blog/amd-2025-fen-bu-shi-tui-li-suan-zi-you-hua-tiao-zhan-sai----bi-ji/</link><pubDate>Tue, 09 Sep 2025 05:48:15 +0800</pubDate><guid>https://moyutianzun.com/blog/amd-2025-fen-bu-shi-tui-li-suan-zi-you-hua-tiao-zhan-sai----bi-ji/</guid><description>&lt;p style=""&gt;比赛提供的link：&lt;/p&gt;&lt;p style=""&gt;&lt;a href="https://modelscope.cn/competition/117/%E6%AF%94%E8%B5%9B%E7%AE%80%E4%BB%8B" target="_self" rel=""&gt;魔搭社区比赛首页&lt;/a&gt; &lt;a href="https://www.datamonsters.com/amd-developer-challenge-2025" target="_self" rel=""&gt;AMD比赛首页&lt;/a&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;a href="https://www.gpumode.com/v2/leaderboard/563?tab=rankings" target="_self" rel=""&gt;amd-all2all kernel Leaderboard&lt;/a&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;a href="https://github.com/gpu-mode/reference-kernels/tree/main/problems/amd_distributed" target="_self" rel=""&gt;reference-kernels&lt;/a&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;a href="https://discord.com/channels/" target="_self" rel=""&gt;discord link&lt;/a&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;a href="https://github.com/gpu-mode/popcorn-cli?tab=readme-ov-file" target="_self" rel=""&gt;Popcorn CLI&lt;/a&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;lect：&lt;/p&gt;&lt;p style=""&gt;&lt;a href="https://www.youtube.com/watch?v=dNWv3qYU60E" target="_self" rel=""&gt;ytb Bonus Lecture: AMD Developer Challenge&lt;/a&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;a href="https://stormy-sailor-96a.notion.site/Mixture-of-Experts-AMD-Problem-1d7221cc2ffa80f9b171c332aed16093" target="_self" rel=""&gt;Mixture of Experts AMD Problem&lt;/a&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;a href="https://moyutianzun.cn/archives/amd-2025-fen-bu-shi-tui-li-suan-zi-you-hua-tiao-zhan-sai------lect-9-16-note" target="_self" rel=""&gt;9/16 lect note&lt;/a&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;</description></item></channel></rss>