Skip to content

Commit cd4a743

Browse files
committed
Update
[ghstack-poisoned]
2 parents fde3710 + c372a21 commit cd4a743

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

backends/webgpu/runtime/WebGPUBackend.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,18 @@ Error WebGPUBackend::execute(
104104
// Copy inputs from EValue tensors to GPU buffers
105105
std::vector<InputData> inputs;
106106
inputs.reserve(num_inputs);
107-
for (size_t i = 0; i < num_inputs; i++) {
108-
const auto& tensor = args[i]->toTensor();
109-
const bool host_is_int64 =
110-
tensor.scalar_type() == executorch::aten::ScalarType::Long;
111-
inputs.push_back({tensor.const_data_ptr(), tensor.nbytes(), host_is_int64});
112-
}
113107
// Fail loud as a runtime Error so a throw never crosses the backend boundary.
114108
try {
115-
// Dynamic shapes: shrink each input to its live sizes before upload
116-
// (mirrors Vulkan maybe_resize_input). No-op when unchanged, so a static
117-
// graph is byte-identical.
109+
// Build the input list and, for dynamic shapes, shrink each input to its
110+
// live sizes before upload (mirrors Vulkan maybe_resize_input). No-op when
111+
// unchanged, so a static graph is byte-identical.
118112
for (size_t i = 0; i < num_inputs; i++) {
119-
const auto sizes = args[i]->toTensor().sizes();
113+
const auto& tensor = args[i]->toTensor();
114+
const bool host_is_int64 =
115+
tensor.scalar_type() == executorch::aten::ScalarType::Long;
116+
inputs.push_back(
117+
{tensor.const_data_ptr(), tensor.nbytes(), host_is_int64});
118+
const auto sizes = tensor.sizes();
120119
std::vector<int64_t> new_dims(sizes.begin(), sizes.end());
121120
graph->resize_input(graph->input_ids()[i], new_dims);
122121
}

backends/webgpu/runtime/WebGPUGraph.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,14 @@ void WebGPUGraph::update_symints_from_inputs(
142142
// Reads the [0,..,index,..,0] element; symint sources are scalar-ish.
143143
const int64_t offset = static_cast<int64_t>(index) * stride;
144144
const void* host = inputs[pos].data;
145-
// Stored elem_size (live nbytes/numel mis-derives for a dynamic source).
146-
const size_t elem_size = tensors_[src.input_tensor_id].elem_size;
145+
// Interpret the HOST buffer by its scalar type, not the tensor's serialized
146+
// elem_size: copy_inputs narrows an int64 host input to an int32 buffer, so
147+
// elem_size (buffer-derived) would misread int64 host data as int32.
147148
int32_t val;
148-
if (elem_size == sizeof(int64_t)) {
149+
if (inputs[pos].host_is_int64) {
149150
val = static_cast<int32_t>(static_cast<const int64_t*>(host)[offset]);
150-
} else if (elem_size == sizeof(int32_t)) {
151-
val = static_cast<const int32_t*>(host)[offset];
152151
} else {
153-
throw std::runtime_error(
154-
"select_as_symint: unsupported input element size");
152+
val = static_cast<const int32_t*>(host)[offset];
155153
}
156154
set_symint(src.symint_id, val);
157155
}

backends/webgpu/runtime/ops/select_as_symint/SelectAsSymint.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ void register_sym_binary(
9191
if (graph.get_value_type(a) == WebGPUGraph::ValueType::SymInt) {
9292
graph.add_resize_hook(a, recompute);
9393
}
94-
if (graph.get_value_type(b) == WebGPUGraph::ValueType::SymInt) {
94+
// b != a: for a self-op (e.g. x + x) both operands share one id; register the
95+
// recompute hook once, not twice.
96+
if (b != a && graph.get_value_type(b) == WebGPUGraph::ValueType::SymInt) {
9597
graph.add_resize_hook(b, recompute);
9698
}
9799
}

0 commit comments

Comments
 (0)