Skip to content

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

@nipunayf

Description

@nipunayf

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);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions