Created
July 26, 2013 10:55
-
-
Save rofirrim/6088016 to your computer and use it in GitHub Desktop.
This file contains 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 <iostream> | |
#include <assert.h> | |
#include <math.h> | |
__global__ void f(float sum, int B, float *z, float *z2) | |
{ | |
*z = sum / B; | |
*z2 = sum / (float)B; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
float a = 3 + argc; | |
int b = 2 + argc; | |
std::cerr << a << " / " << b << " = " << std::endl; | |
float z; | |
float *dev_ptr_z; | |
cudaMalloc(&dev_ptr_z, sizeof(*dev_ptr_z)); | |
float z2; | |
float *dev_ptr_z2; | |
cudaMalloc(&dev_ptr_z2, sizeof(*dev_ptr_z2)); | |
f<<<1,1>>>(a, b, dev_ptr_z, dev_ptr_z2); | |
cudaDeviceSynchronize(); | |
cudaMemcpy(&z, dev_ptr_z, sizeof(z), cudaMemcpyDeviceToHost); | |
cudaMemcpy(&z2, dev_ptr_z2, sizeof(z2), cudaMemcpyDeviceToHost); | |
cudaFree(dev_ptr_z); | |
cudaFree(dev_ptr_z2); | |
std::cerr << "z = " << z << " " << std::hex << (*(int*)&z) << std::dec << std::endl; | |
std::cerr << "z2 = " << z2 << " " << std::hex << (*(int*)&z2) << std::dec << std::endl; | |
assert(z == z2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment