NVIDIA/cuda-quantum

nvq++ bridge compilation issue with `std::vector<bool>` argument

Closed this issue · 0 comments

Required prerequisites

  • Consult the security policy. If reporting a security vulnerability, do not report the bug using this form. Use the process described in the policy to report the issue.
  • Make sure you've read the documentation. Your issue may be addressed there.
  • Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.
  • If possible, make a PR with a failing test to give us a starting point to work on!

Describe the bug

Compilation error: 'cc.if' op operand #0 must be 1-bit signless integer, but got '!cc.ptr<i1>' when dereferencing a std::vector<bool> argument in MLIR mode.

Steps to reproduce the bug

#include <cudaq.h>

void f(const std::vector<bool>& k) __qpu__ {
  cudaq::qubit q;
  for (int i = 0; i < k.size(); ++i)
    if (k[i])
        x(q);
}

int main() {
  std::vector<bool> x { true, false};  
  auto counts = cudaq::sample(f, x);
  counts.dump();
  return 0;
}

The above example works in library mode but fails in MLIR mode:

error: 'cc.if' op operand #0 must be 1-bit signless integer, but got '!cc.ptr<i1>'
"builtin.module"() ({
  "func.func"() ({
  ^bb0(%arg0: !cc.stdvec<i1>):
    %0 = "quake.alloca"() : () -> !quake.ref
    "cc.scope"() ({
      %1 = "arith.constant"() {value = 0 : i32} : () -> i32
      %2 = "cc.alloca"() {elementType = i32} : () -> !cc.ptr<i32>
      "cc.store"(%1, %2) : (i32, !cc.ptr<i32>) -> ()
      "cc.loop"() ({
        %3 = "cc.load"(%2) : (!cc.ptr<i32>) -> i32
        %4 = "arith.extsi"(%3) : (i32) -> i64
        %5 = "cc.stdvec_size"(%arg0) : (!cc.stdvec<i1>) -> i64
        %6 = "arith.cmpi"(%4, %5) {predicate = 6 : i64} : (i64, i64) -> i1
        "cc.condition"(%6) : (i1) -> ()
      }, {
        %3 = "func.constant"() {value = @_ZNKSt6vectorIbSaIbEEixEm} : () -> ((i64) -> i1)
        %4 = "cc.load"(%2) : (!cc.ptr<i32>) -> i32
        %5 = "arith.extsi"(%4) : (i32) -> i64
        %6 = "cc.stdvec_data"(%arg0) : (!cc.stdvec<i1>) -> !cc.ptr<i1>
        %7 = "cc.compute_ptr"(%6, %5) {rawConstantIndices = array<i32: -2147483648>} : (!cc.ptr<i1>, i64) -> !cc.ptr<i1>
        "cc.if"(%7) ({
          %8 = "func.constant"() {value = @_ZN5cudaq1xINS_4baseEJNS_5quditILm2EEEEEEvDpRT0_} : () -> ((!quake.ref) -> ())
          "quake.x"(%0) {operand_segment_sizes = array<i32: 0, 0, 1>} : (!quake.ref) -> ()
          "cc.continue"() : () -> ()
        }, {
        }) : (!cc.ptr<i1>) -> ()
        "cc.continue"() : () -> ()
      }, {
        %3 = "cc.load"(%2) : (!cc.ptr<i32>) -> i32
        %4 = "arith.constant"() {value = 1 : i32} : () -> i32
        %5 = "arith.addi"(%3, %4) : (i32, i32) -> i32
        "cc.store"(%5, %2) : (i32, !cc.ptr<i32>) -> ()
        "cc.continue"() : () -> ()
      }) {post_condition = false} : () -> ()
      "cc.continue"() : () -> ()
    }) : () -> ()
    "func.return"() : () -> ()
  }) {"cudaq-entrypoint", "cudaq-kernel", function_type = (!cc.stdvec<i1>) -> (), no_this, sym_name = "__nvqpp__mlirgen__function_f._Z1fRKSt6vectorIbSaIbEE"} : () -> ()
  "func.func"() ({
  }) {function_type = (i64) -> i1, sym_name = "_ZNKSt6vectorIbSaIbEEixEm", sym_visibility = "private"} : () -> ()
  "func.func"() ({
  }) {function_type = (!quake.ref) -> (), sym_name = "_ZN5cudaq1xINS_4baseEJNS_5quditILm2EEEEEEvDpRT0_", sym_visibility = "private"} : () -> ()
  "func.func"() ({
  ^bb0(%arg0: !cc.ptr<!cc.struct<{!cc.ptr<i1>, !cc.ptr<i1>, !cc.ptr<i1>}>>):
    "func.return"() : () -> ()
  }) {function_type = (!cc.ptr<!cc.struct<{!cc.ptr<i1>, !cc.ptr<i1>, !cc.ptr<i1>}>>) -> (), no_this, sym_name = "_Z1fRKSt6vectorIbSaIbEE"} : () -> ()
}) {llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", llvm.triple = "x86_64-unknown-linux-gnu", quake.mangled_name_map = {__nvqpp__mlirgen__function_f._Z1fRKSt6vectorIbSaIbEE = "_Z1fRKSt6vectorIbSaIbEE"}} : () -> ()
Passes failed!

Expected behavior

No compile errors.

Is this a regression? If it is, put the last known working version (or commit) here.

Not a regression

Environment

  • CUDA Quantum version: main
  • Python version: 3.10
  • C++ compiler: gcc-12
  • Operating system: Ubuntu 22.04

Suggestions

No response