VS查看PTX代码

article/2025/9/13 14:48:51
首先,声明本人用的是Windows 7操作系统,使用Windows 8操作系统的小伙伴们会启动不了Nsight monitor,原因在于Windows 8操作系统的Framework版本过新,解决办法可以是:安装一个版本旧一点的Matlab,安装起初会提示下载安装旧版本的Framework,安装完成Framework就可以停止安装Matlab了,Nsight monitor也可以启动了。
        下面回到正题,如何在VS中查看PTX代码呢?在此举个例子,按照这个步骤便可以查看到了。

        本人使用的代码是CUDA自带的一个Sample:
C/C++ code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
 
#include <stdio.h>
 
cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size);
 
__global__ void addKernel(int *c, const int *a, const int *b)
{
    int i = threadIdx.x;
    c[i] = a[i] + b[i];
}
 
int main()
{
    const int arraySize = 5;
    const int a[arraySize] = { 1, 2, 3, 4, 5 };
    const int b[arraySize] = { 10, 20, 30, 40, 50 };
    int c[arraySize] = { 0 };
 
    // Add vectors in parallel.
    cudaError_t cudaStatus = addWithCuda(c, a, b, arraySize);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "addWithCuda failed!");
        return 1;
    }
 
    printf("{1,2,3,4,5} + {10,20,30,40,50} = {%d,%d,%d,%d,%d}\n",
        c[0], c[1], c[2], c[3], c[4]);
 
    // cudaDeviceReset must be called before exiting in order for profiling and
    // tracing tools such as Nsight and Visual Profiler to show complete traces.
    cudaStatus = cudaDeviceReset();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceReset failed!");
        return 1;
    }
 
    return 0;
}
 
// Helper function for using CUDA to add vectors in parallel.
cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size)
{
    int *dev_a = 0;
    int *dev_b = 0;
    int *dev_c = 0;
    cudaError_t cudaStatus;
 
    // Choose which GPU to run on, change this on a multi-GPU system.
    cudaStatus = cudaSetDevice(0);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?");
        goto Error;
    }
 
    // Allocate GPU buffers for three vectors (two input, one output)    .
    cudaStatus = cudaMalloc((void**)&dev_c, size * sizeof(int));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }
 
    cudaStatus = cudaMalloc((void**)&dev_a, size * sizeof(int));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }
 
    cudaStatus = cudaMalloc((void**)&dev_b, size * sizeof(int));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
        goto Error;
    }
 
    // Copy input vectors from host memory to GPU buffers.
    cudaStatus = cudaMemcpy(dev_a, a, size * sizeof(int), cudaMemcpyHostToDevice);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }
 
    cudaStatus = cudaMemcpy(dev_b, b, size * sizeof(int), cudaMemcpyHostToDevice);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }
 
    // Launch a kernel on the GPU with one thread for each element.
    addKernel<<<1, size>>>(dev_c, dev_a, dev_b);
 
    // Check for any errors launching the kernel
    cudaStatus = cudaGetLastError();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "addKernel launch failed: %s\n", cudaGetErrorString(cudaStatus));
        goto Error;
    }
     
    // cudaDeviceSynchronize waits for the kernel to finish, and returns
    // any errors encountered during the launch.
    cudaStatus = cudaDeviceSynchronize();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching addKernel!\n", cudaStatus);
        goto Error;
    }
 
    // Copy output vector from GPU buffer to host memory.
    cudaStatus = cudaMemcpy(c, dev_c, size * sizeof(int), cudaMemcpyDeviceToHost);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
        goto Error;
    }
 
Error:
    cudaFree(dev_c);
    cudaFree(dev_a);
    cudaFree(dev_b);
     
    return cudaStatus;
}

  1. 确定不适用Nsight安全连接,即下图最后一项为False。


2. 启动Nsight monitor,选择“开始性能分析”


3. 选择Profile CUDA Application,并且将Collect information for CUDA Source View勾选上。


 4. Launch!

5. 切换界面后,左上角选择Source and PTX。


6. 在视图中看到左边是源代码,右边绿色区域是对应某一行源代码的PTX代码。



        其实,Nsight Monitor还是有很强大的功能的,感兴趣的小伙伴们可以自己翻翻手册和资料~

http://chatgpt.dhexx.cn/article/PJqtObTi.shtml

相关文章

Nvidia Tensor Core-MMA PTX编程入门

目录 1 PTX (Parallel Thread Execution) 2 MMA (Matrix Multiply Accumulate) PTX 3 LDMATRIX PTX 4 示例 5 底层代码 6 其他 6.1 HGEMM优化 1 PTX (Parallel Thread Execution) PTX是什么&#xff0c;Nvidia官方描述为a low-level parallel thread execution virtual…

PTX ISA 7.4 参考手册翻译

文章目录 PTX Parallel Thread Execution ISA 7.4SynataxSource FormatCommentsStatementsinstruction identifiersInteger ConstantFloat-Point ConstantConstant expression整型常量表达式求值 State Spaces, Types, and Variables状态空间Kernel Function ParametersKernel …

CUDA PTX ISA阅读笔记(一)

不知道这是个啥的看这里&#xff1a;Parallel Thread Execution ISA Version 5.0. 简要来说&#xff0c;PTX就是.cu代码编译出来的一种东西&#xff0c;然后再由PTX编译生成执行代码。如果不想看网页版&#xff0c;cuda的安装目录下的doc文件夹里有pdf版本&#xff0c;看起来也…

CUDA进阶第二篇:巧用PTX

写在前面 并行线程执行&#xff08;Parallel Thread eXecution&#xff0c;PTX&#xff09;代码是编译后的GPU代码的一种中间形式&#xff0c;它可以再次编译为原生的GPU微码。CUDA 手册传送门&#xff1a;Parallel Thread Execution ISA Version 4.3 利用PTX来进行试验&…

一文了解GPU并行计算CUDA

了解GPU并行计算CUDA 一、CUDA和GPU简介二、GPU工作原理与结构2.1、基础GPU架构2.2、GPU编程模型2.3、软件和硬件的对应关系 三、GPU应用领域四、GPUCPU异构计算五、MPI与CUDA的区别 一、CUDA和GPU简介 CUDA&#xff08;Compute Unified Device Architecture&#xff09;&…

MPI 并行

MPI from b站视频 超算小白-灵犀学院 click &#xff08;一&#xff09;基本框架 头文件 mpi.h #include "mpi.h"初始化函数&#xff1a;MPI_Init( ) MPI_Init(int *argc, char ***argv)完成MPI程序初始化工作&#xff0c;通过获取main函数的参数&#xff0c;让…

C# 并行编程

一 并行任务库TPL 1 并行任务库&#xff08;TPL&#xff0c;Task Parallel Library&#xff09; 2 最重要的是Task类&#xff0c;还有Parallel类 3 Task类&#xff0c;是利用线程池来进行任务的执行 比如直接用ThreadPool更优化&#xff0c;而且编程更方便 4 Paallel类&…

并行处理及分布式系统

并行处理及分布式系统 1 为什么要并行计算 1.1 为什么需要不断提升性能 随着计算能力的增加&#xff0c;我们所面临的计算问题和需求也在增加随着技术的进步&#xff0c;我们从未想过的技术得到了解决&#xff0c;比如&#xff1a;人类基因解码、更准确的医疗成像、更快速准…

并行计算之MPI(一)

MPI学习 1. 了解并行计算 为什么要采用并行计算&#xff1f; &#xff08;1&#xff09;这是因为它可以加快速度即在更短的时间内解决相同的问题或在相同的时间内解决更多更复杂的问题特别是对一些新出现的巨大挑战问题&#xff1b; &#xff08;2&#xff09;节省投入并行计…

并行网关

1、并行网关 假设现在我们想在旁边放一份沙拉。无论如何&#xff0c;如果你想要沙拉&#xff0c;你可以像我们在图1.1中所做的那样建模。 图1.1:准备沙拉和主菜。 在这里&#xff0c;我们介绍了另一个符号&#xff1a;(文本)注释&#xff1b;这是一个您可以与任何流对象(在本…

并行计算:循环程序并行化的一般方法

一、数据划分和处理器指派 1. 带状划分方法 又叫做行列划分&#xff0c;就是将矩阵的整行或整列分成若干组&#xff0c;各组指派给一个处理器。 例如&#xff1a;设矩阵A由n行和m列&#xff0c;对其串行处理的程序段如下&#xff1a; for i1 to n dofor j1 to m doProcess(a[…

并行计算之MPI(三)

了解MPI 什么是MPI &#xff08;1&#xff09;MPI是一个库而不是一门语言&#xff0c;许多人认为MPI就是一种并行语言&#xff0c;这是不准确的。但是按照并行语言的分类可以把FORTRANMPI或CMPI。看作是一种在原来串行语言基础之上扩展后得到的并行语言&#xff0c;MPI库可以被…

并行计算的一些思考与总结

弗林分类法 根据弗林分类法&#xff0c;计算机结构主要分为 SIMD----单指令、多数据MIMD---多指令、多数据SISD----单指令、单数据MISD---多指令、单数据 一般的串行程序中为SISD&#xff0c;即在单核CPU下任何时间和地点只有一个指令处理一个数据&#xff0c;其所谓的多线程…

并行计算之MPI(二)

1.并行编程模型 目前两种最重要的并行编程模型是数据并行和消息传递数据并行编程模型的编程级别比较高编程相对简单但它仅适用于数据并行问题消息传递编程模型的编程级别相对较低但消息传递编程模型可以有更广泛的应用范围。 数据并行即将相同的操作同时作用于不同的数据因此…

Matlab 并行

Matlab 并行 1. 检查是否有并行附加功能2. 创建和删除并行2.1 创建默认的并行池2.2 在本地创建2.3 在集群创建2.4 删除 3. Parallel pool 包含的一些函数3.1 parfor3.2 parfeval 初学&#xff0c;肯定有理解不够的地方。看官方文件更靠谱。 1. 检查是否有并行附加功能 如果没有…

并行处理及分布式系统期末总结笔记

并行处理及分布式系统期末总结笔记 1、任务并行、数据并行的应用2、冯诺依曼体系结构的瓶颈及改进&#xff0c;Flynn分类法涉及的几种模型及其特点3、Cache的特点&#xff0c;Cache缺失、Cache命中、Cache一致性及解决方法、伪共享、流水线、多发射4、加速比、效率、阿姆达尔定…

并行程序设计导论期末复习

任务并行、数据并行的应用 任务并行 将待解决问题所需要执行的各个任务分配到各个核上执行。 数据并行 将待解决问题所需要处理的数据分配给各个核&#xff0c;每个核在分配到的数据集上执行大致相似的操作。 冯诺依曼体系结构的瓶颈及改进&#xff0c;Flynn分类法涉及的几…

并行程序设计导论 概念总结

Parallel Programing caiyi 2021/6/17 第一章 1.为什么要构建并行系统? 电路晶体管密度过大会使处理器能耗增加&#xff0c;散热的问题使通过继续增快集成电路密度提高处理器性能不再现实&#xff0c;因此集成电路商决定构建多核处理器。 2.为什么要编写并行程序&#xf…

cuda 并行计算

1 简介 2006年&#xff0c;NVIDIA公司发布了CUDA&#xff0c;CUDA是建立在NVIDIA的GPU上的一个通用并行计算平台和编程模型&#xff0c;基于CUDA编程可以利用GPU的并行计算引擎来更加高效地解决比较复杂的计算难题。CUDA是NVIDIA公司所开发的GPU编程模型&#xff0c;它提供了GP…

数据 并行

first 含义是计算机内包含一组处理单元&#xff08;PE&#xff09;&#xff0c;每一个处理单元存储一个&#xff08;或多个&#xff09;数据元素。当机器执行顺序程序时&#xff0c;可对应于全部或部分的内部处理单元所存的数据同时操作。 将并行处理技术引入信息检索领域 把数…