主要内容

GPU执行分析生成的代码

这个例子向您展示了如何生成一个执行分析报告生成的CUDA®代码通过使用gpucoder.profile函数。

GPU编码器分析器运行software-in-the-loop (SIL)执行生产执行标准的任务和内核生成的代码。这个示例中生成一个执行分析报告雾整改GPU编码器的例子。有关更多信息,请参见雾整改

第三方的先决条件

  • CUDA NVIDIA GPU®启用。

  • NVIDIA CUDA工具包和司机。

  • 英伟达Nsight™系统。信息的支持版本的编译器和库,明白了金宝app第三方硬件

  • 环境变量的编译器和库。设置环境变量,看到设置必备产品下载188bet金宝搏

  • 本例的分析工作流取决于NVIDIA GPU访问性能计数器的分析工具。从CUDA工具包v10.1, NVIDIA限制访问性能计数器只有管理员用户。让GPU性能计数器被所有用户使用,见提供的指令许可问题性能计数器(英伟达)

验证GPU环境

验证所需的编译器和库运行这个示例设置正确,使用coder.checkGpuInstall函数。

envCfg = coder.gpuEnvConfig (“主机”);envCfg。BasicCodegen = 1;envCfg。安静= 1;coder.checkGpuInstall (envCfg);

雾矫正算法

改善雾蒙蒙的输入图像,该算法执行除雾然后对比度增强。图中显示了这两种操作的步骤。

这个例子需要一个雾蒙蒙的RGB图像作为输入。执行除雾,该算法估计图像的暗通道,计算空气光映射基于黑暗的通道,并改进空气光映射通过使用过滤器。恢复阶段创建一个除雾图像减去精制空气光从输入图像地图。

然后,对比度增强阶段评估的范围在图像强度值,并使用对比度拉伸值的范围扩大,使功能更清楚地脱颖而出。

FogRectificationAlgorithm.png

类型fog_rectification.m
函数[出]= fog_rectification(输入)% # codegen % 2017 - 2019版权MathWorks, inc . coder.gpu.kernelfun;% restoreOut用于存储的输出恢复restoreOut = 0(大小(输入),“双”);%改变输入图像的精度水平双输入=(输入)的两倍。/ 255;% %黑暗信道估计从输入darkChannel = min(输入,[],3);% diff_im作为输入和输出变量用于各向异性扩散diff_im = 0.9 * darkChannel;num_iter = 3;% 2 d卷积面具各向异性扩散hN = (0.0625 0.1250 0.0625;0.1250 0.2500 0.1250;0.0625 0.1250 0.0625);hN =双(hN); %% Refine dark channel using Anisotropic diffusion. for t = 1:num_iter diff_im = conv2(diff_im,hN,'same'); end %% Reduction with min diff_im = min(darkChannel,diff_im); diff_im = 0.6*diff_im ; %% Parallel element-wise math to compute % Restoration with inverse Koschmieder's law factor = 1.0./(1.0-(diff_im)); restoreOut(:,:,1) = (input(:,:,1)-diff_im).*factor; restoreOut(:,:,2) = (input(:,:,2)-diff_im).*factor; restoreOut(:,:,3) = (input(:,:,3)-diff_im).*factor; restoreOut = uint8(255.*restoreOut); restoreOut = uint8(restoreOut); %% % Stretching performs the histogram stretching of the image. % im is the input color image and p is cdf limit. % out is the contrast stretched image and cdf is the cumulative prob. % density function and T is the stretching function. p = 5; % RGB to grayscale conversion im_gray = im2gray(restoreOut); [row,col] = size(im_gray); % histogram calculation [count,~] = imhist(im_gray); prob = count'/(row*col); % cumulative Sum calculation cdf = cumsum(prob(:)); % finding less than particular probability i1 = length(find(cdf <= (p/100))); i2 = 255-length(find(cdf >= 1-(p/100))); o1 = floor(255*.10); o2 = floor(255*.90); t1 = (o1/i1)*[0:i1]; t2 = (((o2-o1)/(i2-i1))*[i1+1:i2])-(((o2-o1)/(i2-i1))*i1)+o1; t3 = (((255-o2)/(255-i2))*[i2+1:255])-(((255-o2)/(255-i2))*i2)+o2; T = (floor([t1 t2 t3])); restoreOut(restoreOut == 0) = 1; u1 = (restoreOut(:,:,1)); u2 = (restoreOut(:,:,2)); u3 = (restoreOut(:,:,3)); % Replacing the value from look up table out1 = T(u1); out2 = T(u2); out3 = T(u3); out = zeros([size(out1),3], 'uint8'); out(:,:,1) = uint8(out1); out(:,:,2) = uint8(out2); out(:,:,3) = uint8(out3); return

生成执行分析报告

代码生成一个执行分析报告,创建一个配置对象动态库(“dll”)建造类型。因为gpucoder。概要文件函数只接受一个嵌入式编码器™配置对象,使选项创建一个coder.EmbeddedCodeConfig配置对象。

cfg = coder.gpuConfig (“dll”,“是”,真正的);cfg.GpuConfig。MallocMode =“离散”;

运行gpucoder.profile使用默认阈值0秒。如果生成的代码有很多CUDA API或内核调用,很可能每个调用是只有一小部分的总时间。在这种情况下,设置一个低(零)阈值来生成有意义的分析报告。是不明智的执行数值设置为一个非常低的数量(小于5)因为它不产生一个精确的表示一个典型的执行概要。

inputImage = imread (“foggyInput.png”);输入= {inputImage};designFileName =“fog_rectification”;gpucoder.profile(designFileName, inputs,“CodegenConfig”cfg,“阈值”0,“我会”10);
代码生成成功:视图报告# # #银开始执行“fog_rectification”终止执行:明确fog_rectification_sil执行分析数据可供浏览。开放的仿真数据检查员。执行分析报告后终止。# # #主机应用程序产生以下标准错误(stderr)消息:警告:LBR回溯方法不支持这个平台。金宝app矮回溯方法将被使用。收集数据……# # #停止SIL执行“fog_rectification”

代码执行分析报告fog_rectification函数

代码执行分析报告提供度量基于收集的数据从一个银执行。执行时间计算从仪器探头记录的数据添加到硅公益诉讼测试工具或内部为每个组件生成的代码。有关更多信息,请参见视图执行时间(嵌入式编码)

这些数字是代表。实际值取决于你的硬件设置。这个分析是通过使用MATLAB R2022b的机器6核心,3.5 ghz Intel®Xeon®CPU、和NVIDIA GPU泰坦XP

总结

本节提供的信息创建报告。

异形的部分代码

本节包含有关异形代码部分。这份报告包含时间测量:

  • entry_point_fn_initialize例如,函数fog_rectification_initialize

  • 的入口点函数,例如,fog_rectification

  • entry_point_fn_terminate例如,函数fog_rectification_terminate

  • 部分列列表的名称的函数代码生成。

  • 最大执行时间是最长的时间开始和结束之间的代码部分。

  • 平均执行时间是开始和结束之间的平均时间的代码部分。

  • 最大的自我时间是最大执行时间,不包括子部分。

  • 平均自我时间平均执行时间,不包括子部分。

  • 调用显示调用代码部分的数量。

  • 查看执行度量代码部分在命令窗口中,在相应的行,点击图标icon_view_code_sect_obj.png

  • 显示测量执行时间,点击模拟数据检查员图标icon_simulation_data_inspectora5cc10a7e5374a15280c4ca6011f26f9.png。您可以使用模拟数据检查员管理和比较各种处决的情节。

  • 显示执行时期分布,单击图标code_exec_profiling_report_icon_frequency_distribution.png

默认情况下,该报告显示时间以毫秒为单位( 10 - - - - - - 3 秒)。您可以指定时间单位和数字显示格式。例如,显示时间以微秒为单位( 10 - - - - - - 6 秒),使用报告(嵌入式编码)命令:

executionProfile = getCoderExecutionProfile (“fog_rectification”);报告(executionProfile,“单位”,“秒”,“ScaleFactor”,“1 e-06”,“NumericFormat”,' % 0.3 f ')
ans = ' / local-ssd / lnarasim / MATLAB / ExampleManager / lnarasim.Bdoc22b.j1984243 / gpucoder-ex87489778 / codegen / dll / fog_rectification / html /孤儿/ ExecutionProfiling_f31bfb52dfefde93.html '

该报告只显示时间在秒如果计时器校准,即每秒计时器滴答数。在Windows®机器上,思科的软件确定这个值模拟。在Linux®机器上,您必须手动调整计时器。例如,如果您的3.5 GHz处理器速度,每秒指定计时器蜱虫的数量:

executionProfile。TimerTicksPerSecond = 3.5 e9;

执行时间的百分比

本节提供函数执行时间的调用方函数和总执行时间的百分比,它可以帮助你在生成的代码识别性能瓶颈。

GPU fog_rectification分析跟踪

第四节显示了完整的跟踪的GPU调用运行时高于阈值。分析跟踪显示的一个片段。

GPU fog_rectification分析总结

第五节在报告中显示了GPU的总结称,第四节所示。的cudaFree叫做15次跑的吗fog_rectification和的平均时间由15调用cudaFree超过9分的fog_rectification是1.3790毫秒。这个总结的降序排序时间让用户了解GPU称之为的最长时间。

定义

本节提供一些指标的描述。