Skip to content

Commit

Permalink
gosl: rand example fixed, x,y,z,w components are auto-downcased
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Jan 9, 2025
1 parent ce5d921 commit 017d41d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
5 changes: 3 additions & 2 deletions gosl/examples/rand/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func main() {
GPUInit()

// n := 10
// n := 16_000_000 // max for macbook M*
n := 200_000
n := 16_000_000 // max for macbook M*
// n := 200_000

UseGPU = false

Expand All @@ -53,6 +53,7 @@ func main() {
gpuFullTmr := timer.Time{}
gpuFullTmr.Start()

ToGPUTensorStrides()
ToGPU(SeedVar, FloatsVar, UintsVar)

gpuTmr := timer.Time{}
Expand Down
16 changes: 8 additions & 8 deletions gosl/examples/rand/shaders/Compute.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ fn RndGen(counter: su64, idx: u32) {
var floats11 = RandFloat32Range11Vec2(counter, u32(2), idx);
var gauss = RandFloat32NormVec2(counter, u32(3), idx);
Uints[Index2D(TensorStrides[10], TensorStrides[11], u32(idx), u32(0))] = uints.x;
Uints[Index2D(TensorStrides[10], TensorStrides[11], u32(idx), u32(1))] = uints.Y;
Floats[Index2D(TensorStrides[0], TensorStrides[1], u32(idx), u32(FloatX))] = floats.X;
Floats[Index2D(TensorStrides[0], TensorStrides[1], u32(idx), u32(FloatY))] = floats.Y;
Floats[Index2D(TensorStrides[0], TensorStrides[1], u32(idx), u32(Float11X))] = floats11.X;
Floats[Index2D(TensorStrides[0], TensorStrides[1], u32(idx), u32(Float11Y))] = floats11.Y;
Floats[Index2D(TensorStrides[0], TensorStrides[1], u32(idx), u32(GaussX))] = gauss.X;
Floats[Index2D(TensorStrides[0], TensorStrides[1], u32(idx), u32(GaussY))] = gauss.Y;
Uints[Index2D(TensorStrides[10], TensorStrides[11], u32(idx), u32(1))] = uints.y;
Floats[Index2D(TensorStrides[0], TensorStrides[1], u32(idx), u32(FloatX))] = floats.x;
Floats[Index2D(TensorStrides[0], TensorStrides[1], u32(idx), u32(FloatY))] = floats.y;
Floats[Index2D(TensorStrides[0], TensorStrides[1], u32(idx), u32(Float11X))] = floats11.x;
Floats[Index2D(TensorStrides[0], TensorStrides[1], u32(idx), u32(Float11Y))] = floats11.y;
Floats[Index2D(TensorStrides[0], TensorStrides[1], u32(idx), u32(GaussX))] = gauss.x;
Floats[Index2D(TensorStrides[0], TensorStrides[1], u32(idx), u32(GaussY))] = gauss.y;
}
fn Compute(i: u32) { //gosl:kernel
RndGen(Seed[0].Seed, i);
Expand Down Expand Up @@ -219,4 +219,4 @@ fn Uint32ToFloat32Range11Vec2(val: vec2<u32>) -> vec2<f32> {
r.x = Uint32ToFloat32Range11(val.x);
r.y = Uint32ToFloat32Range11(val.y);
return r;
}
}
6 changes: 5 additions & 1 deletion gosl/gotosl/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,11 @@ func (p *printer) selectorExpr(x *ast.SelectorExpr, depth int) (wasIndented bool
return true
}
p.setPos(x.Sel.Pos())
p.print(x.Sel)
if x.Sel.Name == "X" || x.Sel.Name == "Y" || x.Sel.Name == "Z" || x.Sel.Name == "W" {
p.print(strings.ToLower(x.Sel.Name))
} else {
p.print(x.Sel)
}
return false
}

Expand Down

0 comments on commit 017d41d

Please sign in to comment.