Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22006

How to call cuda libraries from OpenACC C++ code by g++?

$
0
0

I want to use cuda libraries (cublas, cusparse cusolver) in OpenACC code by g++-8.

Can g++-8 use cuda libraries like PGI?

I wrote following code, that needs cublas or cublas_v2.

// #include<cublas.h>
#include<cublas_v2.h>
int main(){

//...allocate and initialize data...//

#pragma acc data copy(x[0:size], y[0:size])                   
        {                                                     
#pragma acc host_data use_device(x,y)                         
                {                                             
                        //dot = cublasDdot(size, x, 1, y, 1); 
                        cublasDdot(h, size, x, 1, y, 1, &dot);
                }
        } 
}

compile command is here: (These libraries are exists.)

 g++-8 -fopenacc -foffload=nvptx-none \
        -foffload="-I/usr/local/cuda-10.1/targets/x86_64-linux/include/ \
        -L/usr/local/cuda-10.1/targets/x86_64-linux/lib/ \
        -L/usr/lib/x86_64-linux-gnu/ \
        -lcuda -lcudart -lcublas" -O3 -std=c++11 acc_cublas.cpp -o acc_cublas.o

It cause a compilation error. Following error is occured:

acc_cublas.cpp:(.text.startup+0x11f): undefined reference to `cublasCreate_v2'
acc_cublas.cpp:(.text.startup+0x1b4): undefined reference to `cublasDdot_v2'

Is this compile command correct? Why can't find functions?

I created my environment based on nvidia/cuda:10.1-devel by executing following commands:

apt install -y gcc-8-offload-nvptx nvptx-tools g++-8
apt install -y cuda-cublas-dev-10-0
apt install -y cuda-cudart-dev-10-0

I got the correct answer in the following program that does not use cuda libraries:

#pragma acc data copy(x[0:size], y[0:size])
        {
#pragma acc kernels
                {
#pragma acc loop reduction ( + : dot)
                        for(int i=0; i<size; i++){
                                dot += x[i] * y[i];
                        }
                }
        }


Viewing all articles
Browse latest Browse all 22006

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>