Created
February 16, 2015 16:14
-
-
Save wielandbrendel/8505669e9a54b0446ce5 to your computer and use it in GitHub Desktop.
Using kernel_stretch from random.hpp from cudarray leaves input array unchanged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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