junrushao commented on code in PR #191:
URL: https://github.com/apache/tvm-ffi/pull/191#discussion_r2464093274


##########
docs/get_started/stable_c_abi.rst:
##########
@@ -0,0 +1,189 @@
+.. Licensed to the Apache Software Foundation (ASF) under one
+.. or more contributor license agreements.  See the NOTICE file
+.. distributed with this work for additional information
+.. regarding copyright ownership.  The ASF licenses this file
+.. to you under the Apache License, Version 2.0 (the
+.. "License"); you may not use this file except in compliance
+.. with the License.  You may obtain a copy of the License at
+..
+..   http://www.apache.org/licenses/LICENSE-2.0
+..
+.. Unless required by applicable law or agreed to in writing,
+.. software distributed under the License is distributed on an
+.. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+.. KIND, either express or implied.  See the License for the
+.. specific language governing permissions and limitations
+.. under the License.
+
+Stable C ABI
+============
+
+TVM-FFI centers on a single key idea:
+
+
+.. admonition:: Key Idea
+  :class: important
+
+  Every function call can be represented by a single ABI stable C function:
+
+  .. code-block:: c
+
+      int universal_c_abi(  // returns 0 if succeed, error code if failure
+        void*  handle,      // library handle
+        Any*   args,        // inputs: args[0 ... N - 1]
+        int    N,           // number of inputs
+        Any*   result,      // output: *result
+      );
+
+  where ``Any`` is a tagged union of all supported types, e.g. integers, 
floats, Tensors, strings, etc., and can be further extended to arbitrary 
user-defined types.
+
+Built on top of this stable C ABI, TVM-FFI provides an extensible, performant, 
and ecosystem-friendly open solution for all.
+
+The rest of this guide covers:
+
+- The stable C layout and calling convention of ``universal_c_abi``;
+- C examples that implements the stable C ABI, and calls functions that follow 
this ABI.
+
+Stable C Layout
+---------------
+
+The ``universal_c_abi`` function uses a stable layout for all the input and 
output arguments.
+
+Layout of ``Any``
+~~~~~~~~~~~~~~~~~
+
+TVM-FFI's ``Any`` is a fixed size (128-bit) tagged union that represents all 
supported types.
+
+- First 32 bits: type index indicating which value is stored (supports up to 
2^32 types).
+- Next 32 bits: null padding, or reserved for special flags in rare cases.

Review Comment:
   changed it to
   
   > reserved for special flags in rare cases (e.g. small string optimization)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to