▶ 《大规模并行处理器编程实战》第15章,关于OpenACC 的部分,散点
● OpenACC 中,主机存储器和设备存储器是分开处理的,程序员只要制定要传输的存储器对象即可,编译器会自动生成存储器的分配、复制和释放的代码
● OpenACC 不提供任何在执行单元之间的同步机制,只有在线程分支和聚合的时候才进行存储器栅栏同步(唯一的同步方式)
● 使用 parallel 构件时,OpenACC 会在加速器的上创建多个 gang 来执行并行域,每个 gang 默认状态下只有一个 worker(称为 gang lead),gang 的 数量可以通过子句 num_gangs(n) 来指定,worker 的数量可以通过子句 num_workers(n) 来指定。一旦指定,在下面的 parallel 结构体中 gang 和 worker 的数量就不再变化,类比 CUDA kernel 开始执行以后 grid 和 block 的尺寸就不再变化。
● gang 循环,parallel 构件中所有 gang 会被 loop gang 中所有迭代共享,如下代码中,1024 个 gang 共享 2048 个迭代(要求迭代之间独立,不然计算结果可能有问题),每个 gang 分到 2 个 迭代
1 #pragma acc parallel num_gang(1024) 2 { 3 #pragma acc loop gang 4 for (i = 0; i < 2048; i++) 5 { 6 ... 7 } 8 }