summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/unary/f16_conversion.cache.ts
blob: bb0eb091ddcbb9b51ba6593f979e3d9ce7732e67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { abstractInt, bool, f16, i32, u32 } from '../../../../util/conversion.js';
import { FP, FPInterval } from '../../../../util/floating_point.js';
import { fullI32Range, fullI64Range, fullU32Range } from '../../../../util/math.js';
import { makeCaseCache } from '../case_cache.js';

const f16FiniteRangeInterval = new FPInterval(
  'f16',
  FP.f16.constants().negative.min,
  FP.f16.constants().positive.max
);

// Cases: f32_matCxR_[non_]const
// Note that f32 values may be not exactly representable in f16 and/or out of range.
const f32_mat_cases = ([2, 3, 4] as const)
  .flatMap(cols =>
    ([2, 3, 4] as const).flatMap(rows =>
      ([true, false] as const).map(nonConst => ({
        [`f32_mat${cols}x${rows}_${nonConst ? 'non_const' : 'const'}`]: () => {
          return FP.f32.generateMatrixToMatrixCases(
            FP.f32.sparseMatrixRange(cols, rows),
            nonConst ? 'unfiltered' : 'finite',
            FP.f16.correctlyRoundedMatrix
          );
        },
      }))
    )
  )
  .reduce((a, b) => ({ ...a, ...b }), {});

// Cases: f16_matCxR_[non_]const
const f16_mat_cases = ([2, 3, 4] as const)
  .flatMap(cols =>
    ([2, 3, 4] as const).flatMap(rows =>
      ([true, false] as const).map(nonConst => ({
        [`f16_mat${cols}x${rows}_${nonConst ? 'non_const' : 'const'}`]: () => {
          // Input matrix is of f16 types, use f16.generateMatrixToMatrixCases.
          return FP.f16.generateMatrixToMatrixCases(
            FP.f16.sparseMatrixRange(cols, rows),
            nonConst ? 'unfiltered' : 'finite',
            FP.f16.correctlyRoundedMatrix
          );
        },
      }))
    )
  )
  .reduce((a, b) => ({ ...a, ...b }), {});

// Cases: abstract_float_matCxR
// Note that abstract float values may be not exactly representable in f16
// and/or out of range.
const abstract_float_mat_cases = ([2, 3, 4] as const)
  .flatMap(cols =>
    ([2, 3, 4] as const).map(rows => ({
      [`abstract_float_mat${cols}x${rows}`]: () => {
        return FP.abstract.generateMatrixToMatrixCases(
          FP.abstract.sparseMatrixRange(cols, rows),
          'finite',
          FP.f16.correctlyRoundedMatrix
        );
      },
    }))
  )
  .reduce((a, b) => ({ ...a, ...b }), {});

export const d = makeCaseCache('unary/f16_conversion', {
  bool: () => {
    return [
      { input: bool(true), expected: f16(1.0) },
      { input: bool(false), expected: f16(0.0) },
    ];
  },
  u32_non_const: () => {
    return [...fullU32Range(), 65504].map(u => {
      return { input: u32(u), expected: FP.f16.correctlyRoundedInterval(u) };
    });
  },
  u32_const: () => {
    return [...fullU32Range(), 65504]
      .filter(v => f16FiniteRangeInterval.contains(v))
      .map(u => {
        return { input: u32(u), expected: FP.f16.correctlyRoundedInterval(u) };
      });
  },
  i32_non_const: () => {
    return [...fullI32Range(), 65504, -65504].map(i => {
      return { input: i32(i), expected: FP.f16.correctlyRoundedInterval(i) };
    });
  },
  i32_const: () => {
    return [...fullI32Range(), 65504, -65504]
      .filter(v => f16FiniteRangeInterval.contains(v))
      .map(i => {
        return { input: i32(i), expected: FP.f16.correctlyRoundedInterval(i) };
      });
  },
  abstract_int: () => {
    return [...fullI64Range(), 65504n, -65504n]
      .filter(v => f16FiniteRangeInterval.contains(Number(v)))
      .map(i => {
        return { input: abstractInt(i), expected: FP.f16.correctlyRoundedInterval(Number(i)) };
      });
  },
  // Note that f32 values may be not exactly representable in f16 and/or out of range.
  f32_non_const: () => {
    return FP.f32.generateScalarToIntervalCases(
      [...FP.f32.scalarRange(), 65535.996, -65535.996],
      'unfiltered',
      FP.f16.correctlyRoundedInterval
    );
  },
  f32_const: () => {
    return FP.f32.generateScalarToIntervalCases(
      [...FP.f32.scalarRange(), 65535.996, -65535.996],
      'finite',
      FP.f16.correctlyRoundedInterval
    );
  },
  // Note that abstract float values may be not exactly representable in f16.
  abstract_float: () => {
    return FP.abstract.generateScalarToIntervalCases(
      [...FP.abstract.scalarRange(), 65535.996, -65535.996],
      'finite',
      FP.f16.correctlyRoundedInterval
    );
  },
  // All f16 values are exactly representable in f16.
  f16: () => {
    return FP.f16.scalarRange().map(f => {
      return { input: f16(f), expected: FP.f16.correctlyRoundedInterval(f) };
    });
  },
  ...f32_mat_cases,
  ...f16_mat_cases,
  ...abstract_float_mat_cases,
});