Skip to content

MLIR registration multiple times at runtime with mulithreading #2761

New issue

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

Open
4 tasks done
anthony-santana opened this issue Mar 26, 2025 · 0 comments · May be fixed by #2762
Open
4 tasks done

MLIR registration multiple times at runtime with mulithreading #2761

anthony-santana opened this issue Mar 26, 2025 · 0 comments · May be fixed by #2762

Comments

@anthony-santana
Copy link
Collaborator

anthony-santana commented Mar 26, 2025

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

When trying to create many kernels in parallel, we accidentally try to register our MLIR dialect multiple times at runtime.

Steps to reproduce the bug

auto build_kernel() {
  auto kernel = cudaq::make_kernel();
  auto q = kernel.qalloc();
  kernel.x(q);
  return kernel;
}

TEST(testRepro, minimalRepro) {
#pragma omp parallel
  for (size_t idx = 0; idx < 10; ++idx) {
      auto kernel = build_kernel();
      auto result = cudaq::sample(kernel);
      auto now = std::chrono::system_clock::now();
      std::time_t time = std::chrono::system_clock::to_time_t(now);
      std::cout << std::ctime(&time);
  }

}

test: /home/.llvm-project/mlir/lib/Pass/PassRegistry.cpp:102: void mlir::registerPassPipeline(llvm::StringRef, llvm::StringRef, const PassRegistryFunction&, std::function<void(llvm::function_ref<void(const mlir::detail::PassOptions&)>)>): Assertion `inserted && "Pass pipeline registered multiple times"' failed.

Expected behavior

We'd expect output like the following, which indicates all kernels were processed and executed in parallel

Wed Mar 26 19:20:46 2025
module {
  func.func @__nvqpp__mlirgen____nvqppBuilderKernel_367535629127() attributes {"cudaq-entrypoint", "cudaq-kernel"} {
    %0 = quake.alloca !quake.ref
    quake.x %0 : (!quake.ref) -> ()
    return
  }
}

Wed Mar 26 19:20:46 2025
module {
  func.func @__nvqpp__mlirgen____nvqppBuilderKernel_093606261879() attributes {"cudaq-entrypoint", "cudaq-kernel"} {
    %0 = quake.alloca !quake.ref
    quake.x %0 : (!quake.ref) -> ()
    return
  }
}

Wed Mar 26 19:20:46 2025
module {
  func.func @__nvqpp__mlirgen____nvqppBuilderKernel_202375922897() attributes {"cudaq-entrypoint", "cudaq-kernel"} {
    %0 = quake.alloca !quake.ref
    quake.x %0 : (!quake.ref) -> ()
    return
  }
}

Wed Mar 26 19:20:47 2025
module {
  func.func @__nvqpp__mlirgen____nvqppBuilderKernel_361293194784() attributes {"cudaq-entrypoint", "cudaq-kernel"} {
    %0 = quake.alloca !quake.ref
    quake.x %0 : (!quake.ref) -> ()
    return
  }
}

Wed Mar 26 19:20:47 2025
module {
  func.func @__nvqpp__mlirgen____nvqppBuilderKernel_503610632061() attributes {"cudaq-entrypoint", "cudaq-kernel"} {
    %0 = quake.alloca !quake.ref
    quake.x %0 : (!quake.ref) -> ()
    return
  }
}

Wed Mar 26 19:20:47 2025
module {
  func.func @__nvqpp__mlirgen____nvqppBuilderKernel_554765693745() attributes {"cudaq-entrypoint", "cudaq-kernel"} {
    %0 = quake.alloca !quake.ref
    quake.x %0 : (!quake.ref) -> ()
    return
  }
}

Wed Mar 26 19:20:47 2025
module {
  func.func @__nvqpp__mlirgen____nvqppBuilderKernel_254744307868() attributes {"cudaq-entrypoint", "cudaq-kernel"} {
    %0 = quake.alloca !quake.ref
    quake.x %0 : (!quake.ref) -> ()
    return
  }
}

Wed Mar 26 19:20:47 2025
module {
  func.func @__nvqpp__mlirgen____nvqppBuilderKernel_843149206892() attributes {"cudaq-entrypoint", "cudaq-kernel"} {
    %0 = quake.alloca !quake.ref
    quake.x %0 : (!quake.ref) -> ()
    return
  }
}

Wed Mar 26 19:20:47 2025
module {
  func.func @__nvqpp__mlirgen____nvqppBuilderKernel_664950487172() attributes {"cudaq-entrypoint", "cudaq-kernel"} {
    %0 = quake.alloca !quake.ref
    quake.x %0 : (!quake.ref) -> ()
    return
  }
}

Wed Mar 26 19:20:47 2025
module {
  func.func @__nvqpp__mlirgen____nvqppBuilderKernel_722610615949() attributes {"cudaq-entrypoint", "cudaq-kernel"} {
    %0 = quake.alloca !quake.ref
    quake.x %0 : (!quake.ref) -> ()
    return
  }
}

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

Not a regression

Environment

  • CUDA-Q version: Latest
  • Python version:
  • C++ compiler:
  • Operating system:

Suggestions

No response

@anthony-santana anthony-santana linked a pull request Mar 26, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant