forked from microsoft/onnxruntime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[webgpu-native] Add MatmulNBits (microsoft#22150)
### Description <!-- Describe your changes. --> ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> --------- Co-authored-by: Yulong Wang <[email protected]>
- Loading branch information
Showing
8 changed files
with
501 additions
and
102 deletions.
There are no files selected for viewing
294 changes: 294 additions & 0 deletions
294
onnxruntime/contrib_ops/webgpu/quantization/matmul_nbits.cc
Large diffs are not rendered by default.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
onnxruntime/contrib_ops/webgpu/quantization/matmul_nbits.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#include "core/providers/webgpu/program.h" | ||
#include "core/providers/webgpu/webgpu_kernel.h" | ||
|
||
namespace onnxruntime { | ||
namespace contrib { | ||
namespace webgpu { | ||
|
||
using namespace onnxruntime::webgpu; | ||
|
||
class MatMulNBitsProgram final : public Program<MatMulNBitsProgram> { | ||
public: | ||
MatMulNBitsProgram(uint32_t output_number, int components_b, bool has_zero_points) : Program{"MatMulNBits"}, | ||
output_number_{output_number}, | ||
components_b_{components_b}, | ||
has_zero_points_{has_zero_points} { | ||
} | ||
|
||
Status GenerateShaderCode(ShaderHelper& sh) const override; | ||
WEBGPU_PROGRAM_DEFINE_UNIFORM_VARIABLES({"block_size", ProgramUniformVariableDataType::Uint32}); | ||
|
||
private: | ||
uint32_t output_number_; | ||
int components_b_; | ||
bool has_zero_points_; | ||
}; | ||
|
||
class MatMulNBits final : public WebGpuKernel { | ||
public: | ||
MatMulNBits(const OpKernelInfo& info) : WebGpuKernel(info) { | ||
K_ = info.GetAttr<int64_t>("K"); | ||
N_ = info.GetAttr<int64_t>("N"); | ||
block_size_ = info.GetAttr<int64_t>("block_size"); | ||
int64_t bits = info.GetAttr<int64_t>("bits"); | ||
ORT_ENFORCE(bits == 4, | ||
"Only 4b quantization is supported for MatMulNBits op, additional bits support is planned."); | ||
} | ||
|
||
Status ComputeInternal(onnxruntime::webgpu::ComputeContext& context) const override; | ||
|
||
private: | ||
int64_t K_; | ||
int64_t N_; | ||
int64_t block_size_; | ||
}; | ||
|
||
} // namespace webgpu | ||
} // namespace contrib | ||
} // namespace onnxruntime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.