Skip to content

Instantly share code, notes, and snippets.

@wielandbrendel
Created February 16, 2015 16:14
Show Gist options
  • Select an option

  • Save wielandbrendel/8505669e9a54b0446ce5 to your computer and use it in GitHub Desktop.

Select an option

Save wielandbrendel/8505669e9a54b0446ce5 to your computer and use it in GitHub Desktop.
Using kernel_stretch from random.hpp from cudarray leaves input array unchanged
#include <stdio.h>
#include "random.hpp"
#define N 10
int main( void )
{
float a[N];
float alpha = 2;
float beta = 3;
unsigned int n = N;
float *dev_a;
for (int i = 0; i < N; i++){
a[i] = 1;
printf("%f\n", a[i]);
}
// allocate the memory on the GPU
cudaMalloc( (void**)&dev_a, N*sizeof(int) );
cudaMemcpy( dev_a, a, N*sizeof(int), cudaMemcpyHostToDevice );
cudarray::kernel_stretch<<<N,1>>>(dev_a, alpha, beta, n);
cudaMemcpy( a, dev_a, N*sizeof(int), cudaMemcpyDeviceToHost );
cudaFree( dev_a );
for (int i = 0; i < N; i++){
printf("%f\n", a[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment