OpenACC 计算构建内的自定义函数
▶ 使用 routine 构件创建的自定义函数,在并行调用上的差别
● 代码,自定义一个 sqab 函数,使用内建函数 fabsf 和 sqrtf 计算一个矩阵所有元素绝对值的平方根
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <openacc.h> #define ROW 8
#define COL 64 #pragma acc routine vector
void sqab(float *a, const int m)
{
#pragma acc loop
for (int idx = ; idx < m; idx++)
a[idx] = sqrtf(fabsf(a[idx]));
} int main()
{
float x[ROW][COL];
int row, col;
for (row = ; row < ROW; row++)
{
for (col = ; col < COL; col++)
x[row][col] = row * + col;
}
printf("\nx[1][1] = %f\n", x[][]); #pragma acc parallel loop vector pcopy(x[0:ROW][0:COL]) // 之后在这里分别添加 gang,worker,vector
for (row = ; row < ROW; row++)
sqab(&x[row][], COL);
printf("\nx[1][1] = %f\n", x[][]); //getchar();
return ;
}
● 输出结果,第 28 行不添加并行级别子句(默认使用 gang)
D:\Code\OpenACC\OpenACCProject\OpenACCProject>pgcc main.c -acc -Minfo -o main_acc.exe
sqab:
, Generating Tesla code
, #pragma acc loop vector /* threadIdx.x */
, Loop is parallelizable
main:
, Generating copy(x[:][:])
Accelerator kernel generated
Generating Tesla code
, #pragma acc loop gang /* blockIdx.x */ D:\Code\OpenACC\OpenACCProject\OpenACCProject>main_acc.exe x[][] = 11.000000
launch CUDA kernel file=D:\Code\OpenACC\OpenACCProject\OpenACCProject\main.c function=main
line= device= threadid= num_gangs= num_workers= vector_length= grid= block= // 8 个 gang 在 blockIdx.x 层级,1 个 worker,vector 在 threadIdx.x 层级 x[][] = 3.316625
PGI: "acc_shutdown" not detected, performance results might be incomplete.
Please add the call "acc_shutdown(acc_device_nvidia)" to the end of your application to ensure that the performance results are complete. Accelerator Kernel Timing data
D:\Code\OpenACC\OpenACCProject\OpenACCProject\main.c
main NVIDIA devicenum=
time(us):
: compute region reached time
: kernel launched time
grid: [] block: []
elapsed time(us): total= max= min= avg=
: data region reached times
: data copyin transfers:
device time(us): total= max= min= avg=
: data copyout transfers:
device time(us): total= max= min= avg=
● 输出结果,第 28 行添加并行级别子句 worker
D:\Code\OpenACC\OpenACCProject\OpenACCProject>pgcc main.c -acc -Minfo -o main_acc.exe
sqab:
, Generating Tesla code
, #pragma acc loop vector /* threadIdx.x */
, Loop is parallelizable
main:
, Generating copy(x[:][:])
Accelerator kernel generated
Generating Tesla code
, #pragma acc loop worker(4) /* threadIdx.y */
, Loop is parallelizable D:\Code\OpenACC\OpenACCProject\OpenACCProject>main_acc.exe x[][] = 11.000000
launch CUDA kernel file=D:\Code\OpenACC\OpenACCProject\OpenACCProject\main.c function=main
line= device= threadid= num_gangs= num_workers= vector_length= grid= block=32x4 // 1 个 gang,4 个 worker 在 threadIdx.y 层级,使用 2 维线程网格 x[][] = 3.316625
PGI: "acc_shutdown" not detected, performance results might be incomplete.
Please add the call "acc_shutdown(acc_device_nvidia)" to the end of your application to ensure that the performance results are complete. Accelerator Kernel Timing data
D:\Code\OpenACC\OpenACCProject\OpenACCProject\main.c
main NVIDIA devicenum=
time(us):
: compute region reached time
: kernel launched time
grid: [] block: [32x4]
device time(us): total= max= min= avg=
: data region reached times
: data copyin transfers:
device time(us): total= max= min= avg=
: data copyout transfers:
device time(us): total= max= min= avg=
● 输出结果,第 28 行添加并行级别子句 vector
D:\Code\OpenACC\OpenACCProject\OpenACCProject>pgcc main.c -acc -Minfo -o main_acc.exe
sqab:
, Generating Tesla code
, #pragma acc loop vector /* threadIdx.x */
, Loop is parallelizable
main:
, Generating copy(x[:][:])
Accelerator kernel generated
Generating Tesla code
, #pragma acc loop seq
, Loop is parallelizable D:\Code\OpenACC\OpenACCProject\OpenACCProject>main_acc.exe x[][] = 11.000000
launch CUDA kernel file=D:\Code\OpenACC\OpenACCProject\OpenACCProject\main.c function=main
line= device= threadid= num_gangs= num_workers= vector_length= grid= block= // 1 个 gang,1 个 worker,并行全都堆在 threadIdx.x 层级上 x[][] = 3.316625
PGI: "acc_shutdown" not detected, performance results might be incomplete.
Please add the call "acc_shutdown(acc_device_nvidia)" to the end of your application to ensure that the performance results are complete. Accelerator Kernel Timing data
D:\Code\OpenACC\OpenACCProject\OpenACCProject\main.c
main NVIDIA devicenum=
time(us):
: compute region reached time
: kernel launched time
grid: [] block: []
elapsed time(us): total= max= min= avg=
: data region reached times
: data copyin transfers:
device time(us): total= max= min= avg=
: data copyout transfers:
device time(us): total= max= min= avg=
● 如果自定义函数并行子句等级高于主调函数,则主调函数并行子句会变成 seq;如果自定义函数并行子句等级低于内部并行子句等级,则会报 warning,忽略掉内部并行子句:
#pragma acc routine vector
void sqab(float *a, const int m)
{
#pragma acc loop worker
for (int idx = ; idx < m; idx++)
a[idx] = sqrtf(fabsf(a[idx]));
}
● 编译结果(运行结果通上面的 worker,不写)
D:\Code\OpenACC\OpenACCProject\OpenACCProject>pgcc main.c -acc -Minfo -o main_acc.exe
PGC-W--acc loop worker clause ignored in acc routine vector procedure (main.c: )
sqab:
, Generating Tesla code
, #pragma acc loop vector /* threadIdx.x */
, Loop is parallelizable
OpenACC 计算构建内的自定义函数的更多相关文章
- SQL Server 2008 R2——使用计算列为表创建自定义的自增列
=================================版权声明================================= 版权声明:原创文章 谢绝转载 请通过右侧公告中的“联系邮 ...
- hive的内置函数和自定义函数
一.内置函数 1.一般常用函数 .取整函数 round() 当传入第二个参数则为精度 bround() 银行家舍入法:为5时,前一位为偶则舍,奇则进. .向下取整 floor() .向上取整 ceil ...
- python自定义函数和内置函数
函数 1.定义 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 先定义,后使用 1.2分类 系统函数 自定义函数 1.3语法: def functionname(parameter ...
- [VBA]发布一个计算桩号之差的Excel自定义函数(VBA)
这是一个可以计算桩号之差(也就是得到长度)的Excel(或WPS)扩展函数,可以减少工程师在统计工程量时的工作量. 该函数具有一定的通用性.可以在MS Office和金山WPS上使用. 文末会给出使用 ...
- 5.Smart使用内置函数或者自定义函数
1.使用内置函数 例如使用date函数 {"Y-m-d"|date:$time}格式{第一个参数|方法:第二个参数:第三个参数}即可转换成 2016-07-19 2.使用resi ...
- JSP第四篇【EL表达式介绍、获取各类数据、11个内置对象、执行运算、回显数据、自定义函数、fn方法库】
什么是EL表达式? 表达式语言(Expression Language,EL),EL表达式是用"${}"括起来的脚本,用来更方便的读取对象! EL表达式主要用来读取数据,进行内容的 ...
- Python之函数(自定义函数,内置函数,装饰器,迭代器,生成器)
Python之函数(自定义函数,内置函数,装饰器,迭代器,生成器) 1.初始函数 2.函数嵌套及作用域 3.装饰器 4.迭代器和生成器 6.内置函数 7.递归函数 8.匿名函数
- Hive内置函数和自定义函数的使用
一.内置函数的使用 查看当前hive版本支持的所有内置函数 show function; 查看某个函数的使用方法及作用,比如查看upper函数 desc function upper; 查看upper ...
- 利用函数计算构建微信小程序的Server端
10分钟上线 - 利用函数计算构建微信小程序的Server端-博客-云栖社区-阿里云 https://yq.aliyun.com/articles/435430 函数计算 读写 oss import ...
随机推荐
- 为什么我们不应该使用微信或者 QQ 作为团队协作的 IM 工具?
如果你的团队没有觉得微信是低效的团队 IM 工具,那只有两种可能: 团队成员很少使用微信进行私人的生活和娱乐. 你就是一个低效的团队,而且还不自知. 本文内容 微信,连接一切 每个人都有微信 微信,低 ...
- Ordering Tasks 拓扑排序
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...
- 【问题】PPS、PPSX自动放映格式打开直接进入编辑模式
在做自动放映格式的PPT的时候,发现另存为PPS或PPSX格式后,自动放映无法实现,而是直接进入了PPT编辑模式,于是开始寻找原因.发现是文件关联有问题,这与安装多个版本的ppt有关系. 解决办法: ...
- 在Docker中运行crontab
在把自己的项目通过Docker进行打包时,由于项目中用到了crontab,不过使用到的基础镜像python:3.6-slim并没有安装这项服务,记录下在镜像中安装和配置crontab的过程. Dock ...
- JSONObject JSONArray json字符串 HashMap ArryList 在java开发中用到的数据结构
1.JSONObject 长成这样的: { "key1":value1, "key2":value2, "key3":value3} ...
- 复制IE缓存里多个文件的方法
IE8缓存地址可以自己设置,要复制里面的文件,需要点小技巧: 真正的文件在E:\baidu download\Internet 临时文件\content.ie5下面:E:\baidu download ...
- APP自动化测试各项指标分析
一.内存分析专项 启动App. DDMS->update heap 操作app,点几次GC dump heap hprof-conv转化 MAT分析 二.区分几种内存 VSS- Virtual ...
- 写了一篇关于 FastAdmin 插件路由的分析文章
写了一篇关于 FastAdmin 插件路由的分析文章 插件路由演示 ThinkPHP 的路由就像是整个应用的调度室,让你的应用 url 更友好,而且让应用更安全,不会让真实的地址暴露出去. 了解过 L ...
- java 访问修饰符:public protected default private
- 51nod 1673 树有几多愁——虚树+状压DP
题目:http://www.51nod.com/Challenge/Problem.html#!#problemId=1673 建一个虚树. 一种贪心的想法是把较小的值填到叶子上,这样一个小值限制到的 ...