Skip to content

Commit 6d2c37e

Browse files
committed
Revert "Update samples"
This reverts commit 7a8697e.
1 parent 7a8697e commit 6d2c37e

File tree

15 files changed

+42
-42
lines changed

15 files changed

+42
-42
lines changed

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Welcome to SlangPy examples! Here you'll find well written and documented exampl
2121
|-------------|-------------|
2222
| [first_function](https://slangpy.shader-slang.org/en/latest/src/basics/firstfunctions.html) | Most basic use of SlangPy to call a single function. |
2323
| [return_type](https://slangpy.shader-slang.org/en/latest/src/basics/returntype.html) | Use a different return type for a function. |
24-
| [buffers](https://slangpy.shader-slang.org/en/latest/src/basics/buffers.html) | Tensor creation/use. |
24+
| [buffers](https://slangpy.shader-slang.org/en/latest/src/basics/buffers.html) | NDBuffer creation/use. |
2525
| [textures](https://slangpy.shader-slang.org/en/latest/src/basics/textures.html) | Simple manipulation of texture data using SlangPy. |
2626
| [nested](https://slangpy.shader-slang.org/en/latest/src/basics/nested.html) | Shows how to use Python dictionaries to pass nested data in SOA form. |
2727
| [type_methods](https://slangpy.shader-slang.org/en/latest/src/basics/typemethods.html) | Use of InstanceList, InstanceBuffer and get_this to invoke methods of a type. |

examples/autodiff/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
# Attach gradients to the result, and set them to 1 for the backward pass
3030
result = result.with_grads()
31-
result.grad.copy_from_numpy(np.array([1, 1, 1, 1], dtype=np.float32))
31+
result.grad.storage.copy_from_numpy(np.array([1, 1, 1, 1], dtype=np.float32))
3232

3333
# Call the backwards version of module.polynomial
3434
# This will read the grads from _result, and write the grads to x

examples/buffers/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
# Load module
1919
module = spy.Module.load_from_file(device, "example.slang")
2020

21-
# Create a couple of 2D 16x16 tensors
22-
image_1 = spy.Tensor.empty(device,shape=(16, 16), dtype=module.Pixel)
23-
image_2 = spy.Tensor.empty(device,shape=(16, 16), dtype=module.Pixel)
21+
# Create a couple of 2D 16x16 buffers
22+
image_1 = spy.NDBuffer(device, dtype=module.Pixel, shape=(16, 16))
23+
image_2 = spy.NDBuffer(device, dtype=module.Pixel, shape=(16, 16))
2424

25-
# Use a cursor to fill the first tensor with readable structured data.
25+
# Use a cursor to fill the first buffer with readable structured data.
2626
cursor_1 = image_1.cursor()
2727
for x in range(16):
2828
for y in range(16):
@@ -35,8 +35,8 @@
3535
)
3636
cursor_1.apply()
3737

38-
# Use the fact that we know the tensors are just 16x16 grids of 3 floats
39-
# to just populate the 2nd tensor straight from random numpy array
38+
# Use the fact that we know the buffers are just 16x16 grids of 3 floats
39+
# to just populate the 2nd buffer straight from random numpy array
4040
image_2.copy_from_numpy(0.1 * np.random.rand(16 * 16 * 3).astype(np.float32))
4141

4242
# Call the module's add function

examples/sdf-match/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ input, input_data = generate_input(samplesSize)
7575
params, params_grad, params_data, params_grad_data = generate_init_params(network_shape)
7676

7777
# Initialize Adam optimizer state
78-
adam_state = spy.Tensor.empty(app.device, dtype=module.AdamState, shape=(param_size,))
78+
adam_state = spy.NDBuffer(app.device, dtype=module.AdamState, shape=(param_size,))
7979
```
8080

8181
### 2. Main Loop

examples/sdf-match/main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def generate_init_params(network_shape: list[int]):
4949

5050
params_grad_data = np.zeros((params_size,), dtype=np.float32)
5151

52-
params = spy.Tensor.from_numpy(app.device, params_data)
53-
params_grad = spy.Tensor.from_numpy(app.device, params_grad_data)
52+
params = spy.NDBuffer.from_numpy(app.device, params_data)
53+
params_grad = spy.NDBuffer.from_numpy(app.device, params_grad_data)
5454
return params, params_grad, params_data, params_grad_data
5555

5656

@@ -63,8 +63,8 @@ def generate_input(samplesSize: int, input_size: int):
6363

6464

6565
# construct the network, the network is a tiny MLP with 1 hidden layer
66-
def construct_network(params: spy.Tensor, params_grad: spy.Tensor):
67-
tiny_mlp = spy.Tensor.empty(app.device, dtype=module.TinyMLP_Params, shape=(1,))
66+
def construct_network(params: spy.NDBuffer, params_grad: spy.NDBuffer):
67+
tiny_mlp = spy.NDBuffer(app.device, dtype=module.TinyMLP_Params, shape=(1,))
6868
tiny_mlp_cursor = tiny_mlp.cursor()
6969
tiny_mlp_cursor[0].write(
7070
{
@@ -78,8 +78,8 @@ def construct_network(params: spy.Tensor, params_grad: spy.Tensor):
7878

7979
def trainMLP(
8080
iter: int,
81-
tiny_mlp_params: spy.Tensor,
82-
adam_state: spy.Tensor,
81+
tiny_mlp_params: spy.NDBuffer,
82+
adam_state: spy.NDBuffer,
8383
input: spy.Tensor,
8484
batch_size: int,
8585
):
@@ -113,7 +113,7 @@ def trainMLP(
113113
# Initialize Adam state, the adam state is per-parameter state, so the size is the same as the params.
114114
# Call slang function `clearAdamState` to clear the adam state.
115115
param_size = get_weight_size(network_shape) + get_bias_size(network_shape)
116-
adam_state = spy.Tensor.empty(app.device, dtype=module.AdamState, shape=(param_size,))
116+
adam_state = spy.NDBuffer(app.device, dtype=module.AdamState, shape=(param_size,))
117117
module.clearAdamState(adam_state)
118118

119119
# Main loop

examples/soft-rasterizer/rasterizer2d.slang

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,15 @@ void generate_gradients(Camera camera, in Tensor<float2, 1> primal, AtomicTensor
212212
{
213213
// Wrap the vertices in a diffPair so we can use autodiff to get the
214214
// partial derivatives and calculate gradients
215-
float2 vertices[3] = { primal.load(0), primal.load(1), primal.load(2) };
215+
float2 vertices[3] = { primal.get({0}), primal.get({1}), primal.get({2}) };
216216
var dVertices = diffPair(vertices);
217217

218218
bwd_diff(loss)(camera, dVertices, pixelCoord, reference, 1.0);
219219

220220
// Accumulate (add) gradients for this point into the gradients tensor.
221-
grad.add(0, dVertices.d[0]);
222-
grad.add(1, dVertices.d[1]);
223-
grad.add(2, dVertices.d[2]);
221+
grad.set({0}, dVertices.d[0]);
222+
grad.set({1}, dVertices.d[1]);
223+
grad.set({2}, dVertices.d[2]);
224224
}
225225

226226

examples/toy-restir/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@
5959

6060
# Initialize the random generators.
6161
np.random.seed(0)
62-
pathRandom = spy.Tensor.empty(device,shape=(imageHeight, imageWidth), dtype=module.RandomStream)
63-
risRandom = spy.Tensor.empty(device,shape=(imageHeight, imageWidth), dtype=module.RandomStream)
62+
pathRandom = spy.NDBuffer(device, dtype=module.RandomStream, shape=(imageHeight, imageWidth))
63+
risRandom = spy.NDBuffer(device, dtype=module.RandomStream, shape=(imageHeight, imageWidth))
6464
risRandom.copy_from_numpy(np.random.randint(2**32, dtype=np.uint32, size=(imageHeight, imageWidth)))
6565

6666
# Create reservoirs.
67-
initialOutput = spy.Tensor.empty(device,shape=(imageHeight, imageWidth), dtype=module.Reservoir)
68-
temporalOutput = spy.Tensor.empty(device,shape=(imageHeight, imageWidth), dtype=module.Reservoir)
69-
spatialOutput = spy.Tensor.empty(device,shape=(imageHeight, imageWidth), dtype=module.Reservoir)
67+
initialOutput = spy.NDBuffer(device, dtype=module.Reservoir, shape=(imageHeight, imageWidth))
68+
temporalOutput = spy.NDBuffer(device, dtype=module.Reservoir, shape=(imageHeight, imageWidth))
69+
spatialOutput = spy.NDBuffer(device, dtype=module.Reservoir, shape=(imageHeight, imageWidth))
7070

7171
# Prepare the image.
7272
tex = device.create_texture(

examples/toy-restir/toy-restir.slang

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ void sampleAndMergeInitialCandidate(int2 pixel, int frame, int2 imageSize, int s
360360
reservoir.c = 1.0f;
361361
}
362362

363-
void performTemporalReuse(int2 pixel, int frame, inout Reservoir outReservoir, in RWTensor<Reservoir, 2> initialSampleReservoirs, in RWTensor<Reservoir, 2> temporalReservoirs, int2 imageSize,
363+
void performTemporalReuse(int2 pixel, int frame, inout Reservoir outReservoir, in RWNDBuffer<Reservoir, 2> initialSampleReservoirs, in RWNDBuffer<Reservoir, 2> temporalReservoirs, int2 imageSize,
364364
inout RandomStream risRandom)
365365
{
366366
float t = (float)frame;
@@ -405,7 +405,7 @@ void performTemporalReuse(int2 pixel, int frame, inout Reservoir outReservoir, i
405405
outReservoir = result;
406406
}
407407

408-
void performSpatialReuse(int2 pixel, inout Reservoir outReservoir, in RWTensor<Reservoir, 2> reservoirs, int2 imageSize, inout RandomStream risRandom)
408+
void performSpatialReuse(int2 pixel, inout Reservoir outReservoir, in RWNDBuffer<Reservoir, 2> reservoirs, int2 imageSize, inout RandomStream risRandom)
409409
{
410410
// Get current pixel's reservoir.
411411
let currentReservoir = reservoirs[pixel];

examples/type_methods/extend_instancelists.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class MyParticles(spy.InstanceList):
2525
def __init__(self, name: str, count: int):
2626
super().__init__(module.Particle.as_struct())
2727
self.name = name
28-
self.position = spy.Tensor.empty(device,shape=(count,), dtype=module.float3)
29-
self.velocity = spy.Tensor.empty(device,shape=(count,), dtype=module.float3)
28+
self.position = spy.NDBuffer(device, dtype=module.float3, shape=(count,))
29+
self.velocity = spy.NDBuffer(device, dtype=module.float3, shape=(count,))
3030

3131
def print_particles(self):
3232
print(self.name)

examples/type_methods/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
module = spy.Module.load_from_file(device, "example.slang")
1818

1919
# Create buffer of particles (.as_struct is used to make python typing happy!)
20-
particles = spy.InstanceTensor(struct=module.Particle.as_struct(), shape=(10,))
20+
particles = spy.InstanceBuffer(struct=module.Particle.as_struct(), shape=(10,))
2121

2222
# Construct every particle with position of 0, and use slangpy's rand_float
2323
# functionality to supply a different rand vector for each one.
2424
particles.construct(p=spy.float3(0), v=spy.rand_float(-1, 1, 3))
2525

2626
# Print all the particles by breaking them down into groups of 6 floats
27-
result_cursor = particles.tensor.cursor()
27+
result_cursor = particles.buffer.cursor()
2828

2929
for i in range(particles.shape[0]):
3030
instance = result_cursor[i].read()
@@ -33,7 +33,7 @@
3333
# Update the particles
3434
particles.update(0.1)
3535

36-
result_cursor = particles.tensor.cursor()
36+
result_cursor = particles.buffer.cursor()
3737
# Print all the particles by breaking them down into groups of 6 floats
3838
for i in range(particles.shape[0]):
3939
instance = result_cursor[i].read()

0 commit comments

Comments
 (0)