Cudamemcpy for different datatypes

I am reading an array from data acquisition device which is of type int16_t. I am copying the data to GPU with needs to be of type float.

Can I use cudamemcpy to copy int16_t array to float array?

I found a old thread which says it can’t be done. But would like to know is there any other way of doing it. Will reinterpret_cast help?

Presumably a conversion is required. A bulk copy of data does not just magically convert between different data representations.

We first need to determine what each int16_t data item represents. For example, it might be a purely fractional fixed-point value, so 0x7fff corresponds to 32767/32768 and 0x8000 corresponds to -32768/32768 meaning the values represented are in [-1, 0.9999695]. Each 16-bit data item may also represent any of a variety of fixed-point or floating-point formats, or some custom format. We will need the exact specifications of that.

The next thing we would want to take into consideration is how this data is being used by the GPU kernel. If it is loaded just once (GPU kernel either streams through the array or copies it into shared memory for reuse) it will be best to copy over the data unchanged (as a block of int16_t data items) and then convert each data item on the fly on the GPU side, during the first and only read access.

If kernel access patterns are more complicated, and there are many int16_t data items, it will likely be best to perform a bulk copy of the int16_t data to a device side buffer, then run a conversion kernel on the GPU that converts the data to float and writes the result to a second device-side buffer, which is then use as an input to you actual processing kernel.

The key principles here in terms of a high-performance design is to keep the data traveling across the PCIe interconnect between host and device as compact as possible, and to use the superior compute and memory throughput of the GPU (as compared to the host system) to perform the conversion.