Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to realize reduction when a variable is initialized within the loop #195

Open
nipunayf opened this issue May 26, 2023 · 2 comments
Open
Labels
bug Something isn't working

Comments

@nipunayf
Copy link
Contributor

When we initialize the variable x within the kernel as shown below, an error is generated indicating that it has failed to realize reduction.

void foo(double step, int steps, double *sum) {
  for (int i = 0; i < steps; i++) {
    double x = (i + 0.5) * step;
    sum[0] += 4.0 / (1.0 + x * x);
  }
}

The following error is generated when the kernel is run in loopy_api.py.

Traceback (most recent call last):
  File "/home/xenon/projects/nomp/libnomp/python/loopy_api.py", line 813, in <module>
    lp_knl = realize_reduction(lp_knl, "sum")
  File "/home/xenon/projects/nomp/libnomp/python/reduction.py", line 113, in realize_reduction
    tunit = lp.make_kernel(
  File "/home/xenon/mambaforge/envs/libnomp/lib/python3.10/site-packages/loopy/kernel/creation.py", line 2569, in make_kernel
    tunit = make_function(*args, **kwargs)
  File "/home/xenon/mambaforge/envs/libnomp/lib/python3.10/site-packages/loopy/kernel/creation.py", line 2497, in make_function
    check_for_duplicate_insn_ids(knl)
  File "/home/xenon/mambaforge/envs/libnomp/lib/python3.10/site-packages/loopy/translation_unit.py", line 703, in _collective_transform
    return transform(kernel, *args, **kwargs)
  File "/home/xenon/mambaforge/envs/libnomp/lib/python3.10/site-packages/loopy/check.py", line 417, in check_for_duplicate_insn_ids
    raise LoopyError("duplicate instruction id: '%s'" % insn.id)
loopy.diagnostic.LoopyError: duplicate instruction id: '_nomp_insn'

However, the following kernel works as expected.

void foo(double step, int steps, double *sum) {
  for (int i = 0; i < steps; i++) {
    sum[0] += 4.0 / (1.0 + (i + 0.5) * step * (i + 0.5) * step);
  }
}
@nipunayf nipunayf added the bug Something isn't working label May 26, 2023
@thilinarmtb
Copy link
Contributor

This should be easy to fix. I think the issue is the following line in reduction.py generating
instructions ids already generated in loopy_api.py:
https://github.com/nomp-org/libnomp/blob/main/python/reduction.py#L106

@thilinarmtb
Copy link
Contributor

thilinarmtb commented Jun 1, 2023

This should be easy to fix. I think the issue is the following line in reduction.py generating instructions ids already generated in loopy_api.py: https://github.com/nomp-org/libnomp/blob/main/python/reduction.py#L106

I think this was a typo on my part. I should have used the following function (get_instruction_id_generator()) instead of get_var_name_generator():
https://github.com/inducer/loopy/blob/main/loopy/kernel/__init__.py#L258

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants