mirror of
https://github.com/epasveer/seer.git
synced 2026-08-30 00:50:42 +08:00
28 lines
369 B
Plaintext
28 lines
369 B
Plaintext
#include "stdio.h"
|
|
|
|
__global__ void add(int a, int b, int *c) {
|
|
*c = a + b;
|
|
}
|
|
|
|
int main() {
|
|
|
|
int a,b,c;
|
|
int* dev_c;
|
|
|
|
a=3;
|
|
b=4;
|
|
|
|
cudaMalloc((void**)&dev_c, sizeof(int));
|
|
|
|
add<<<1,1>>>(a,b,dev_c);
|
|
|
|
cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);
|
|
|
|
printf("%d + %d is %d\n", a, b, c);
|
|
|
|
cudaFree(dev_c);
|
|
|
|
return 0;
|
|
}
|
|
|