diff --git a/loopy/codegen/instruction.py b/loopy/codegen/instruction.py index 8e8eb86a1459cd3e2052babe74d1d1016ad81beb..371979d97448f72e3832a626dc2944f1f52a15b9 100644 --- a/loopy/codegen/instruction.py +++ b/loopy/codegen/instruction.py @@ -297,7 +297,7 @@ def generate_c_instruction_code(codegen_state, insn): def generate_nop_instruction_code(codegen_state, insn): if codegen_state.vectorization_info is not None: raise UnvectorizableError("C instructions cannot be vectorized") - return codegen_state.ast_builder.emit_comment( + return codegen_state.ast_builder.emit_noop_with_comment( "no-op (insn=%s)" % (insn.id)) # vim: foldmethod=marker diff --git a/loopy/target/__init__.py b/loopy/target/__init__.py index 5bb1043b9441c31d9592659df6f14ff3e0435545..54a0729da723235277960dc2bb894abd792e10c9 100644 --- a/loopy/target/__init__.py +++ b/loopy/target/__init__.py @@ -271,6 +271,9 @@ class ASTBuilderBase(Generic[ASTType]): def emit_comment(self, s): raise NotImplementedError() + def emit_noop_with_comment(self, s): + raise NotImplementedError() + # }}} def process_ast(self, node): diff --git a/loopy/target/c/__init__.py b/loopy/target/c/__init__.py index 426d87fe58dc65752bc45a23cb2fb7755dd2bdfb..d8475cdb198390b1a842e378b3f5b486a21a58ba 100644 --- a/loopy/target/c/__init__.py +++ b/loopy/target/c/__init__.py @@ -1263,6 +1263,10 @@ class CFamilyASTBuilder(ASTBuilderBase[Generable]): from cgen import Comment return Comment(s) + def emit_noop_with_comment(self, s): + from cgen import Line + return Line(f"; /*{s}*/") + @property def can_implement_conditionals(self): return True diff --git a/loopy/target/python.py b/loopy/target/python.py index b50ddaf8eb2794ec9dbd1d65a7cbeae37ac7286a..f9cc06147df4c8d657474df5737bc564bd83b219 100644 --- a/loopy/target/python.py +++ b/loopy/target/python.py @@ -253,6 +253,10 @@ class PythonASTBuilderBase(ASTBuilderBase[Generable]): from genpy import Comment return Comment(s) + def emit_noop_with_comment(self, s): + from cgen import Line + return Line(f"pass #{s}") + @property def can_implement_conditionals(self): return True diff --git a/test/test_target.py b/test/test_target.py index 2115d60ccd89ac8b7393ae7958c9faee3304e71a..389c865b6b92cb2f6528553909865861d79e8358 100644 --- a/test/test_target.py +++ b/test/test_target.py @@ -29,6 +29,7 @@ import pyopencl.clmath import pyopencl.clrandom import pyopencl.tools import pytest +import pymbolic.primitives as prim from loopy.target.c import CTarget from loopy.target.opencl import OpenCLTarget @@ -704,6 +705,16 @@ def test_empty_array_stride_check(ctx_factory): einsum(cq, a=np.random.randn(3, 2, 5).copy(order="F"), x=np.random.randn(5)) +def test_no_op_with_predicate(ctx_factory): + ctx = ctx_factory() + + predicate = prim.Comparison(prim.Variable("a"), ">", 0) + knl = lp.make_kernel([], + ["<> a = 1", lp.NoOpInstruction(predicates=[predicate])]) + code = lp.generate_code_v2(knl).device_code() + cl.Program(ctx, code).build() + + def test_empty_array_stride_check_fortran(ctx_factory): # https://github.com/inducer/loopy/issues/583 ctx = ctx_factory()