double to float conversion

hi everyone,

i am trying to implement a code such that it truncates a double number(/variable) to a float. but i cant seem to get it working. I have a strong feeling the fact that i only got a GPU that supports single precision (float only) has a lot to do with it.

[codebox]#include <cuda.h>

#include <math.h>

#include “mem_trunc.h”

// globals

// contains information about maximum allowable sizes

static int max_threads=0;

//function prototypes

global void mem_dtf (double *, int );

//condenses double storage to float

global void mem_dtf (double * array_, int elements){ /to be executed on device only/

int i=blockIdx.x*blockDim.x+threadIdx.x;/*thread number*/

float *temp=NULL;

temp=(float *)array_;

if (i<elements)



void call_mem_dtf (void *array_, int elements){

dim3 dimBlock (max_threads,1);

dim3 dimGrid((int)ceil((float)elements/max_threads),1);

mem_dtf <<<dimBlock, dimGrid>>>((double *)array_, elements) ;


void set_max_thread (int threads){



dw abt threads- that is set by me from a c function (main) and i dont think thats where the error is.

my question is how can i truncate a double to a float in a GPU that only supports single precision (compute capability 1.1)

any suggestions?



Since your hardware doesn’t understand double precision, there’s no way it can convert from double to float in a kernel. The only way to do this would be to cast the data to a different 64-bit type like uint2 and then extract the bits using bit arithmetic.