Show HN: Npunlock – Run custom C kernels for Intel NPUs

(github.com)

64 points | by hsfzxjy 2 days ago ago

12 comments

  • hsfzxjy a day ago ago

    Author here. Feel free to ask any questions :)

    • __atx__ a day ago ago

      Nice work! I have been messing with doing some radio DSP on the NPU in my laptop and found the Intel graph compiler to be rather unpredictable. Weird random mis-lowering to fp16 ops instead of int8, unpredictable throughput depending on tensor sizes, reshapes being sometimes extremely expensive and sometimes basically free etc.

      Obviously I am mostly just driving the DPU, as the SHAVE cores are just not beefy enough, but maybe this will be useful at some point, at least to gain more insight into the architecture...

      • hsfzxjy a day ago ago

        Thanks! I can observe similar behaviors on my laptop. FP32 operations are sometimes siliently lowered to a sequence of (FP32->FP16)->(FP16 OP)->(FP16->FP32), causing precision loss. It further frustrated me during npunlock development. Changing custom SHAVE OP from FP16 -> FP32 also changes the blob structure, and I have to explore different binary patching strategy.

        As for the interesting cost variance for reshape you've mentioned, I guess surrounding context is the cause. The NPU compiler might adjust the data layout to match successive OPs' requirements. But, yes, that's annoying~

        Studying DPU is not my current priority, but I may dig it up in the future to understand its invocation descriptor, and hopefully to discover more interesting stuff. I hope this project ends up being useful to you!

  • Bayard_ne a day ago ago

    Finally, bare-metal NPU programming! Immediately thought of those custom, weird inference tasks Intel won't ever officially support.

    • hsfzxjy a day ago ago

      Let's play Doom on NPU!

  • alex7o a day ago ago

    Pls do hexagon next

  • Gigachad a day ago ago

    What is this useful for?

    • hsfzxjy a day ago ago

      The main use is enabling developers to write their own NPU kernels according to their respective need, instead of picking workaround from what Intel provides in OpenVINO. I think the project would benefit three scenarios:

      1. Implement uncommon NN operators.

      2. Implement a high-precision (FP32, etc.) version of existing OpenVINO operators for numerically sensitive usage.

      3. Implement a mega kernel that fuse several small kernels together to reduce SHAVE invocations, and potentially improve performance.

      But most importantly, it gives you more control over the hardware you own. That control IMO should have been yours from day one you bought the machine.

  • ur-whale a day ago ago

    > Requirements Windows x64

    plonk.

    • hsfzxjy a day ago ago

      I have no access to other environment setting, so, sadly, that's the best I can do for now.

      But based on my understanding, playing this on Linux or newer NPU generations might be possible. I have recorded my hypotheses in [0]. Verifying the hypotheses would require additional utility tools, which I am stilling crafting.

      [0]: https://github.com/hsfzxjy/npunlock/blob/master/wiki/PORTING...

      • hypercube33 a day ago ago

        Windows comes with the ability to do wsl so you somewhat have Linux as well even though it's limited in some ways. May be worth a shot cross compiling it.

        • hsfzxjy a day ago ago

          Yes. But WSL doesn't come with NPU passthrough, so I still can't test the hardware-specific behavior. Cross-compiling the project with WSL is plausible. I will try it and leave for the community to do verification.