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
17 changes: 15 additions & 2 deletions onnxruntime/core/framework/allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,22 @@ ORT_API_STATUS_IMPL(OrtApis::CreateMemoryInfo, _In_ const char* name1, enum OrtA
OrtDevice(OrtDevice::GPU, OrtDevice::MemType::DEFAULT, OrtDevice::VendorIds::AMD, device_id),
mem_type1);
} else if (strcmp(name1, onnxruntime::WEBGPU_BUFFER) == 0 ||
strcmp(name1, onnxruntime::WEBNN_TENSOR) == 0) {
strcmp(name1, onnxruntime::WEBNN_TENSOR) == 0 ||
// Accept pre-1.25 names "WebGPU_Buffer"/"WebNN_Tensor" for backward compatibility
// with released onnxruntime-genai that still uses the old names.
// Normalize to the current (short) constant so downstream name comparisons work.
// See: https://github.com/microsoft/onnxruntime/pull/27207
strcmp(name1, "WebGPU_Buffer") == 0 ||
strcmp(name1, "WebNN_Tensor") == 0) {
// Map old long names to current short constants to keep downstream name comparisons consistent.
const char* normalized_name = name1;
if (strcmp(name1, "WebGPU_Buffer") == 0) {
normalized_name = onnxruntime::WEBGPU_BUFFER;
} else if (strcmp(name1, "WebNN_Tensor") == 0) {
normalized_name = onnxruntime::WEBNN_TENSOR;
}
*out = new OrtMemoryInfo(
name1, type,
normalized_name, type,
OrtDevice(OrtDevice::GPU, OrtDevice::MemType::DEFAULT, OrtDevice::VendorIds::NONE, device_id),
mem_type1);

Expand Down
21 changes: 21 additions & 0 deletions onnxruntime/test/shared_lib/test_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ TEST(CApiTest, allocation_info) {
ASSERT_EQ(OrtMemTypeDefault, cpu_mem_info_1.GetMemoryType());
}

// Verify that legacy (pre-1.25) memory info names "WebGPU_Buffer" and "WebNN_Tensor" are accepted
// and normalized to the current short names "WebGPU_Buf" and "WebNN_Ten".
// This ensures backward compatibility with released onnxruntime-genai that uses the old names.
TEST(CApiTest, LegacyWebGpuWebNNMemoryInfoNames) {
// Old (pre-1.25) names must be accepted
Ort::MemoryInfo legacy_webgpu("WebGPU_Buffer", OrtDeviceAllocator, 0, OrtMemTypeDefault);
Ort::MemoryInfo legacy_webnn("WebNN_Tensor", OrtDeviceAllocator, 0, OrtMemTypeDefault);

// Current (short) names
Ort::MemoryInfo current_webgpu("WebGPU_Buf", OrtDeviceAllocator, 0, OrtMemTypeDefault);
Ort::MemoryInfo current_webnn("WebNN_Ten", OrtDeviceAllocator, 0, OrtMemTypeDefault);

// Legacy names should be normalized to the current names
ASSERT_EQ(std::string("WebGPU_Buf"), legacy_webgpu.GetAllocatorName());
ASSERT_EQ(std::string("WebNN_Ten"), legacy_webnn.GetAllocatorName());

// Memory infos created with legacy and current names should be equal
ASSERT_EQ(legacy_webgpu, current_webgpu);
ASSERT_EQ(legacy_webnn, current_webnn);
}

TEST(CApiTest, DefaultAllocator) {
Ort::AllocatorWithDefaultOptions default_allocator;
auto cpu_info = default_allocator.GetInfo();
Expand Down
Loading