Retaining dot product on GPGPU using CUBLAS routine

前端 未结 2 1104
天命终不由人
天命终不由人 2020-12-11 20:44

I am writing a code to compute dot product of two vectors using CUBLAS routine of dot product but it returns the value in host memory. I want to use the dot product for furt

2条回答
  •  不知归路
    2020-12-11 21:30

    You can do this in CUBLAS as long as you use the "V2" API. The newer API includes a function cublasSetPointerMode which you can use to set the API to assume that all routines which return a scalar value will be passed a device pointer rather than a host pointer. This is discussed in Section 2.4 of the latest CUBLAS documentation. For example:

    #include 
    #include 
    #include 
    
    int main(void)
    {
        const int nvals = 10;
        const size_t sz = sizeof(double) * (size_t)nvals;
        double x[nvals], y[nvals];
        double *x_, *y_, *result_;
        double result=0., resulth=0.;
    
        for(int i=0; i

    Using CUBLAS_POINTER_MODE_DEVICE makes cublasDdot assume that result_ is a device pointer, and there is no attempt made to copy the result back to the host. Note that this makes routines like dot asynchronous, so you might need to keep on eye on synchronization between device and host.

提交回复
热议问题