forked from XimingCheng/webgpu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenACC_Vector_Addition.cpp
More file actions
36 lines (28 loc) · 1.01 KB
/
OpenACC_Vector_Addition.cpp
File metadata and controls
36 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <wb.h>
void addVector(float* A, float* B, float* C, int inputLength) {
#pragma acc parallel loop copyin(A[0:inputLength]) copyin(B[0:inputLength]) copyout(C[0:inputLength])
#pragma acc loop
for (int i = 0; i < inputLength; i++) {
C[i] = A[i] + B[i];
}
}
int main(int argc, char **argv) {
wbArg_t args;
int inputLength;
float *hostInput1;
float *hostInput2;
float *hostOutput;
args = wbArg_read(argc, argv);
wbTime_start(Generic, "Importing data and creating memory on host");
hostInput1 = (float *)wbImport(wbArg_getInputFile(args, 0), &inputLength);
hostInput2 = (float *)wbImport(wbArg_getInputFile(args, 1), &inputLength);
hostOutput = (float *)malloc(inputLength * sizeof(float));
wbTime_stop(Generic, "Importing data and creating memory on host");
wbLog(TRACE, "The input length is ", inputLength);
addVector(hostInput1, hostInput2, hostOutput, inputLength);
wbSolution(args, hostOutput, inputLength);
free(hostInput1);
free(hostInput2);
free(hostOutput);
return 0;
}