"docs/features/reasoning_outputs.md" did not exist on "bf33700ecd6db472c4aeb489c5d42aa47a735198"
common.cuh 1.47 KB
Newer Older
1
2
#pragma once

3
#include "quantization/vectorization.cuh"
4
#include "quantization/utils.cuh"
5

6
7
#include <cmath>

8
#ifdef USE_ROCM
9
  #include "amd/quant_utils.cuh"
10
11
12
13
14
15
16
17
18
19
20
21
22
#endif

// Determines the preferred FP8 type for the current platform.
// Note that for CUDA this just returns true,
// but on ROCm it will check device props.
static bool is_fp8_ocp() {
#ifndef USE_ROCM
  return true;
#else
  auto dprops = at::cuda::getCurrentDeviceProperties();
  std::string device_arch = dprops->gcnArchName;
  size_t substring = device_arch.find("gfx94");
  return substring == std::string::npos;
23
#endif
24
25
}

26
27
28
29
30
31
32
33
34
35
36
37
namespace vllm {

__device__ __forceinline__ float atomicMaxFloat(float* addr, float value) {
  float old;
  old = (value >= 0)
            ? __int_as_float(atomicMax((int*)addr, __float_as_int(value)))
            : __uint_as_float(
                  atomicMin((unsigned int*)addr, __float_as_uint(value)));

  return old;
}

38
39
template <bool is_scale_inverted, typename fp8_type>
__device__ __forceinline__ fp8_type scaled_fp8_conversion(float const val,
40
41
42
43
44
45
46
47
                                                          float const scale) {
  float x = 0.0f;
  if constexpr (is_scale_inverted) {
    x = val * scale;
  } else {
    x = val / scale;
  }

48
  float r =
49
      fmaxf(-quant_type_max_v<fp8_type>, fminf(x, quant_type_max_v<fp8_type>));
50
#ifndef USE_ROCM
51
  return static_cast<fp8_type>(r);
52
53
#else
  // Use hardware cvt instruction for fp8 on rocm
54
  return fp8::cvt_c10<fp8_type>(r);
55
56
57
#endif
}

58
}  // namespace vllm