Skip to content

Commit

Permalink
Merge branch 'master' into push-qtwvolruuqpx
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe authored Dec 2, 2024
2 parents 1374d9d + 0586e5a commit b46c9dd
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 15 deletions.
5 changes: 3 additions & 2 deletions docs/scripts/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ public static string getAnchorId(string title)
{
StringBuilder sb = new StringBuilder();
title = title.Trim().ToLower();

foreach (var ch in title)
{
if (ch >= 'a' && ch <= 'z' || ch >= '0' && ch <= '9'
|| ch == '-')
|| ch == '-'|| ch =='_')
sb.Append(ch);
else if (ch==' ' || ch =='_')
else if (ch == ' ' )
sb.Append('-');
}
return sb.ToString();
Expand Down
3 changes: 3 additions & 0 deletions docs/user-guide/07-autodiff.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ interface IDifferentiablePtrType
}
```

> #### Note ####
> Support for `IDifferentiablePtrType` is still experimental.
Types should not conform to both `IDifferentiablePtrType` and `IDifferentiable`. Such cases will result in a compiler error.


Expand Down
41 changes: 41 additions & 0 deletions docs/user-guide/09-targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,47 @@ Slang's CPU compute target supports only a compute pipeline.

Because CPU target support flexible pointer-based addressing and large low-latency caches, a compute kernel can simply be passed a small fixed number of pointers and be relied upon to load parameter values of any types via indirection through those pointers.

## WebGPU

> #### Note
>
> Slang support for WebGPU is work in progress.
WebGPU is a graphics and compute API.
It is similar in spirit to modern APIs, like Metal, Direct3D 12 and Vulkan, but with concessions to portability and privacy.

WebGPU is available both in browsers as a JavaScript API, and natively as a C/C++ API.
[Dawn](https://github.com/google/dawn), is a native WebGPU implementation used by the Chrome browser.

By combining Slang, [Dawn](https://github.com/google/dawn) and [Emscripten](https://emscripten.org/),
an application can easily target any native API, and the web, with a single codebase consisting of C++ and Slang code.

WebGPU shader modules are created from WGSL (WebGPU Shading Language) source files.
WebGPU does not use an intermediate representation - WGSL code is compiled to backend-specific code by
compilers provided by the WebGPU implementation.

### Pipelines

WebGPU supports render and compute pipelines.

The WebGPU render pipeline includes the following programmable stages:

- The vertex stage outputs vertex data

- The fragment stage outputs fragments

### Parameter Passing

WebGPU uses groups of bindings called bind groups to bind things like textures, buffers and samplers.
Bind group objects are passed as arguments when encoding bind group setting commands.

There is a notion of equivalence for bind groups, and a notion of equivalence for pipelines defined in
terms of bind group equivalence.
This equivalence allows an application to save some bind group setting commands, when switching between
pipelines, if bindings are grouped together appropriately.

Which bindings are grouped together can be controlled using Slang's `ParameterBlock` generic type.

## Summary

This chapter has reviewed the main target platforms supported by the Slang compiler and runtime system.
Expand Down
5 changes: 3 additions & 2 deletions docs/user-guide/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<li data-link="convenience-features#subscript-operator"><span>Subscript Operator</span></li>
<li data-link="convenience-features#tuple-types"><span>Tuple Types</span></li>
<li data-link="convenience-features#optionalt-type"><span>`Optional&lt;T&gt;` type</span></li>
<li data-link="convenience-features#if-let-syntax"><span>`if_let` syntax</span></li>
<li data-link="convenience-features#if_let-syntax"><span>`if_let` syntax</span></li>
<li data-link="convenience-features#reinterprett-operation"><span>`reinterpret&lt;T&gt;` operation</span></li>
<li data-link="convenience-features#pointers-limited"><span>Pointers (limited)</span></li>
<li data-link="convenience-features#extensions"><span>Extensions</span></li>
Expand All @@ -66,7 +66,7 @@
<li data-link="capabilities#conflicting-capabilities"><span>Conflicting Capabilities</span></li>
<li data-link="capabilities#requirements-in-parent-scope"><span>Requirements in Parent Scope</span></li>
<li data-link="capabilities#inference-of-capability-requirements"><span>Inference of Capability Requirements</span></li>
<li data-link="capabilities#inference-on-target-switch"><span>Inference on target_switch</span></li>
<li data-link="capabilities#inference-on-target_switch"><span>Inference on target_switch</span></li>
<li data-link="capabilities#capability-aliases"><span>Capability Aliases</span></li>
<li data-link="capabilities#validation-of-capability-requirements"><span>Validation of Capability Requirements</span></li>
</ul>
Expand Down Expand Up @@ -135,6 +135,7 @@
<li data-link="targets#metal"><span>Metal</span></li>
<li data-link="targets#cuda-and-optix"><span>CUDA and OptiX</span></li>
<li data-link="targets#cpu-compute"><span>CPU Compute</span></li>
<li data-link="targets#webgpu"><span>WebGPU</span></li>
<li data-link="targets#summary"><span>Summary</span></li>
</ul>
</li>
Expand Down
36 changes: 25 additions & 11 deletions source/slang/core.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,18 @@ void __requireGLSLExtension(constexpr String preludeText);
__intrinsic_op($(kIROp_StaticAssert))
void static_assert(constexpr bool condition, NativeString errorMessage);

/// Interface to denote types as differentiable.
/// Allows for user-specified differential types as
/// well as automatic generation, for when the associated type
/// hasn't been declared explicitly.
/// Note that the requirements must currently be defined in this exact order
/// since the auto-diff pass relies on the order to grab the struct keys.
/// Represents a type that is differentiable for the purposes of automatic differentiation.
///
/// Implemented by builtin floating-point scalar types (`float`, `half`, `double`)
///
/// vector<T, N>, matrix<T, N, M> and Array<T, N> automatically conform to
/// `IDifferentiable` if `T` conforms to `IDifferentiable`.
///
/// @remarks Types that implement `IDifferentiable` can be used with the automatic differentiation
/// primitives `bwd_diff` and `fwd_diff` to load and store gradients of parameters.
/// @remarks This interface supports automatic synthesis of requirements. A struct that conforms to `IDifferentiable`
/// will have its `Differential`, `dzero()` and `dadd()` methods automatically synthesized based on its fields, if
/// they are not already defined.
__magic_type(DifferentiableType)
interface IDifferentiable
{
Expand All @@ -446,9 +451,13 @@ interface IDifferentiable
static Differential dmul(T, Differential);
};

/// Represents a type that supports differentiation operations for pointer types.
/// This interface is used to define operations that are specific to pointer types
/// in the context of automatic differentiation.
/// @experimental
///
/// Represents a type that supports differentiation operations for pointers, buffers and
/// any other types
///
/// @remarks Support for this interface is still experimental and subject to change.
///
__magic_type(DifferentiablePtrType)
interface IDifferentiablePtrType
{
Expand All @@ -458,8 +467,9 @@ interface IDifferentiablePtrType


/// Pair type that serves to wrap the primal and
/// differential types of an arbitrary type T.

/// differential types of a differentiable value type
/// T that conforms to `IDifferentiable`.
///
__generic<T : IDifferentiable>
__magic_type(DifferentialPairType)
__intrinsic_type($(kIROp_DifferentialPairUserCodeType))
Expand Down Expand Up @@ -528,6 +538,10 @@ struct DifferentialPair : IDifferentiable
}
};

/// Pair type that serves to wrap the primal and
/// differential types of a differentiable pointer type
/// T that conforms to `IDifferentiablePtrType`.
///
__generic<T : IDifferentiablePtrType>
__magic_type(DifferentialPtrPairType)
__intrinsic_type($(kIROp_DifferentialPtrPairType))
Expand Down
1 change: 1 addition & 0 deletions source/slang/slang-ir-autodiff-fwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,7 @@ InstPair ForwardDiffTranscriber::transcribeInstImpl(IRBuilder* builder, IRInst*
case kIROp_GetArrayLength:
case kIROp_SizeOf:
case kIROp_AlignOf:
case kIROp_Printf:
return transcribeNonDiffInst(builder, origInst);

// A call to createDynamicObject<T>(arbitraryData) cannot provide a diff value,
Expand Down

0 comments on commit b46c9dd

Please sign in to comment.