Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wgsl: Convert quantizeToF16 to used hfround #3118

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/webgpu/util/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { assert } from '../../common/util/util.js';
import {
Float16Array,
getFloat16,
hfround,
setFloat16,
} from '../../external/petamoriken/float16/float16.js';

Expand Down Expand Up @@ -2021,13 +2022,9 @@ export function quantizeToF32(num: number): number {
return quantizeToF32Data[0];
}

/** Statically allocate working data, so it doesn't need per-call creation */
const quantizeToF16Data = new Float16Array(new ArrayBuffer(2));

/** @returns the closest 16-bit floating point value to the input */
export function quantizeToF16(num: number): number {
quantizeToF16Data[0] = num;
return quantizeToF16Data[0];
return hfround(num);
}

/** Statically allocate working data, so it doesn't need per-call creation */
Expand Down
Loading