Skip to content

Commit 70da183

Browse files
author
hartsantler
committed
webCLgl backend: fixed pure python typedef vars that use an attribute a.x
1 parent 08ff532 commit 70da183

3 files changed

Lines changed: 23 additions & 17 deletions

File tree

pythonjs/python_to_pythonjs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,6 +2418,7 @@ def visit_FunctionDef(self, node):
24182418
threaded = self._with_webworker
24192419
jsfile = None
24202420

2421+
self._typedef_vars = dict() ## clear typed variables: filled in below by @typedef or in visit_Assign
24212422
self._gpu_return_types = set()
24222423
gpu = False
24232424
gpu_main = False
@@ -2441,6 +2442,7 @@ def visit_FunctionDef(self, node):
24412442
assert len(c.args) == 0 and len(c.keywords)
24422443
for kw in c.keywords:
24432444
assert isinstance( kw.value, Name)
2445+
self._typedef_vars[ kw.arg ] = kw.value.id
24442446
self._instances[ kw.arg ] = kw.value.id
24452447
self._func_typedefs[ kw.arg ] = kw.value.id
24462448
local_typedefs.append( '%s=%s' %(kw.arg, kw.value.id))

regtests/webclgl/hello_gpu.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
"""gpu test"""
22

33
def main():
4-
with glsl as myfunc:
5-
def main(buffA, buffB, num):
6-
float* buffA
7-
float* buffB
8-
float num
9-
vec2 n = get_global_id() ## WebCL API
10-
float result = 0.0
11-
for i in range(1000):
12-
result = sqrt(result + A[n] + B[n] + float(i))
13-
return result * num
4+
@returns( array=[4,16])
5+
@gpu.main
6+
def myfunc(a, b, num):
7+
float* a
8+
float* b
9+
float num
10+
vec2 n = get_global_id() ## WebCL API
11+
float result = 0.0
12+
for i in range(1000):
13+
result = sqrt(result + a[n] + b[n] + float(i))
14+
return result * num
1415

15-
A = [1,2,3]
16-
B = [4,5,6]
17-
res = myfunc( A, B, 2.0 )
16+
A = [ 0.5 for x in range(64) ]
17+
B = [ 0.25 for x in range(64) ]
18+
res = myfunc( A, B, 0.1 )
1819
print(res)

regtests/webclgl/mandel_purepy.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def pprint(arr, w):
1010

1111
def main():
1212

13-
@returns( array=[32,32] )
13+
@returns( array=[64,64] )
1414
@typedef( x=float, y=float, tempX=float, i=int, runaway=int, c=vec2)
1515
@gpu.main
1616
def gpufunc():
@@ -30,7 +30,10 @@ def gpufunc():
3030
return float(runaway) * 0.01
3131

3232
res = gpufunc()
33+
print(res)
34+
TestError( len(res)==64*64 )
35+
3336
#pprint(res, 32)
34-
for row in res:
35-
a = [ round(v,3) for v in row ]
36-
print( a )
37+
#for row in res:
38+
# a = [ round(v,3) for v in row ]
39+
# print( a )

0 commit comments

Comments
 (0)