Skip to content

TypeInferenceMapper.map_floor_div returns incorrect results with np.uint64 #999

@kaushikcfd

Description

@kaushikcfd
(py314_env) kaushikggg@line:~/temp$ cat file.py 
import loopy as lp
import numpy as np


knl = lp.make_kernel(
    "{[i]: 0<=i<10}",
    """
    a[map[i] // 2] = i
    """,
    [lp.GlobalArg("map", dtype=np.uint64, shape=lp.auto), ...],
    lang_version=(2018, 2))
print(lp.generate_code_v2(knl).device_code())
(py314_env) kaushikggg@line:~/temp$ LOOPY_NO_CACHE=1 python file.py
===========================================================================
failing translation unit during pre-schedule check:
===========================================================================
---------------------------------------------------------------------------
KERNEL: loopy_kernel
---------------------------------------------------------------------------
ARGUMENTS:
map: type: np:dtype('uint64'), shape: (10), dim_tags: (N0:stride:1) in aspace: global
a: ArrayArg, type: np:dtype('int32'), shape: unknown out aspace: global
---------------------------------------------------------------------------
DOMAINS:
{ [i] : 0 <= i <= 9 }
---------------------------------------------------------------------------
INAME TAGS:
i: None
---------------------------------------------------------------------------
INSTRUCTIONS:
for i
  a[map[i] // 2] = i  {id=insn}
end i
---------------------------------------------------------------------------
===========================================================================
Traceback (most recent call last):
  File "/home/kaushikggg/temp/file.py", line 12, in <module>
    print(lp.generate_code_v2(knl).device_code())
          ~~~~~~~~~~~~~~~~~~~^^^^^
  File "/home/kaushikggg/projects/loopy/loopy/codegen/__init__.py", line 569, in generate_code_v2
    t_unit = linearize(t_unit)
  File "/home/kaushikggg/projects/loopy/loopy/schedule/__init__.py", line 2456, in linearize
    pre_schedule_checks(t_unit)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/home/kaushikggg/projects/loopy/loopy/check.py", line 1308, in pre_schedule_checks
    check_for_integer_subscript_indices(t_unit)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/home/kaushikggg/projects/loopy/loopy/check.py", line 377, in check_for_integer_subscript_indices
    _check_for_integer_subscript_indices_inner(clbl.subkernel,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
                                               t_unit.callables_table)
                                               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kaushikggg/projects/loopy/loopy/check.py", line 361, in _check_for_integer_subscript_indices_inner
    [idx_int_checker(assignee) for assignee in insn.assignees if
     ~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/home/kaushikggg/projects/loopy/loopy/type_inference.py", line 281, in __call__
    super().__call__(expr, **kwargs))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/home/kaushikggg/.miniforge3/envs/py314_env/lib/python3.14/site-packages/pymbolic/mapper/__init__.py", line 483, in __call__
    result = method(expr, *args, **kwargs)
  File "/home/kaushikggg/projects/loopy/loopy/check.py", line 340, in map_subscript
    raise LoopyError(
        f"Non-integral array indices obtained in {expr}")
loopy.diagnostic.LoopyError: Non-integral array indices obtained in a[map[i] // 2]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions