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
7 changes: 2 additions & 5 deletions onnxruntime/core/providers/webgpu/program_cache_key.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ void AppendTensorInfo(OStringStream& ss,

std::string CalculateProgramCacheKey(const ProgramBase& program,
std::span<uint32_t> inputs_segments,
std::span<uint32_t> outputs_segments,
bool is_1d_dispatch) {
std::span<uint32_t> outputs_segments) {
SS(ss, kStringInitialSizeCacheKey);

// final key format:
// <KEY>=<PROGRAM_NAME>[<CUSTOM_CACHE_HINT>]:<WORKGROUP_SIZE>:<SUBGROUP_SIZE>:<DISPATCH_FLAG>:<UNIFORMS>:<INPUTS_INFO>
// <KEY>=<PROGRAM_NAME>[<CUSTOM_CACHE_HINT>]:<WORKGROUP_SIZE>:<SUBGROUP_SIZE>:<UNIFORMS>:<INPUTS_INFO>
//
// <CUSTOM_CACHE_HINT> = <HINT_0>|<HINT_1>|...
// <WORKGROUP_SIZE> = <X_IF_OVERRIDDEN>,<Y_IF_OVERRIDDEN>,<Z_IF_OVERRIDDEN>
// <SUBGROUP_SIZE> = <SUBGROUP_SIZE_IF_OVERRIDDEN>
// <DISPATCH_FLAG> = <!IS_1D_DISPATCH>
// <UNIFORMS> = <UNIFORMS_INFO_0>|<UNIFORMS_INFO_1>|...
// <UNIFORMS_INFO_i> = <UNIFORM_LENGTH>
// <INPUTS_INFO> = <INPUTS_INFO_0>|<INPUTS_INFO_1>|...
Expand Down Expand Up @@ -97,7 +95,6 @@ std::string CalculateProgramCacheKey(const ProgramBase& program,
ss << ":" D("SubgroupSize=") << subgroup_size;
}

ss << ":" D("DispatchDim=") << (is_1d_dispatch ? "1" : "3");
ss << ":" D("UniformSizes=");
bool first = true;
for (const auto& uniform : program.UniformVariables()) {
Expand Down
3 changes: 1 addition & 2 deletions onnxruntime/core/providers/webgpu/program_cache_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ namespace webgpu {

std::string CalculateProgramCacheKey(const ProgramBase& program,
std::span<uint32_t> inputs_segments,
std::span<uint32_t> outputs_segments,
bool is_1d_dispatch);
std::span<uint32_t> outputs_segments);

} // namespace webgpu
} // namespace onnxruntime
5 changes: 0 additions & 5 deletions onnxruntime/core/providers/webgpu/shader_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ Status ShaderHelper::Init() {
}

// init body string stream
bool is_1d_dispatch = dispatch_group_size_y_ == 1 && dispatch_group_size_z_ == 1;
bool use_indirect_dispatch = program_.IndirectDispatchTensor() != nullptr;

// append header for main function so it is ready for user to append main function body
Expand Down Expand Up @@ -103,10 +102,6 @@ Status ShaderHelper::Init() {
" let num_workgroups_y = indirect_buffer[1];\n"
" let workgroup_idx = workgroup_id.z * num_workgroups_x * num_workgroups_y + workgroup_id.y * num_workgroups_x + workgroup_id.x;\n"
" let global_idx = workgroup_idx * (workgroup_size_x * workgroup_size_y * workgroup_size_z) + local_idx;\n";
} else if (is_1d_dispatch) {
body_ss_ << ") {\n";
body_ss_ << " let global_idx = global_id.x;\n"
" let workgroup_idx = workgroup_id.x;\n";
} else {
Comment thread
qjia7 marked this conversation as resolved.
body_ss_ << ",\n"
" @builtin(num_workgroups) num_workgroups : vec3<u32>) {\n";
Expand Down
4 changes: 1 addition & 3 deletions onnxruntime/core/providers/webgpu/webgpu_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,7 @@ Status WebGpuContext::Run(ComputeContextBase& context, const ProgramBase& progra
"Only one of SetIndirectDispatchTensor and SetDispatchGroupSize should be called for program", program.Name());
}

bool is_1d_dispatch = (y == 1 && z == 1);

auto key = CalculateProgramCacheKey(program, inputs_segments, outputs_segments, is_1d_dispatch);
auto key = CalculateProgramCacheKey(program, inputs_segments, outputs_segments);

LOGS(context.Logger(), INFO) << "Starting program \"" << key << "\" (" << x << ", " << y << ", " << z << ")";
// The program cache prevents duplicate builds across encoded windows.
Expand Down
Loading