/*
Copyright (C) 2012 fmaj7b5.info
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include
#include "hello.cuh"
using namespace FM7b5;
__device__ const char str[] = "Hello CUDA!";
__global__ void hello(char* buf)
{
const size_t idx = threadIdx.x;
if (idx < sizeof(str)) {
buf[idx] = str[idx];
}
}
void FM7b5::hello_gpu(char* buf)
{
const size_t num_str(sizeof(str));
char* d_buf(nullptr);
cudaMalloc(&d_buf, sizeof(char) * num_str);
hello<<<1, num_str>>>(d_buf);
cudaMemcpy(buf, d_buf, sizeof(char) * num_str, cudaMemcpyDeviceToHost);
cudaFree(d_buf);
}