Login
You're viewing the code4lib.social public feed.
  • Nov 28, 2026, 9:06 PM

    @thesolidpixel oh, also, UDOT "emulation" for the NEONs and SSEs that don't have it: small value ranges thankfully makes this easy

    inputs are [0,64] and interp weights [0,16], so their products are in [0,1024], no problem

    NEON can do:
    lo8 = vdupq_n_u16(0xff);

    t0 = vmulq_u16(in & lo8, weights & lo8);
    t1 = vmlaq_u16(t0, vshrq_n_u16(in, 8), vshrq_n_u16(weights, 8));
    t2 = vpaddlq_u16(t1);

    SSE2:
    same idea, mask evens / shift odds, two PMADDWD, PADDD

    💬 1🔄 0⭐ 0

Replies

  • Nov 28, 2026, 9:29 PM

    @rygorous speed-running an approach review - seems like most uses of the bilinear infills can be replaced. I think compute_ideal_weights_for_decimation() is the only one that can't.

    💬 1🔄 0⭐ 0
  • Nov 28, 2026, 9:50 PM

    @thesolidpixel the alternative approach that I was considering previously would still work, but it's only good for 2D blocks, so you still need the general case for 3D:

    for that one, the idea was that the addresses within each row of the weight grid are increasing.

    Do 4 loads, one at [top_left], one at [top_left + 1], one at [top_left + W] and one at [top_left + W + 1], apply the same (regular) shuffle to all of them, then do the linear combine.

    💬 1🔄 0⭐ 0
  • Nov 28, 2026, 9:53 PM

    @thesolidpixel this "almost works", except when you have a break between rows that use the same texels in the middle of the vector, and it suddenly wants texels with lower inds than the earliest one you loaded.

    e.g. suppose 5x5 weight grid for a 10x10 block, vector size 8.

    The first 8 output weights are no problem, within the next 8 you use the the texels at (3,0), (4,0) but then go back to (0,0) - this one you can still compensate for with a regular load by adjusting load addr + shuffles.

    💬 1🔄 0⭐ 0
  • Nov 28, 2026, 9:56 PM

    @thesolidpixel but for vec4 it wouldn't work, because the last 2 texels need (3,0) and (4,0) and then the next 2 need (0,0) and (1,0) and there's no one contiguous load that makes that work.

    That is fixable by precomputing (during texel index gen) what runs to use. In this case you might decide with vec4 to have one partial vec4 (with only 2 useful elements) at the row transition and then start the next vec4 2 elements from there, not a full 4.

    Some "over-shade", but also gather-free.

    💬 1🔄 0⭐ 0
  • Nov 28, 2026, 9:59 PM

    @thesolidpixel this is all doable, and a more local change that still works with float weights and doesn't require any interface changes. It'd mostly be some added fields in the decimation info to facilitate this - you'd want to set up the permutation vectors to use for the target ISA up front, since e.g. for SSSE3/NEON you need to use byte-level permutations for this, which is not horrible but still a bit of a production to get from float element-level permutes.

    💬 2🔄 0⭐ 0
  • Nov 28, 2026, 10:03 PM

    @thesolidpixel this one should be pretty much drop-in, and it has that to recommend it, but on the flipside it has the partial vectors in the middle (at least sometimes) and doesn't help with 3D blocks at all.

    💬 0🔄 0⭐ 0
  • Nov 28, 2026, 10:03 PM

    @rygorous If you abstract the byte integer work behind a vtable-like abstraction, I don't think it's that messy in terms of inteface changes. No worse than the existing vtable stuff, and not really any worse than hauling float* arrays around for unpacked weights.

    💬 1🔄 0⭐ 0
  • Nov 28, 2026, 10:05 PM

    @rygorous I'm always a bit wary of mangled data layouts, they always end up being a bit of a pain to maintain if you don't use them a lot, so my gut feel says the integer approach is probably nicer.

    💬 0🔄 0⭐ 0
  • Nov 28, 2026, 10:08 PM

    @thesolidpixel yeah I agree, that's why I pitched it; more uniform approach that can handle all block types just feels much better.

    Might be able to reduce compute_ideal_weights for decimation to the uint8 case kinda sneakily though, the same way real sampler HW does it. :)

    💬 1🔄 0⭐ 0
  • Nov 28, 2026, 10:11 PM

    @thesolidpixel assume for a second bilinear returns just the int32 results of the weighted sum, and doesn't do the +8 or the final >>4 either; we push that into the consumer.

    That now means we can filter uint16 values by filtering uint8 twice, once for the low and once for the high bytes.

    Add low_sum + (high_sum << 8) and do the rounding and final shift, ta-da, uint16 sum.

    💬 1🔄 0⭐ 0
  • Nov 28, 2026, 10:18 PM

    @thesolidpixel in this case we'd quantize the ideal weights to something like s3.12 int16 fixed point (seems like more than enough), add a bias of 0x8000 to convert to uint16, and undo that bias after the combine of the low/high byte filtering.

    Dunno. It's also a bit strange. But that'd get rid of the float bilinears entirely

    💬 1🔄 0⭐ 0
  • Nov 28, 2026, 10:59 PM

    @rygorous Playing with the AVX512 VNNI dot implementation, as I've never had an excuse before =)

    Is there some _evil_ store forwarding cost on Xeon? Quantizer tables are written as 2x 128-bit values, and then loaded by AVX512 as a single wide load, and it kills performance.

    If I force it to load as 128-bit values and manually pack (who doesn't like a volatile pointer hack) it seems much happier, so I'm guessing the size mismatch causes the store-to-load forwarding path to crap out.

    💬 1🔄 0⭐ 0
  • Nov 28, 2026, 11:07 PM

    @thesolidpixel Vector loads that span multiple stores stall until all the constituent stores are retired. No forwarding whatsoever. Other direction (partial loads that are covered by a single wide vector store) is usually fine.

    Pretty much the same on AMD HW as well.

    💬 0🔄 0⭐ 0