loopy icon indicating copy to clipboard operation
loopy copied to clipboard

Not able to infer ``HUGE_VAL`` for ``CudaTarget``

Open mitkotak opened this issue 1 year ago • 0 comments

Here's the MWE

import loopy as lp
import numpy as np
knl = lp.make_kernel(
        domains = "{ [_0]: 0<=_0<3000 }",
        instructions = "out = min(_0, a)",
        kernel_data = [lp.GlobalArg("out", shape=lp.auto, dtype="float64"),
            lp.GlobalArg("a", shape=lp.auto, dtype="float64")],
        target=lp.CudaTarget(),
        lang_version=(2018, 2))
print(knl)
lp.generate_code_v2(knl).device_code()

Here's the kernel

---------------------------------------------------------------------------
KERNEL: loopy_kernel
---------------------------------------------------------------------------
ARGUMENTS:
out: type: np:dtype('float64'), shape: () out aspace: global
a: type: np:dtype('float64'), shape: () in aspace: global
---------------------------------------------------------------------------
DOMAINS:
{ [_0] : 0 <= _0 <= 2999 }
---------------------------------------------------------------------------
INAME TAGS:
_0: None
---------------------------------------------------------------------------
INSTRUCTIONS:
out = reduce(min, [_0], a)  {id=insn}
---------------------------------------------------------------------------
===========================================================================
failing translation unit during pre-schedule check:
===========================================================================
---------------------------------------------------------------------------
KERNEL: loopy_kernel
---------------------------------------------------------------------------
ARGUMENTS:
out: type: np:dtype('float64'), shape: () out aspace: global
a: type: np:dtype('float64'), shape: () in aspace: global
---------------------------------------------------------------------------
DOMAINS:
{ [_0] : 0 <= _0 <= 2999 }
---------------------------------------------------------------------------
INAME TAGS:
_0: None
---------------------------------------------------------------------------
TEMPORARIES:
acc__0: type: np:dtype('float64'), shape: () aspace: private
---------------------------------------------------------------------------
INSTRUCTIONS:
↱  acc__0 = HUGE_VAL  {id=insn__0_init}
│  for _0
└↱   acc__0 = m̲i̲n(acc__0, a)  {id=insn__0_update}
 │ end _0
 └ out = acc__0  {id=insn}
---------------------------------------------------------------------------
===========================================================================

Here's the error trace

Traceback (most recent call last):
  File "/home/mitak2/env/lib/python3.10/site-packages/pymbolic/mapper/__init__.py", line 242, in __call__
    return self._cache[cache_key]
KeyError: (<class 'pymbolic.primitives.Variable'>, Variable('HUGE_VAL'), (), ())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mitak2/cudagraph_pytato/loopy_hugeval.py", line 11, in <module>
    lp.generate_code_v2(knl).device_code()
  File "/home/mitak2/env/lib/python3.10/site-packages/loopy/codegen/__init__.py", line 604, in generate_code_v2
    program = linearize(program)
  File "/home/mitak2/env/lib/python3.10/site-packages/loopy/schedule/__init__.py", line 2197, in linearize
    pre_schedule_checks(t_unit)
  File "/home/mitak2/env/lib/python3.10/site-packages/loopy/check.py", line 1234, in pre_schedule_checks
    check_for_integer_subscript_indices(t_unit)
  File "/home/mitak2/env/lib/python3.10/site-packages/loopy/check.py", line 341, in check_for_integer_subscript_indices
    _check_for_integer_subscript_indices_inner(clbl.subkernel,
  File "/home/mitak2/env/lib/python3.10/site-packages/loopy/check.py", line 322, in _check_for_integer_subscript_indices_inner
    idx_int_checker(insn.expression, return_tuple=isinstance(insn,
  File "/home/mitak2/env/lib/python3.10/site-packages/loopy/type_inference.py", line 208, in __call__
    result = super().__call__(
  File "/home/mitak2/env/lib/python3.10/site-packages/pymbolic/mapper/__init__.py", line 244, in __call__
    result = super().rec(expr, *args, **kwargs)
  File "/home/mitak2/env/lib/python3.10/site-packages/pymbolic/mapper/__init__.py", line 153, in __call__
    return method(expr, *args, **kwargs)
  File "/home/mitak2/env/lib/python3.10/site-packages/loopy/type_inference.py", line 674, in map_variable
    raise TypeInferenceFailure("name not known in type inference: %s"
loopy.diagnostic.TypeInferenceFailure: name not known in type inference: HUGE_VAL

mitkotak avatar Aug 06 '22 16:08 mitkotak