Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion onnxruntime/contrib_ops/webgpu/bert/rotary_embedding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Status RotaryEmbeddingProgram::GenerateShaderCode(ShaderHelper& shader) const {
const auto& sin_cache = shader.AddInput("sin_cache", ShaderUsage::UseUniform);
const auto& output = shader.AddOutput("output", ShaderUsage::UseUniform);
// TODO: remove output_indices.
const auto& output_indices = shader.AddIndices("output_indices", false);
const auto& output_indices = shader.AddIndices("output_indices", ShaderUsage::None);
const auto interleaved_str = interleaved_ ? "true" : "false";
shader.MainFunctionBody() << " let half_rotary_emb_dim = uniforms.cos_cache_shape[1];\n"
" let bsnh = global_idx / uniforms.global_stride % uniforms.global_shape;\n"
Expand Down
11 changes: 9 additions & 2 deletions onnxruntime/core/providers/webgpu/shader_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,19 @@ const ShaderVariableHelper& ShaderHelper::AddOutput(const std::string& name, Sha
return AddVariableImpl(false, name, usage, dims);
}

const ShaderIndicesHelper& ShaderHelper::AddIndices(const std::string& name, bool use_uniform) {
const ShaderIndicesHelper& ShaderHelper::AddIndices(const std::string& name, ShaderUsage usage) {
const size_t indices_index = indices_vars_.size();
ORT_ENFORCE(indices_index < program_.Indices().size(),
"Too many indices in the program (", program_.Indices().size(), ")");

// usage of indices should not use flag other than UseUniform and UseIndicesTypeAlias
ORT_ENFORCE(!(usage & ~(ShaderUsage::UseUniform | ShaderUsage::UseIndicesTypeAlias)),
"Invalid usage for indices variable ", name);

return *indices_vars_.emplace_back(
std::make_unique<ShaderIndicesHelper>(name,
ProgramVariableDataType::InvalidType,
use_uniform ? ShaderUsage::UseUniform : ShaderUsage::None,
usage,
program_.Indices()[indices_index]));
}

Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/providers/webgpu/shader_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ShaderHelper final {
ShaderUsage usage = ShaderUsage::UseIndicesTypeAlias | ShaderUsage::UseValueTypeAlias | ShaderUsage::UseUniform);

// Add an indices variable to the shader.
const ShaderIndicesHelper& AddIndices(const std::string& name, bool use_uniform = true);
const ShaderIndicesHelper& AddIndices(const std::string& name, ShaderUsage usage = ShaderUsage::UseUniform);

// Get the string stream for additional implementation code to the shader.
inline OStringStream& AdditionalImplementation() {
Expand Down