#include "cuda_runtime.h" #include "device_launch_parameters.h" #include #define BLOCK_SIZE 2 #define GRID_SIZE 2 __global__ void addKernel(int *x) { x[0]++; return; } int main(int argc, char** argv) { int i; int* x = new int[1]; int* dev_x; int res_cpu; int* res_gpu = new int[1]; cudaMalloc((void**)&dev_x, sizeof(int)); *x = 4; // Számítás a GPU-n cudaMemcpy(dev_x, x, sizeof(int), cudaMemcpyHostToDevice); addKernel<<<2, 2>>>(dev_x); cudaMemcpy(res_gpu, dev_x, sizeof(int), cudaMemcpyDeviceToHost); // Számítás a CPU-n res_cpu = x[0]; for(i=0; i