// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module webnn.mojom;
import "mojo/public/mojom/base/big_buffer.mojom";
import "services/webnn/public/mojom/webnn_graph.mojom";
import "services/webnn/public/mojom/webnn_error.mojom";
// A struct is used to represent MLBufferUsageFlags since Mojo does not have
// the concept of an enum set (see https://crbug.com/40130879#comment11).
struct BufferUsage {
bool web_gpu_interop;
// This buffer can be used with readBuffer().
bool read_from;
// This buffer can be used with writeBuffer().
bool write_to;
};
// Description of the WebNNBuffer to create.
struct BufferInfo {
OperandDescriptor descriptor;
BufferUsage usage;
};
// Represents the return value of `ReadBuffer()`. Let it be
// `buffer` if the buffer was successfully read back and `error` otherwise.
union ReadBufferResult {
mojo_base.mojom.BigBuffer buffer;
Error error;
};
// WebNNBuffer creates memory in the GPU process and is used by the renderer
// process to execute or transfer data for the computational graph.
// Buffer creation is performed by calling hardware accelerated OS machine
// learning APIs.
interface WebNNBuffer {
// Called by the renderer process to carryout reading data from a
// `WebNNBuffer`. The result callback contains a copy of the data being
// read.
ReadBuffer() => (ReadBufferResult result);
// Called by the renderer process to carryout writing to a `WebNNBuffer`.
// The src_buffer is a BigBuffer representing the data to write from.
WriteBuffer(mojo_base.mojom.BigBuffer src_buffer);
};