11 #include "Float16.cuh"
12 #include "nvidia/fp16_emu.cuh"
13 #include <thrust/execution_policy.h>
14 #include <thrust/transform.h>
16 #ifdef FAISS_USE_FLOAT16
18 namespace faiss {
namespace gpu {
20 bool getDeviceSupportsFloat16Math(
int device) {
21 const auto& prop = getDeviceProperties(device);
23 return (prop.major >= 6 ||
24 (prop.major == 5 && prop.minor >= 3));
28 __device__ half operator()(
float v)
const {
return __float2half(v); }
32 __device__
float operator()(half v)
const {
return __half2float(v); }
35 void runConvertToFloat16(half* out,
38 cudaStream_t stream) {
39 thrust::transform(thrust::cuda::par.on(stream),
40 in, in + num, out, FloatToHalf());
43 void runConvertToFloat32(
float* out,
46 cudaStream_t stream) {
47 thrust::transform(thrust::cuda::par.on(stream),
48 in, in + num, out, HalfToFloat());
51 half hostFloat2Half(
float a) {
53 h.x = cpu_float2half_rn(a).x;
59 #endif // FAISS_USE_FLOAT16