Created
March 3, 2020 14:37
-
-
Save hayunjong83/a33e267211837282e1849746dd3babbc to your computer and use it in GitHub Desktop.
SAXPY implementation with cublas library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cublas.h> | |
int main() | |
{ | |
int N = 1 << 16; | |
int size = N * sizeof(float); | |
float *h_x = (float*)malloc(size); | |
float *h_y = (float*)malloc(size); | |
for(int i = 0; i < N; i++) | |
{ | |
h_x[i] = 2.0; | |
h_y[i] = 2.0; | |
} | |
float *d_x; | |
float *d_y; | |
cublasInit(); | |
cublasAlloc(N, sizeof(float), (void**)&d_x); | |
cublasAlloc(N, sizeof(float), (void**)&d_y); | |
cublasSetVector(N, sizeof(float), h_x, 1, d_x, 1); | |
cublasSetVector(N, sizeof(float), h_y, 1, d_y, 1); | |
cublasSaxpy(N, 2.0, d_x, 1, d_y, 1); | |
cublasGetVector(N, sizeof(float), d_y, 1, h_y, 1); | |
cublasShutdown(); | |
cublasFree(d_x); | |
cublasFree(d_y); | |
free(h_x); | |
free(h_y); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment