yaoyaoding commented on code in PR #169:
URL: https://github.com/apache/tvm-ffi/pull/169#discussion_r2470904235


##########
docs/guides/kernel_library_guide.rst:
##########
@@ -0,0 +1,161 @@
+.. 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 python version and framework 
agnostic kernel libraries with TVM FFI.
+
+Tensor
+======
+
+TVM FFI provide minimal set of data structures to represent tensors from 
frameworks and allows us to build kernels for frameworks. In TVM FFI, we 
support two types of tensor constructs, ``ffi::Tensor`` and ``ffi::TensorView`` 
that can be used to represent a tensor from machine learning frameworks, such 
as PyTorch, XLA, JAX, and so on.
+
+Tensor and TensorView
+---------------------
+
+Both ``ffi::Tensor`` and ``ffi::TensorView`` are designed to represent tensors 
from ML frameworks that interact with the TVM FFI ABI. The main difference is 
whether it is an owning tensor structure.
+
+ffi::Tensor
+ ``ffi::Tensor`` is a completely onwing tensor pointer, pointing to a TVM FFI 
tensor object. TVM FFI handles the lifetime of ``ffi::Tensor`` by retaining a 
strong reference.
+
+ffi::TensorView
+ ``ffi::TensorView`` is non-owning view of an existing tensor. It is backed by 
``DLTensor`` structure in DLPack. Since it is a non-owning view, it is the 
user's responsibility to ensure the lifetime of underlying tensor data and 
attributes of the viewed tensor object.
+
+We **recommend** to use ``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.
+
+Tensor Attributes
+-----------------
+
+For the sake of convenience, ``ffi::TensorView`` and ``ffi::Tensor`` align the 
following attributes retrieval mehtods to ``at::Tensor`` interface:
+
+``dim``, ``sizes``, ``size``, ``strides``, ``stride``, ``numel``, 
``data_ptr``, ``device``, ``is_contiguous``
+
+DLDataType
+ In TVM FFI, tensor data types are stored as ``DLDataType`` which is defined 
by DLPack protocol.
+
+DLDevice
+ In TVM FFI, tensor device information are stored as ``DLDevice`` which is 
defined by DLPack protocol.
+
+ShapeView
+ In TVM FFI, tensor shapes and strides attributes retrieval are returned as 
``ShapeView``. It is an iterate-able data structure storing the shapes or 
strides data as ``int64_t`` array.
+
+Tensor Allocation
+-----------------
+
+TVM FFI provides several methods to allocate tensors, when dynamic tensor 
allocation is necessary.
+
+FromEnvAlloc

Review Comment:
   Any details related to stream? Since the kernel launch will be async, same 
as the memory allocation. The alloc will be issued on the current cuda stream 
of the input tensor's device? What happens if they are on different devices?



##########
docs/guides/kernel_library_guide.rst:
##########
@@ -0,0 +1,161 @@
+.. 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 python version and framework 
agnostic kernel libraries with TVM FFI.
+
+Tensor
+======
+
+TVM FFI provide minimal set of data structures to represent tensors from 
frameworks and allows us to build kernels for frameworks. In TVM FFI, we 
support two types of tensor constructs, ``ffi::Tensor`` and ``ffi::TensorView`` 
that can be used to represent a tensor from machine learning frameworks, such 
as PyTorch, XLA, JAX, and so on.
+
+Tensor and TensorView
+---------------------
+
+Both ``ffi::Tensor`` and ``ffi::TensorView`` are designed to represent tensors 
from ML frameworks that interact with the TVM FFI ABI. The main difference is 
whether it is an owning tensor structure.
+
+ffi::Tensor
+ ``ffi::Tensor`` is a completely onwing tensor pointer, pointing to a TVM FFI 
tensor object. TVM FFI handles the lifetime of ``ffi::Tensor`` by retaining a 
strong reference.
+
+ffi::TensorView
+ ``ffi::TensorView`` is non-owning view of an existing tensor. It is backed by 
``DLTensor`` structure in DLPack. Since it is a non-owning view, it is the 
user's responsibility to ensure the lifetime of underlying tensor data and 
attributes of the viewed tensor object.
+
+We **recommend** to use ``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.
+
+Tensor Attributes
+-----------------
+
+For the sake of convenience, ``ffi::TensorView`` and ``ffi::Tensor`` align the 
following attributes retrieval mehtods to ``at::Tensor`` interface:
+
+``dim``, ``sizes``, ``size``, ``strides``, ``stride``, ``numel``, 
``data_ptr``, ``device``, ``is_contiguous``
+
+DLDataType
+ In TVM FFI, tensor data types are stored as ``DLDataType`` which is defined 
by DLPack protocol.
+
+DLDevice
+ In TVM FFI, tensor device information are stored as ``DLDevice`` which is 
defined by DLPack protocol.
+
+ShapeView
+ In TVM FFI, tensor shapes and strides attributes retrieval are returned as 
``ShapeView``. It is an iterate-able data structure storing the shapes or 
strides data as ``int64_t`` array.
+
+Tensor Allocation

Review Comment:
   Do we support allocate some zero-initialized tensor?
   
   I ask this question because there is a usage that requires the workspace to 
be zero-initailized before we launch the kernel - like the semaphores used in 
split_k optimization of matmul in cutlass. If we have an extra memset-async 
kernel, it will introduce some overhead. I don't have some good idea on this. 
Maybe manually set to zero when first launch the kernel and reserve it to the 
kernel provider.



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