Reputation: 11
I’m trying to compute on GPU, using OpenACC, the sum between two vectors of std::vector. As compiler I’m using GCC+NVPTX with OpenACC support but when I compile the code with these flags:
g++ -fopenacc -offload=nvptx-none -fopt-info-optimized-omp -g -std=c++17
But I got: “array_1 does not have pointer or array type” and “array_2 does not have pointer or array type”. Is there any way to use std::vector with OpenACC?
This a minimal reproducible example:
int main(int argc, char **argv) {
std::vector<std::vector<float>> array1,array2;
float result[1000]={0.0};
for(int i=0; i<1000; i++){
std::vector<float> accumulator1, accumulator2;
for (int j=0; j<1000; j++){
accumulator1.push_back(99.99);
accumulator2.push_back(66.66);
}
array1.push_back(accumulator1);
array2.push_back(accumulator2);
}
#pragma acc data copyin(array1[:1000][:1000],array2[:1000][:1000])
#pragma acc data copy(result[:1000])
#pragma acc parallel loop
for(int i=0; i<1000; i++){
for (int j=0; j<1000; j++){
result[i] += array1[i][j] + array2[i][j];
}
}
for(int i=0; i<10; i++){
std::cout << result[i] << std::endl;
}
return 0;
}
Compiling with GCC+NVPTX is mandatory for me, but also trying to compile it with nvc++ returns:
main:
18, Generating copyin(array1,array2) [if not already present]
Generating copy(result[:]) [if not already present]
Generating NVIDIA GPU code
23, #pragma acc loop gang, vector(128) /* blockIdx.x threadIdx.x */
24, #pragma acc loop seq
24, Complex loop carried dependence of prevents parallelization
Loop carried dependence of result prevents parallelization
Loop carried backward dependence of result prevents vectorization
std::vector<std::vector<float, std::allocator<float>>, std::allocator<std::vector<float, std::allocator<float>>>>::operator [](unsigned long):
3, include "vector"
64, include "stl_vector.h"
771, Generating implicit acc routine seq
Generating acc routine seq
Generating NVIDIA GPU code
std::vector<float, std::allocator<float>>::operator [](unsigned long):
3, include "vector"
64, include "stl_vector.h"
771, Generating implicit acc routine seq
Generating acc routine seq
Generating NVIDIA GPU code
And launching the application:
Failing in Thread:0
call to cuInit returned error 999: Unknown
Any advice? Thanks
Upvotes: 1
Views: 226