We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When attempting to convert and generate the device code for a C kernel with a if condition, it generates the following error:
/home/hp/mambaforge/envs/libnomp/bin/python /home/hp/projects/nomp/libnomp/python/loopy_api.py Traceback (most recent call last): File "/home/hp/mambaforge/envs/libnomp/lib/python3.10/site-packages/loopy/tools.py", line 933, in wrapper result = transform_cache[cache_key] File "/home/hp/mambaforge/envs/libnomp/lib/python3.10/site-packages/pytools/persistent_dict.py", line 583, in __getitem__ return self.fetch(key, _stacklevel=1) File "/home/hp/mambaforge/envs/libnomp/lib/python3.10/site-packages/pytools/persistent_dict.py", line 702, in fetch raise NoSuchEntryError(key) pytools.persistent_dict.NoSuchEntryError: ('preprocess_program', 'preprocess_program', (TranslationUnit(func_id_to_in_knl_callable_mappers=[], entrypoints=frozenset({'foo'}), callables_table=pmap({'foo': CallableKernel(arg_id_to_descr=None, arg_id_to_dtype=None, name='foo', subkernel=LoopKernel(domains=[BasicSet("[N] -> { [i] : 0 <= i <= N }")], instructions=[Assignment(conflicts_with_groups=frozenset(), assignee=Subscript(Variable('a'), Variable('i')), tags=frozenset(), depends_on=frozenset(), no_sync_with=frozenset(), within_inames=frozenset({'i'}), groups=frozenset(), id='_nomp_insn', within_inames_is_final=False, expression=Product((Subscript(Variable('a'), Variable('i')), Sum((Variable('i'), 1)))), predicates=frozenset({Comparison(Subscript(Variable('a'), Variable('i')), '>', 0)}), temp_var_type=Optional(), atomicity=(), depends_on_is_final=True, priority=0)], args=[<a: ArrayArg, type: np:dtype('float64'), shape: unknown in/out aspace: global>, <N: ValueArg, type: np:dtype('int32')>], assumptions=BasicSet("[N] -> { : }"), temporary_variables={}, inames={'i': Iname(name='i', tags=frozenset())}, substitutions={}, options=Options(disable_global_barriers=False, enforce_variable_access_ordered=True, return_dict=False, trace_assignments=False, insert_gbarriers=False, check_dep_resolution=True, no_numpy=False, annotate_inames=False, cl_exec_manage_array_events=True, edit_code=False, write_code=False, allow_fp_reordering=True, enforce_array_accesses_within_bounds=True, trace_assignment_values=False, skip_arg_checks=False, allow_terminal_colors=True, build_options=[], write_wrapper=False), target=<loopy.target.opencl.OpenCLTarget object at 0x7fc1fcd3b670>, tags=frozenset(), state=<KernelState.INITIAL: 0>, name='foo', preambles=(), preamble_generators=(), symbol_manglers=(), linearization=None, iname_slab_increments=immutables.Map({}), loop_priority=frozenset(), applied_iname_rewrites=(), index_dtype=np:dtype('int32'), silenced_warnings=[], overridden_get_grid_sizes_for_insn_ids=None))}), target=<loopy.target.opencl.OpenCLTarget object at 0x7fc1fcd3b670>),), {}) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/hp/projects/nomp/libnomp/python/loopy_api.py", line 624, in <module> print(lp.generate_code_v2(lp_knl).device_code()) File "/home/hp/mambaforge/envs/libnomp/lib/python3.10/site-packages/loopy/codegen/__init__.py", line 597, in generate_code_v2 program = preprocess_program(program) File "/home/hp/mambaforge/envs/libnomp/lib/python3.10/site-packages/loopy/tools.py", line 949, in wrapper result = func(*args, **kwargs) File "/home/hp/mambaforge/envs/libnomp/lib/python3.10/site-packages/loopy/preprocess.py", line 843, in preprocess_program new_subkernel = _preprocess_single_kernel( File "/home/hp/mambaforge/envs/libnomp/lib/python3.10/site-packages/loopy/preprocess.py", line 761, in _preprocess_single_kernel check_for_writes_to_predicates(kernel) File "/home/hp/mambaforge/envs/libnomp/lib/python3.10/site-packages/loopy/preprocess.py", line 67, in check_for_writes_to_predicates raise LoopyError("In instruction '%s': may not write to " loopy.diagnostic.LoopyError: In instruction '_nomp_insn': may not write to variable(s) 'a' involved in the instruction's predicates Process finished with exit code 1
loopy_api.py
void foo(double *a, int N) { for (int i = 0; i < N + 1; i++) if (a[i] > 0) a[i] = a[i] * (i + 1); }
print(lp.generate_code_v2(lp_knl).device_code())
The text was updated successfully, but these errors were encountered:
Thanks for reporting this !
Sorry, something went wrong.
Additional note to this issue,
The issue appears when we access an array element in the condition, in this case a[i]. If we rewrite the kernel as below, the issue will be resolved.
a[i]
void foo(double *a, int N) { for (int i = 0; i < N + 1; i++) int temp = a[i]; if (temp > 0) a[i] = a[i] * (i + 1); }
Additional note to this issue, The issue appears when we access an array element in the condition, in this case a[i]. If we rewrite the kernel as below, the issue will be resolved. void foo(double *a, int N) { for (int i = 0; i < N + 1; i++) int temp = a[i]; if (temp > 0) a[i] = a[i] * (i + 1); }
Yes, we need to make sure that if condition is a dependency for the code in then and else branch.
if
then
else
thilinarmtb
No branches or pull requests
Description
When attempting to convert and generate the device code for a C kernel with a if condition, it generates the following error:
Reproduce Steps
loopy_api.py
to convert the following C kernel.The text was updated successfully, but these errors were encountered: