WebAssembly / WebAssembly/component-model

Allow non-canonical type alignment?

Open
#258 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
1.4k
Forks
130
Avg merge
2d 1h
Merged PRs (30d)
15

Description

Over in wasi-nn, we have been wondering whether there might be a way to specify an alignment for a type larger than the one specified by the canonical ABI. This is similar to what @titzer brings up in https://github.com/WebAssembly/component-model/issues/194 but I thought it was different enough to merit its own issue.

wasi-nn currently specifies the tensor data as list<u8> (WIT). The initial rationale (long ago, back in the WITX days) was a performance consideration: ML frameworks can deal with tensor data as byte blobs and if we can just "pass the bytes through" we can avoid some extra copies. This means that when we, as a wasi-nn guest user, receive tensor data back we must convert it somehow from list<u8> to list<f64>, e.g. This conversion is an unsafe cast in some of the bindings — what if the list<u8> is not aligned to cast to list<f64>? There has been an outstanding issue (https://github.com/WebAssembly/wasi-nn/issues/27) to figure this out. One solution would be to always copy the data; another to conditionally copy the data only if unaligned; etc.

The solution I'm asking about here is adding some way to inform the runtime of the alignment we would like when allocating space for the tensor data. Is this possible? Is it different enough from what @titzer is asking? I suspect we would only want to allow allocations for alignments larger than what the canonical ABI specifies, but maybe not.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked component-model issue #194, wasi-nn's wit/wasi-nn.wit at line 44, and wasi-nn issue #27 to understand the canonical ABI alignment and tensor conversion concerns. Done means reaching and documenting a decided design for whether callers can request larger alignments and how that relates to the existing proposal.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.