Skip to content
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

[nvq++] Removes MLIR's memref dialect. #2438

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/cudaq/Frontend/nvqpp/ASTBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "clang/Frontend/FrontendAction.h"
#include "clang/Rewrite/Core/Rewriter.h"
#include "llvm/ADT/ScopedHashTable.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
#include "mlir/IR/Builders.h"
Expand Down
6 changes: 0 additions & 6 deletions include/cudaq/Optimizer/InitAllDialects.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@

#include "cudaq/Optimizer/Dialect/CC/CCDialect.h"
#include "cudaq/Optimizer/Dialect/Quake/QuakeDialect.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Complex/IR/Complex.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/Math/IR/Math.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/SCF/IR/SCF.h"

namespace cudaq {

Expand All @@ -27,15 +24,12 @@ inline void registerAllDialects(mlir::DialectRegistry &registry) {
// clang-format off
registry.insert<
// MLIR dialects
mlir::AffineDialect,
mlir::arith::ArithDialect,
mlir::cf::ControlFlowDialect,
mlir::complex::ComplexDialect,
mlir::func::FuncDialect,
mlir::LLVM::LLVMDialect,
mlir::math::MathDialect,
mlir::memref::MemRefDialect,
mlir::scf::SCFDialect,

// NVQ++ dialects
cudaq::cc::CCDialect,
Expand Down
1 change: 0 additions & 1 deletion include/cudaq/Optimizer/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ std::unique_ptr<mlir::Pass>
createQuakeSynthesizer(std::string_view, const void *,
std::size_t startingArgIdx = 0,
bool sameAddressSpace = false);
std::unique_ptr<mlir::Pass> createRaiseToAffinePass();
std::unique_ptr<mlir::Pass> createUnwindLoweringPass();

std::unique_ptr<mlir::Pass>
Expand Down
1 change: 0 additions & 1 deletion lib/Frontend/nvqpp/ConvertExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "cudaq/Optimizer/Dialect/CC/CCOps.h"
#include "cudaq/Optimizer/Dialect/Quake/QuakeOps.h"
#include "llvm/Support/Debug.h"
#include "mlir/Dialect/SCF/IR/SCF.h"

#define DEBUG_TYPE "lower-ast-expr"

Expand Down
2 changes: 0 additions & 2 deletions lib/Optimizer/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ add_cudaq_library(OptCodeGen
MLIRTransforms

# Conversions
MLIRAffineToStandard
MLIRArithToLLVM
MLIRComplexToLibm
MLIRComplexToLLVM
MLIRControlFlowToLLVM
MLIRFuncToLLVM
MLIRMathToFuncs
MLIRMathToLLVM
MLIRSCFToControlFlow

# Translation
MLIRTargetLLVMIRExport
Expand Down
2 changes: 0 additions & 2 deletions lib/Optimizer/CodeGen/ConvertCCToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "mlir/Conversion/LLVMCommon/Pattern.h"
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
#include "mlir/Conversion/MathToLLVM/MathToLLVM.h"
#include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h"
#include "mlir/Dialect/Arith/Transforms/Passes.h"
#include "mlir/Target/LLVMIR/TypeToLLVM.h"

Expand Down Expand Up @@ -121,7 +120,6 @@ struct CCToLLVM : public cudaq::opt::impl::CCToLLVMBase<CCToLLVM> {
arith::populateArithToLLVMConversionPatterns(ccTypeConverter, patterns);
populateMathToLLVMConversionPatterns(ccTypeConverter, patterns);

populateSCFToControlFlowConversionPatterns(patterns);
cf::populateControlFlowToLLVMConversionPatterns(ccTypeConverter, patterns);
populateFuncToLLVMConversionPatterns(ccTypeConverter, patterns);
cudaq::opt::populateCCToLLVMPatterns(ccTypeConverter, patterns);
Expand Down
4 changes: 0 additions & 4 deletions lib/Optimizer/CodeGen/ConvertToQIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/FormatVariadic.h"
#include "mlir/Conversion/AffineToStandard/AffineToStandard.h"
#include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
#include "mlir/Conversion/ComplexToLLVM/ComplexToLLVM.h"
#include "mlir/Conversion/ComplexToLibm/ComplexToLibm.h"
Expand All @@ -30,7 +29,6 @@
#include "mlir/Conversion/LLVMCommon/Pattern.h"
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
#include "mlir/Conversion/MathToLLVM/MathToLLVM.h"
#include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h"
#include "mlir/Dialect/Arith/Transforms/Passes.h"
#include "mlir/Dialect/Complex/IR/Complex.h"
#include "mlir/Target/LLVMIR/ModuleTranslation.h"
Expand Down Expand Up @@ -167,12 +165,10 @@ class ConvertToQIR : public cudaq::opt::impl::ConvertToQIRBase<ConvertToQIR> {
populateComplexToLibmConversionPatterns(patterns, 1);
populateComplexToLLVMConversionPatterns(typeConverter, patterns);

populateAffineToStdConversionPatterns(patterns);
arith::populateCeilFloorDivExpandOpsPatterns(patterns);
arith::populateArithToLLVMConversionPatterns(typeConverter, patterns);
populateMathToLLVMConversionPatterns(typeConverter, patterns);

populateSCFToControlFlowConversionPatterns(patterns);
cf::populateControlFlowToLLVMConversionPatterns(typeConverter, patterns);
populateFuncToLLVMConversionPatterns(typeConverter, patterns);
cudaq::opt::populateCCToLLVMPatterns(typeConverter, patterns);
Expand Down
6 changes: 0 additions & 6 deletions lib/Optimizer/Transforms/ApplyOpSpecialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "cudaq/Optimizer/Transforms/Passes.h"
#include "cudaq/Todo.h"
#include "llvm/Support/Debug.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/IR/Dominance.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/Transforms/DialectConversion.h"
Expand Down Expand Up @@ -558,11 +557,6 @@ class ApplySpecializationPass
invert(newIfOp.getElseRegion());
continue;
}
if (auto forOp = dyn_cast<scf::ForOp>(op)) {
LLVM_DEBUG(llvm::dbgs() << "moving for: " << forOp << ".\n");
TODO_loc(loc, "cannot make adjoint of kernel with scf.for");
// should we convert to cc.loop and use code below?
}
if (auto loopOp = dyn_cast<cudaq::cc::LoopOp>(op)) {
LLVM_DEBUG(llvm::dbgs() << "moving loop: " << loopOp << ".\n");
auto newLoopOp = cloneReversedLoop(builder, loopOp);
Expand Down
1 change: 0 additions & 1 deletion lib/Optimizer/Transforms/PassDetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "cudaq/Optimizer/Dialect/CC/CCDialect.h"
#include "cudaq/Optimizer/Dialect/Quake/QuakeDialect.h"
#include "cudaq/Optimizer/Dialect/Quake/QuakeOps.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Complex/IR/Complex.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
Expand Down
1 change: 0 additions & 1 deletion lib/Optimizer/Transforms/QuakeAddMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "cudaq/Optimizer/Transforms/Passes.h"
#include "cudaq/Todo.h"
#include "llvm/Support/Debug.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
Expand Down
2 changes: 0 additions & 2 deletions runtime/cudaq/builder/kernel_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include "cudaq/Optimizer/Dialect/Quake/QuakeDialect.h"
#include "cudaq/Optimizer/Dialect/Quake/QuakeOps.h"
#include "cudaq/Optimizer/Transforms/Passes.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/Passes.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/Math/IR/Math.h"
#include "mlir/ExecutionEngine/ExecutionEngine.h"
Expand Down
65 changes: 20 additions & 45 deletions test/Quake/canonical-2.qke
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,29 @@

// RUN: cudaq-opt -canonicalize %s | FileCheck %s

func.func @__nvqpp__mlirgen__reflect_about_uniform(%arg0: !quake.veq<?>) attributes {"cudaq-kernel"} {
%0 = quake.veq_size %arg0 : (!quake.veq<?>) -> i64
%c1_i32 = arith.constant 1 : i32
%1 = arith.extsi %c1_i32 : i32 to i64
%2 = arith.subi %0, %1 : i64
%c0_i64 = arith.constant 0 : i64
%c1_i64 = arith.constant 1 : i64
%3 = arith.subi %2, %c1_i64 : i64
%4 = quake.subveq %arg0, %c0_i64, %3 : (!quake.veq<?>, i64, i64) -> !quake.veq<?>
%5 = quake.veq_size %arg0 : (!quake.veq<?>) -> i64
%c1_i64_0 = arith.constant 1 : i64
%6 = arith.subi %5, %c1_i64_0 : i64
%7 = quake.extract_ref %arg0[%6] : (!quake.veq<?>,i64) -> !quake.ref
%8 = cc.create_lambda {
cc.scope {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%10 = quake.veq_size %arg0 : (!quake.veq<?>) -> i64
%11 = arith.index_cast %10 : i64 to index
scf.for %arg1 = %c0 to %11 step %c1 {
%12 = quake.extract_ref %arg0[%arg1] : (!quake.veq<?>,index) -> !quake.ref
quake.h %12 : (!quake.ref) -> ()
}
}
} : !cc.callable<() -> ()>
%9 = cc.create_lambda {
cc.scope {
quake.z [%4] %7 : (!quake.veq<?>, !quake.ref) -> ()
}
} : !cc.callable<() -> ()>
quake.compute_action %8, %9 : !cc.callable<() -> ()>, !cc.callable<() -> ()>
return
}
func.func @canonicalize_scope(%arg0: !quake.ref) attributes {"cudaq-kernel"} {
%0 = cc.create_lambda {
cc.scope {
quake.h %arg0 : (!quake.ref) -> ()
}
} : !cc.callable<() -> ()>
%1 = cc.create_lambda {
cc.scope {
quake.z %arg0 : (!quake.ref) -> ()
}
} : !cc.callable<() -> ()>
quake.compute_action %0, %1 : !cc.callable<() -> ()>, !cc.callable<() -> ()>
return
}

// CHECK-LABEL: func.func @__nvqpp__mlirgen__reflect_about_uniform(
// CHECK: %[[VAL_12:.*]] = cc.create_lambda {
// CHECK-LABEL: func.func @canonicalize_scope(
// CHECK: %[[VAL_0:.*]] = cc.create_lambda {
// CHECK-NOT: cc.scope
// CHECK: %[[VAL_13:.*]] = quake.veq_size %{{.*}} : (!quake.veq<?>) -> i64
// CHECK: %[[VAL_14:.*]] = arith.index_cast %[[VAL_13]] : i64 to index
// CHECK: scf.for %[[VAL_15:.*]] = %{{.*}} to %[[VAL_14]] step %
// CHECK: %[[VAL_16:.*]] = quake.extract_ref
// CHECK: quake.h %[[VAL_16]]
// CHECK: }
// CHECK: quake.h %{{.*}} :
// CHECK: } : !cc.callable<() -> ()>
// CHECK: %[[VAL_17:.*]] = cc.create_lambda {
// CHECK: %[[VAL_1:.*]] = cc.create_lambda {
// CHECK-NOT: cc.scope
// CHECK: quake.z [%{{.*}}] %{{.*}} :
// CHECK: quake.z %{{.*}} :
// CHECK: } : !cc.callable<() -> ()>
// CHECK: quake.compute_action
// CHECK: return
// CHECK: quake.compute_action %[[VAL_0]], %[[VAL_1]]

52 changes: 0 additions & 52 deletions test/Quake/ccnot.qke

This file was deleted.

45 changes: 0 additions & 45 deletions test/Quake/ghz.qke

This file was deleted.

Loading
Loading