Half values held at 16 bits where the module computes half in 16 bits
Under the 16-bit float controls (QuantizeForm::Controlled), a module that computes half in 16 bits held every other half value widened in an f32: each 16-bit + - * sat between conversion pairs, and min, max, clamp, select, mix, dot, the demotion variables and the thread arrays read and wrote the f32. The device's native form of half arithmetic there is its 16-bit instruction (rule 1), so a new IR pass, spirv::half_hold, runs after emission and the dead-code pass: - an f32 scalar or vector is an exact half where it widens a 16-bit float, is a constant of halves, an undefined value, a load of a held variable, the member an extract takes from its construct, or a move or exact operation (select, composite moves, shuffle, negate, abs, min, max, clamp, sign, floor, ceil, trunc, round) of exact halves; each gets a 16-bit twin computed by the same instruction, and a narrowing of one is its twin; - a Function or Private variable of f32 scalars, vectors or arrays of them, reached only by loads and stores (through access chains or not) of exact halves, holds the 16-bit type; - an f32 sum, difference, product, product by a scalar, dot product or mix of exact halves whose every use narrows it is the 16-bit instruction; the first four answer the same half (f32 carries 2p + 2 bits, correctly rounded under the controls), a dot product and a mix are within the device's bounds and pipeline/compile.rs records DeviceArithmetic for them; - comparisons, NaN and infinity tests and conversions to integers of exact halves read the twins. Verification: none yet in this commit; the build, the hnq FConvert count, the half engine tests and the golden tables follow.
This commit is contained in:
1 parent
be1e8bb311
commit
081fea3239
4 files changed
+1034
-2
No files matched your search
@@ -7,8 +7,10 @@
|
||||
//! each block by routing every instruction's [`Strategy`] to its family's emit function. It then
|
||||
//! lets `fragment::wrap_entry` choose the entry function (the walked body itself, or a raster order
|
||||
//! group's interlocked wrapper that calls it), declares the entry point, finalizes, runs P9
|
||||
//! (`promote_single_store`), and removes what no instruction reads, taking the lowering's offers
|
||||
//! that make the module smaller (`spirv::dead::remove_dead_keeping`).
|
||||
//! (`promote_single_store`), removes what no instruction reads, taking the lowering's offers
|
||||
//! that make the module smaller (`spirv::dead::remove_dead_keeping`), and, under the 16-bit float
|
||||
//! controls, holds the `half` values of a module that computes `half` in 16 bits there
|
||||
//! (`spirv::half_hold`).
|
||||
//!
|
||||
//! The emitter owns its value environment: the SPIR-V value of each AIR value in the block being
|
||||
//! emitted, reset at the top of every block, and the values the entry hook (`stage_io::emit_entry`;
|
||||
@@ -1460,6 +1462,11 @@ pub fn emit_module(e: &Entry, plan: &Plan, m: &mut Meter) -> Result<Emitted, Err
|
||||
let r = remove_dead_keeping(&mut module, &offers, m);
|
||||
m.release(std::mem::size_of_val(offers.as_slice()));
|
||||
r?;
|
||||
// Under the 16-bit float controls, a module that computes `half` in 16 bits holds its `half`
|
||||
// values there (`spirv::half_hold`).
|
||||
if plan.families.arith.quantize == crate::spirv::builder::QuantizeForm::Controlled {
|
||||
crate::spirv::half_hold::hold(&mut module, m)?;
|
||||
}
|
||||
Ok(Emitted { module, merged })
|
||||
}
|
||||
|
||||
|
||||
@@ -2929,6 +2929,15 @@ fn compile_kept<K>(
|
||||
precision.sort_unstable();
|
||||
}
|
||||
}
|
||||
// A `half` dot product or `mix` the module computes at 16 bits (`spirv::half_hold`): the
|
||||
// device's 16-bit instruction within its precision bounds, where the `float` one rounded may
|
||||
// differ.
|
||||
if crate::spirv::half_hold::rounds_in_16_bits(&module)
|
||||
&& !precision.contains(&PrecisionNote::DeviceArithmetic)
|
||||
{
|
||||
precision.push(PrecisionNote::DeviceArithmetic);
|
||||
precision.sort_unstable();
|
||||
}
|
||||
if helper_guard.exposed {
|
||||
precision.push(PrecisionNote::HelperBranchDropsSimdgroupStores);
|
||||
precision.sort_unstable();
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -7,6 +7,7 @@
|
||||
pub mod builder;
|
||||
pub mod dead;
|
||||
pub mod error;
|
||||
pub mod half_hold;
|
||||
pub mod helper_branches;
|
||||
pub mod ids;
|
||||
// The CPU interpreter: test support for the crate's own tests.
|
||||
|
||||
Reference in new issue
Block a user