12 #include "Float16.cuh"
13 #include "nvidia/fp16_emu.cuh"
14 #include <thrust/execution_policy.h>
15 #include <thrust/transform.h>
17 #ifdef FAISS_USE_FLOAT16
19 namespace faiss {
namespace gpu {
21 bool getDeviceSupportsFloat16Math(
int device) {
22 const auto& prop = getDeviceProperties(device);
24 return (prop.major >= 6 ||
25 (prop.major == 5 && prop.minor >= 3));
29 __device__ half operator()(
float v)
const {
return __float2half(v); }
33 __device__
float operator()(half v)
const {
return __half2float(v); }
36 void runConvertToFloat16(half* out,
39 cudaStream_t stream) {
40 thrust::transform(thrust::cuda::par.on(stream),
41 in, in + num, out, FloatToHalf());
44 void runConvertToFloat32(
float* out,
47 cudaStream_t stream) {
48 thrust::transform(thrust::cuda::par.on(stream),
49 in, in + num, out, HalfToFloat());
52 half hostFloat2Half(
float a) {
54 h.x = cpu_float2half_rn(a).x;
60 #endif // FAISS_USE_FLOAT16