// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "core/providers/js/js_kernel.h" namespace onnxruntime { namespace contrib { namespace js { using onnxruntime::js::JsKernel; class MatMulNBits final : public JsKernel { public: MatMulNBits(const OpKernelInfo& info) : JsKernel(info), K_{narrow(info.GetAttr("K"))}, N_{narrow(info.GetAttr("N"))}, accuracy_level_{info.GetAttrOrDefault("accuracy_level", 0)}, nbits_{narrow(info.GetAttr("bits"))}, block_size_{narrow(info.GetAttr("block_size"))} { ORT_ENFORCE(nbits_ == 4 || nbits_ == 2, "Only 2b and 4b quantization is supported for MatMulNBits op, additional bits support is planned."); ORT_ENFORCE(block_size_ >= 16 && !(block_size_ & (block_size_ - 1)), "Block size must be a power of 2 and greater than or equal to 16."); JSEP_INIT_KERNEL_ATTRIBUTE(MatMulNBits, ({ "k" : $1, "n" : $2, "accuracyLevel" : $3, "bits" : $4, "blockSize" : $5 }), static_cast(K_), static_cast(N_), static_cast(accuracy_level_), static_cast(nbits_), static_cast(block_size_)); } private: const size_t K_; const size_t N_; const int64_t accuracy_level_; const size_t nbits_; const size_t block_size_; }; } // namespace js } // namespace contrib } // namespace onnxruntime