inducer / inducer/loopy

What is Loopy's function namespace? (was: Is min a reduction or a 2-arg minimum like OpenCL)

Open
#73 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
636
Forks
81
Avg merge
1d 19h
Merged PRs (30d)
7

Description

Sorry about the many pull requests / issues today! Been playing around with reductions, and breaking things in all sorts of interesting ways :)

Here's a fun one:

```
import loopy as lp
import pyopencl as cl
lp.set_caching_enabled(False)

ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)

knl = lp.make_kernel('{[i]: 0 < i < 10}',
"""
out[i] = min(i, 5)
""",
['...'])

print lp.generate_code(knl)[0]
```

Results in:
```
File "test.py", line 14, in
print lp.generate_code(knl)[0]
File "/home/nick/loopy/loopy/codegen/__init__.py", line 523, in generate_code
codegen_result = generate_code_v2(kernel)
File "/home/nick/loopy/loopy/codegen/__init__.py", line 383, in generate_code_v2
kernel = preprocess_kernel(kernel)
File "/home/nick/loopy/loopy/preprocess.py", line 912, in preprocess_kernel
kernel = realize_reduction(kernel, unknown_types_ok=False)
File "/home/nick/loopy/loopy/preprocess.py", line 649, in realize_reduction
new_expressions = (cb_mapper(insn.expression),)
File "/home/nick/.local/lib/python2.7/site-packages/pymbolic/mapper/__init__.py", line 134, in __call__
return method(expr, *args, **kwargs)
File "/home/nick/loopy/loopy/symbolic.py", line 1345, in map_reduction
result = self.callback(expr, self.rec, **kwargs)
File "/home/nick/loopy/loopy/preprocess.py", line 559, in map_reduction
"supposed to reduce over: " + ", ".join(bad_inames))
loopy.diagnostic.LoopyError: reduction used within loop(s) that it was supposed to reduce over: i
```

However,

```
import loopy as lp
import pyopencl as cl
lp.set_caching_enabled(False)

ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)

knl = lp.make_kernel('{[i]: 0 < i < 10}',
"""
out[i] = abs(-i)
""",
['...'])

print knl(queue)[1]
```

works as expected (both are defined in the opencl function manglers).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.