From 1f9f6045d2b83d8b6bddf30315e00231364a1bb3 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 28 Mar 2023 16:51:56 -0700 Subject: Update a1-02-slangpy.md --- docs/user-guide/a1-02-slangpy.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'docs') diff --git a/docs/user-guide/a1-02-slangpy.md b/docs/user-guide/a1-02-slangpy.md index f6f122241..ca0613b1b 100644 --- a/docs/user-guide/a1-02-slangpy.md +++ b/docs/user-guide/a1-02-slangpy.md @@ -10,7 +10,7 @@ to provide a simple way to define kernel functions that runs extremely fast in g automatic differentiation and PyTorch interop features, Slang provides a streamlined solution to author auto-differentiated kernels that runs at the speed of light with a strongly typed, per-thread programming model. -## Getting Started with `slangpy` +## Getting Started with slangpy In this tutorial, we will use a simple example to walkthrough the steps to use Slang in your PyTorch project. @@ -62,8 +62,8 @@ TorchTensor square_fwd(TorchTensor input) return result; } ``` -Here, we first call `TorchTensor.zerosLike` to allocate a 2D-tensor that has the same size as the input. -This function returns a `TorchTensor` object that represents a CPU handle of a PyTorch tensor. +Here, we mark the function with the `[TorchEntryPoint]` attribute so it will be exported to Python. In the function body, we call `TorchTensor.zerosLike` to allocate a 2D-tensor that has the same size as the input. +`zerosLike` returns a `TorchTensor` object that represents a CPU handle of a PyTorch tensor. Then we launch `square_fwd_kernel` with the `__dispatch_kernel` syntax. Note that we can directly pass `TorchTensor` arguments to a `TensorView` parameter and the compiler will automatically convert the type and obtain a view into the tensor that can be accessed by the GPU kernel function. @@ -162,7 +162,7 @@ __bwd_diff(square)(dp, 1.0); // dp.d is now 6.0 ``` -Similarly to `square_fwd`, we can define the host side function `square_bwd` as: +Similar to `square_fwd`, we can define the host side function `square_bwd` as: ```csharp [TorchEntryPoint] @@ -176,11 +176,11 @@ TorchTensor square_bwd(TorchTensor input, TorchTensor grad_ } ``` -You can refer [this documentation](07-autodiff.md) for a detailed reference of Slang's automatic differentiation system. +You can refer to [this documentation](07-autodiff.md) for a detailed reference of Slang's automatic differentiation feature. With this, the python script `slangpy.loadModule("square.slang")` will now return a scope that defines two functions, `square_fwd` and `square_bwd`. We can then use these -two functions to define a PyTorch autograd kernel class: +two functions to define a PyTorch autograd function class: ```python m = slangpy.loadModule("square.slang") @@ -217,7 +217,7 @@ dX = tensor([[6., 8.], ``` -## Builtin Types for PyTorch Interop +## Builtin Library Support for PyTorch Interop As shown in previous tutorial, Slang has defined the `TorchTensor` and `TensorView` type for interop with PyTorch tensors. The `TorchTensor` represents the CPU view of a tensor and provides methods to allocate a new tensor object. -- cgit v1.2.3