The following source codes show different results when run on the CPU and the GPU respectively. In view of this, I would like to ask if the NVIDIA Tesla C870 follows the IEEE floating-point convention. If not, what convention does it follow. In other words, what is the reason for such a difference.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - cpu.c - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#include “stdio.h”
main(){
float n = 1.0;
int i;
for(i = 1; i <= 100; i++) printf(“%d\t\t%42.41f\n”, i, n *= 1.02);
}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - cpu.c - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - gpu.cu - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#include “stdio.h”
global void kernel(int i, float *d_n){
*d_n *= 1.02;
}
main(){
float n = 1.0, *d_n;
int i;
cudaMalloc((void **)&d_n, sizeof(float));
for(i = 1; i <= 100; i++){
cudaMemcpy(d_n, &n, sizeof(float), cudaMemcpyHostToDevice);
kernel <<< 1, 1 >>> (i, d_n);
cudaMemcpy(&n, d_n, sizeof(float), cudaMemcpyDeviceToHost);
printf(“%d\t\t%42.41f\n”, i, n);
}
}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - gpu.cu - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx