gpt4 book ai didi

c - OpenMP 卸载到 nvptx 时 gcc 7 和 8 (debian) 的问题

转载 作者:太空宇宙 更新时间:2023-11-04 04:18:30 24 4
gpt4 key购买 nike

我都安装了 gcc-7 , gcc-8 , gcc-7-offload-nvptxgcc-8-offload-nvptx

我尝试同时使用两者来编译带卸载的简单 OpenMP 代码:

#include <omp.h>
#include <stdio.h>

int main(){
#pragma omp target
#pragma omp teams distribute parallel for
for (int i=0; i<omp_get_num_threads(); i++)
printf("%d in %d of %d\n",i,omp_get_thread_num(), omp_get_num_threads());
}

使用以下行(也使用 gcc-7):

gcc-8 code.c -fopenmp -foffload=nvptx-none

但是编译不通过,报如下错误:

/tmp/ccKESWcF.o: In function "main":
teste.c:(.text+0x50): undefined reference to "GOMP_target_ext"
/tmp/cc0iOH1Y.target.o: In function "init":
ccPXyu6Y.c:(.text+0x1d): undefined reference to "GOMP_offload_register_ver"
/tmp/cc0iOH1Y.target.o: In function "fini":
ccPXyu6Y.c:(.text+0x41): undefined reference to "GOMP_offload_unregister_ver"
collect2: error: ld returned 1 exit status

一些线索?

最佳答案

您的代码使用 -foffload=disable -fno-stack-protector 为我编译和运行与 gcc7gcc-7-offload-nvptx和 Ubuntu 17.10。

但在 GPU 上(没有 -foffload=disable )它无法编译。你不能调用 printf从GPU。相反,您可以这样做:

#include <omp.h>
#include <stdio.h>
#include <stdlib.h>

int main(){
int nthreads;
#pragma omp target teams map(tofrom:nthreads)
#pragma omp parallel
#pragma omp single
nthreads = omp_get_num_threads();

int *ithreads = malloc(sizeof *ithreads *nthreads);

#pragma omp target teams distribute parallel for map(tofrom:ithreads[0:nthreads])
for (int i=0; i<nthreads; i++) ithreads[i] = omp_get_thread_num();

for (int i=0; i<nthreads; i++)
printf("%d in %d of %d\n", i, ithreads[i], nthreads);

free(ithreads);
}

对我来说这个输出

0 in 0 of 8
1 in 0 of 8
2 in 0 of 8
3 in 0 of 8
4 in 0 of 8
5 in 0 of 8
6 in 0 of 8
7 in 0 of 8

关于c - OpenMP 卸载到 nvptx 时 gcc 7 和 8 (debian) 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49309557/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com