From 2393dbf118f3bab7045cb1923e130279c049eb8c Mon Sep 17 00:00:00 2001 From: Yulong Wang <7679871+fs-eire@users.noreply.github.com> Date: Wed, 25 Sep 2024 11:43:16 -0700 Subject: [PATCH 1/2] fix: move inline impl to .h --- onnxruntime/core/providers/webgpu/shader_variable.cc | 6 ------ onnxruntime/core/providers/webgpu/shader_variable.h | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/onnxruntime/core/providers/webgpu/shader_variable.cc b/onnxruntime/core/providers/webgpu/shader_variable.cc index 7dcf2f352905d..f2a5b049b4777 100644 --- a/onnxruntime/core/providers/webgpu/shader_variable.cc +++ b/onnxruntime/core/providers/webgpu/shader_variable.cc @@ -88,12 +88,6 @@ ShaderIndicesHelper::ShaderIndicesHelper(std::string_view name, ProgramVariableD element_type_alias_{name_ + "_element_t"}, indices_type_alias_{name_ + "_indices_t"} {} -inline int ShaderIndicesHelper::Rank() { - // getting the rank means the information is exposed to the shader. So we consider it as a usage of shape and stride. - usage_ |= ShaderUsage::UseShapeAndStride; - return rank_; -} - ShaderVariableHelper::ShaderVariableHelper(std::string_view name, ProgramVariableDataType type, ShaderUsage usage, const TensorShape& dims) : ShaderIndicesHelper{name, type, usage, dims} { ORT_ENFORCE(type_ != ProgramVariableDataType::InvalidType, "Invalid type for variable ", name_); diff --git a/onnxruntime/core/providers/webgpu/shader_variable.h b/onnxruntime/core/providers/webgpu/shader_variable.h index 4b2d304782324..dc1c1742fe0e3 100644 --- a/onnxruntime/core/providers/webgpu/shader_variable.h +++ b/onnxruntime/core/providers/webgpu/shader_variable.h @@ -213,6 +213,12 @@ std::string pass_as_string(T&& v) { } } // namespace detail +inline int ShaderIndicesHelper::Rank() { + // getting the rank means the information is exposed to the shader. So we consider it as a usage of shape and stride. + usage_ |= ShaderUsage::UseShapeAndStride; + return rank_; +} + inline std::string ShaderIndicesHelper::OffsetToIndices(std::string_view offset_expr) const { usage_ |= ShaderUsage::UseOffsetToIndices | ShaderUsage::UseShapeAndStride; return rank_ < 2 ? std::string{offset_expr} From 9bdbd85ff3ae50aa445701b245336493b8984a7d Mon Sep 17 00:00:00 2001 From: Yulong Wang <7679871+fs-eire@users.noreply.github.com> Date: Wed, 25 Sep 2024 11:56:05 -0700 Subject: [PATCH 2/2] add const modifier --- onnxruntime/core/providers/webgpu/shader_variable.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onnxruntime/core/providers/webgpu/shader_variable.h b/onnxruntime/core/providers/webgpu/shader_variable.h index dc1c1742fe0e3..2ddc9a6e8160f 100644 --- a/onnxruntime/core/providers/webgpu/shader_variable.h +++ b/onnxruntime/core/providers/webgpu/shader_variable.h @@ -71,7 +71,7 @@ class ShaderIndicesHelper { inline int NumComponents() const { return num_components_; } // get the rank of the indices. - inline int Rank(); + inline int Rank() const; // create a WGSL expression ({varname}_indices_t) for getting indices from offset. // \param offset: a WGSL expression (u32) representing the offset. @@ -213,7 +213,7 @@ std::string pass_as_string(T&& v) { } } // namespace detail -inline int ShaderIndicesHelper::Rank() { +inline int ShaderIndicesHelper::Rank() const { // getting the rank means the information is exposed to the shader. So we consider it as a usage of shape and stride. usage_ |= ShaderUsage::UseShapeAndStride; return rank_;