Skip to content

[WebGPU EP] Support int64 for Min and Max - #31709

Open
Wanming Lin (Honry) wants to merge 2 commits into
microsoft:mainfrom
Honry:webgpu-int64-minmax
Open

[WebGPU EP] Support int64 for Min and Max#31709
Wanming Lin (Honry) wants to merge 2 commits into
microsoft:mainfrom
Honry:webgpu-int64-minmax

Conversation

@Honry

@Honry Wanming Lin (Honry) commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Description

Registers the WebGPU Min and Max kernels with conditional int64 support, mirroring the existing Add/Sub/Equal int64 mechanism. The kernels were previously registered with WebGpuSupportedNumberTypes() (float/fp16/ int32/uint32 only), causing int64 tensors to fall back to CPU.

Motivation and Context

Min/Max are arithmetic/comparison ops, so they reuse the existing low-32-bit i32 shader path (like Add/Sub). Values outside the int32 range produce incorrect results, which is acceptable for token-position workloads and consistent with the other arithmetic int64 kernels.

int64 support is gated behind the enableInt64 provider option, so the generic Min_12_Int64/Max_12_Int64 tests do not exercise it. Added WebGPU int64 tests (int64 enabled, CPU-EP fallback disabled) mirroring the Add int64 path coverage, element-wise, size divisible by 4, scalar operand, broadcast, plus the variadic (>2 input) fold unique to Min/Max, with INT32_MIN/INT32_MAX exercising the supported range edges.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@Honry
Wanming Lin (Honry) force-pushed the webgpu-int64-minmax branch 2 times, most recently from 9817d52 to 78abe6c Compare August 7, 2026 08:21
Registers the WebGPU Min and Max kernels with conditional int64 support,
mirroring the existing Add/Sub/Equal int64 mechanism. The kernels were
previously registered with WebGpuSupportedNumberTypes() (float/fp16/
int32/uint32 only), causing int64 tensors to fall back to CPU.

Min/Max are arithmetic/comparison ops, so they reuse the existing
low-32-bit i32 shader path (like Add/Sub). Values outside the int32
range produce incorrect results, which is acceptable for token-position
workloads and consistent with the other arithmetic int64 kernels.

int64 support is gated behind the enableInt64 provider option, so the
generic Min_12_Int64/Max_12_Int64 tests do not exercise it. Added
WebGPU int64 tests (int64 enabled, CPU-EP fallback disabled) mirroring
the Add int64 path coverage, element-wise, size divisible by 4,
scalar operand, broadcast, plus the variadic (>2 input) fold unique
to Min/Max, with INT32_MIN/INT32_MAX exercising the supported range
edges.
@Honry

Copy link
Copy Markdown
Contributor Author

@qjia7

Copy link
Copy Markdown
Contributor

Since int64 support is needed for an increasing number of binary ops, could you consider enabling int64 support across all binary ops behind the enableInt64 flag? It would also be great to reuse as much common code as possible so that the overall int64 support for binary ops can be implemented and maintained consistently.

@edgchen1 Edward Chen (edgchen1) added the ep:WebGPU ort-web webgpu provider label Aug 7, 2026
return Status::OK();
}

// A single opset version range for an op registration. end <= 0 means "since start" (open-ended).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe std::optional<int> end would be clearer than having special handling for values <= 0?

Comment on lines +489 to +490
int start;
int end;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the names begin/end feel more consistent. e.g., std::begin()/std::end()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ep:WebGPU ort-web webgpu provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants