cyx-6 commented on code in PR #169:
URL: https://github.com/apache/tvm-ffi/pull/169#discussion_r2544258458


##########
docs/guides/kernel_library_guide.rst:
##########
@@ -0,0 +1,171 @@
+.. 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.
+
+====================
+Kernel Library Guide
+====================
+
+This guide serves as a quick start for shipping kernel libraries with TVM FFI. 
The shipped kernel libraries are of python version and ML framework agnostic. 
With the help of TVM FFI, we can connect the kernel libraries to multiple ML 
framework, such as PyTorch, XLA, JAX, together with the minimal efforts.
+
+Tensor
+======
+
+Almost all kernel libraries are about tensor computation and manipulation. For 
better adaptation to different ML frameworks, TVM FFI provides a minimal set of 
data structures to represent tensors from ML frameworks, including the tensor 
basic attributes and storage pointer.
+To be specific, in TVM FFI, two types of tensor constructs, 
:cpp:class:`~tvm::ffi::Tensor` and :cpp:class:`~tvm::ffi::TensorView`, can be 
used to represent a tensor from ML frameworks.
+
+Tensor and TensorView
+---------------------
+
+Both :cpp:class:`~tvm::ffi::Tensor` and :cpp:class:`~tvm::ffi::TensorView` are 
designed to represent tensors from ML frameworks that interact with the TVM FFI 
ABI. They are backed by the `DLTensor` in DLPack in practice. The main 
difference is whether it is an owning tensor structure.
+
+:cpp:class:`tvm::ffi::Tensor`
+ :cpp:class:`~tvm::ffi::Tensor` is a completely owning tensor with reference 
counting. It can be created on either C++ or Python side and passed between 
either side. And TVM FFI internally keeps a reference count to track lifetime 
of the tensors. When the reference count goes to zero, its underlying deleter 
function will be called to free the tensor storage.
+
+:cpp:class:`tvm::ffi::TensorView`
+ :cpp:class:`~tvm::ffi::TensorView` is a non-owning view of an existing 
tensor, pointing to an existing tensor (e.g., a tensor allocated by PyTorch).
+
+It is **recommended** to use :cpp:class:`~tvm::ffi::TensorView` when possible, 
that helps us to support more cases, including cases where only view but not 
strong reference are passed, like XLA buffer. It is also more lightweight. 
However, since :cpp:class:`~tvm::ffi::TensorView` is a non-owning view, it is 
the user's responsibility to ensure the lifetime of underlying tensor.
+
+Tensor Attributes
+-----------------
+
+For the sake of convenience, :cpp:class:`~tvm::ffi::TensorView` and 
:cpp:class:`~tvm::ffi::Tensor` align the following attributes retrieval mehtods 
to :cpp:class:`at::Tensor` interface, to obtain tensor basic attributes and 
storage pointer:
+``dim``, ``dtype``, ``sizes``, ``size``, ``strides``, ``stride``, ``numel``, 
``data_ptr``, ``device``, ``is_contiguous``
+
+Please refer to the documentation of both tensor classes for their details. 
Here  highlight some non-primitive attributes:
+
+:c:struct:`DLDataType`

Review Comment:
   yes, I have verified locally and it rendered correctly. Here, to obtain the 
correct tags, just using
   `python -m sphinx.ext.intersphinx 
https://docs.pytorch.org/cppdocs/objects.inv`
   and make sure `conf.py` is updated as well.



-- 
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