-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[webgpu EP] Binary operators (#22112)
based on: - #22058 --------- Co-authored-by: Qin Jiajia <[email protected]>
- Loading branch information
Showing
17 changed files
with
736 additions
and
262 deletions.
There are no files selected for viewing
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
311 changes: 311 additions & 0 deletions
311
onnxruntime/core/providers/webgpu/math/binary_elementwise_ops.cc
Large diffs are not rendered by default.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
onnxruntime/core/providers/webgpu/math/binary_elementwise_ops.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,56 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#include "core/providers/webgpu/webgpu_kernel.h" | ||
#include "core/providers/webgpu/shader_helper.h" | ||
#include "core/providers/webgpu/program.h" | ||
|
||
namespace onnxruntime { | ||
namespace webgpu { | ||
|
||
class BinaryElementwiseProgram final : public Program<BinaryElementwiseProgram> { | ||
public: | ||
BinaryElementwiseProgram(const std::string& kernel_name, | ||
const std::string& expression, | ||
const bool is_broadcast, | ||
const bool is_lhs_scalar, | ||
const bool is_rhs_scalar, | ||
const bool vectorize) : Program{kernel_name}, | ||
expression_{expression}, | ||
is_broadcast_{is_broadcast}, | ||
is_lhs_scalar_{is_lhs_scalar}, | ||
is_rhs_scalar_{is_rhs_scalar}, | ||
vectorize_{vectorize} {} | ||
|
||
Status GenerateShaderCode(ShaderHelper& sh) const override; | ||
|
||
WEBGPU_PROGRAM_DEFINE_UNIFORM_VARIABLES({"vec_size", ProgramUniformVariableDataType::Uint32}); | ||
|
||
private: | ||
std::string expression_; | ||
bool is_broadcast_; | ||
bool is_lhs_scalar_; | ||
bool is_rhs_scalar_; | ||
bool vectorize_; | ||
}; | ||
|
||
class BinaryElementwise : public WebGpuKernel { | ||
public: | ||
BinaryElementwise(const OpKernelInfo& info, | ||
const std::string& kernel_name, | ||
const std::string& expression) : WebGpuKernel{info}, | ||
kernel_name_{kernel_name}, | ||
expression_{expression} {} | ||
|
||
protected: | ||
Status ComputeInternal(ComputeContext& context) const final; | ||
|
||
private: | ||
std::string kernel_name_; | ||
std::string expression_; | ||
}; | ||
|
||
} // namespace webgpu | ||
} // 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
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.