Skip to content

Commit 633c1d2

Browse files
authored
Merge branch 'main' into use-zstd-layers
2 parents 40e4a84 + 5fad63e commit 633c1d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1019
-190
lines changed

.github/workflows/config/validation_config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"operating_systems":
77
[
88
"ubuntu:22.04",
9-
"redhat/ubi8:8.10",
109
"fedora:42"
1110
]
1211
},

include/cudaq/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88

99
include(HandleLLVMOptions)
1010
add_subdirectory(Optimizer)
11+
add_subdirectory(Support)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# ============================================================================ #
2+
# Copyright (c) 2022 - 2025 NVIDIA Corporation & Affiliates. #
3+
# All rights reserved. #
4+
# #
5+
# This source code and the accompanying materials are made available under #
6+
# the terms of the Apache License 2.0 which accompanies this distribution. #
7+
# ============================================================================ #
8+
9+
# Install TargetConfig.h file
10+
install (FILES TargetConfig.h DESTINATION include/cudaq/Support)

include/cudaq/Support/TargetConfig.h

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#pragma once
1010

11-
#include "llvm/Support/YAMLTraits.h"
1211
#include <optional>
1312
#include <string>
1413
#include <vector>
@@ -142,56 +141,3 @@ std::string processRuntimeArgs(const TargetConfig &config,
142141
const std::vector<std::string> &targetArgv);
143142
} // namespace config
144143
} // namespace cudaq
145-
146-
// These structs can be used in a vector.
147-
LLVM_YAML_IS_SEQUENCE_VECTOR(cudaq::config::TargetFeatureFlag)
148-
LLVM_YAML_IS_SEQUENCE_VECTOR(cudaq::config::TargetArgument)
149-
LLVM_YAML_IS_SEQUENCE_VECTOR(cudaq::config::ConditionalBuildConfig)
150-
LLVM_YAML_IS_SEQUENCE_VECTOR(cudaq::config::BackendFeatureMap)
151-
152-
namespace llvm {
153-
namespace yaml {
154-
// YML serialization declarations.
155-
template <>
156-
struct ScalarBitSetTraits<cudaq::config::TargetFeatureFlag> {
157-
static void bitset(IO &io, cudaq::config::TargetFeatureFlag &value);
158-
};
159-
160-
template <>
161-
struct ScalarEnumerationTraits<cudaq::config::ArgumentType> {
162-
static void enumeration(IO &io, cudaq::config::ArgumentType &value);
163-
};
164-
165-
template <>
166-
struct MappingTraits<cudaq::config::TargetArgument> {
167-
static void mapping(IO &io, cudaq::config::TargetArgument &info);
168-
};
169-
170-
template <>
171-
struct BlockScalarTraits<cudaq::config::SimulationBackendSetting> {
172-
static void output(const cudaq::config::SimulationBackendSetting &Value,
173-
void *Ctxt, llvm::raw_ostream &OS);
174-
static StringRef input(StringRef Scalar, void *Ctxt,
175-
cudaq::config::SimulationBackendSetting &Value);
176-
};
177-
template <>
178-
struct MappingTraits<cudaq::config::ConditionalBuildConfig> {
179-
static void mapping(IO &io, cudaq::config::ConditionalBuildConfig &info);
180-
};
181-
182-
template <>
183-
struct MappingTraits<cudaq::config::BackendEndConfigEntry> {
184-
static void mapping(IO &io, cudaq::config::BackendEndConfigEntry &info);
185-
};
186-
template <>
187-
struct MappingTraits<cudaq::config::BackendFeatureMap> {
188-
static void mapping(IO &io, cudaq::config::BackendFeatureMap &info);
189-
};
190-
191-
template <>
192-
struct MappingTraits<cudaq::config::TargetConfig> {
193-
static void mapping(IO &io, cudaq::config::TargetConfig &info);
194-
};
195-
196-
} // namespace yaml
197-
} // namespace llvm
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/****************************************************************-*- C++ -*-****
2+
* Copyright (c) 2022 - 2025 NVIDIA Corporation & Affiliates. *
3+
* All rights reserved. *
4+
* *
5+
* This source code and the accompanying materials are made available under *
6+
* the terms of the Apache License 2.0 which accompanies this distribution. *
7+
******************************************************************************/
8+
9+
#pragma once
10+
11+
#include "TargetConfig.h"
12+
#include "llvm/Support/YAMLTraits.h"
13+
14+
// These structs can be used in a vector.
15+
LLVM_YAML_IS_SEQUENCE_VECTOR(cudaq::config::TargetFeatureFlag)
16+
LLVM_YAML_IS_SEQUENCE_VECTOR(cudaq::config::TargetArgument)
17+
LLVM_YAML_IS_SEQUENCE_VECTOR(cudaq::config::ConditionalBuildConfig)
18+
LLVM_YAML_IS_SEQUENCE_VECTOR(cudaq::config::BackendFeatureMap)
19+
20+
namespace llvm {
21+
namespace yaml {
22+
// YML serialization declarations.
23+
template <>
24+
struct ScalarBitSetTraits<cudaq::config::TargetFeatureFlag> {
25+
static void bitset(IO &io, cudaq::config::TargetFeatureFlag &value);
26+
};
27+
28+
template <>
29+
struct ScalarEnumerationTraits<cudaq::config::ArgumentType> {
30+
static void enumeration(IO &io, cudaq::config::ArgumentType &value);
31+
};
32+
33+
template <>
34+
struct MappingTraits<cudaq::config::TargetArgument> {
35+
static void mapping(IO &io, cudaq::config::TargetArgument &info);
36+
};
37+
38+
template <>
39+
struct BlockScalarTraits<cudaq::config::SimulationBackendSetting> {
40+
static void output(const cudaq::config::SimulationBackendSetting &Value,
41+
void *Ctxt, llvm::raw_ostream &OS);
42+
static StringRef input(StringRef Scalar, void *Ctxt,
43+
cudaq::config::SimulationBackendSetting &Value);
44+
};
45+
template <>
46+
struct MappingTraits<cudaq::config::ConditionalBuildConfig> {
47+
static void mapping(IO &io, cudaq::config::ConditionalBuildConfig &info);
48+
};
49+
50+
template <>
51+
struct MappingTraits<cudaq::config::BackendEndConfigEntry> {
52+
static void mapping(IO &io, cudaq::config::BackendEndConfigEntry &info);
53+
};
54+
template <>
55+
struct MappingTraits<cudaq::config::BackendFeatureMap> {
56+
static void mapping(IO &io, cudaq::config::BackendFeatureMap &info);
57+
};
58+
59+
template <>
60+
struct MappingTraits<cudaq::config::TargetConfig> {
61+
static void mapping(IO &io, cudaq::config::TargetConfig &info);
62+
};
63+
64+
} // namespace yaml
65+
} // namespace llvm

lib/Optimizer/Builder/Marshal.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,8 @@ cudaq::opt::marshal::dropAnyHiddenArguments(MutableArrayRef<BlockArgument> args,
785785
std::pair<bool, func::FuncOp> cudaq::opt::marshal::lookupHostEntryPointFunc(
786786
StringRef mangledEntryPointName, ModuleOp module, func::FuncOp funcOp) {
787787
if (mangledEntryPointName == "BuilderKernel.EntryPoint" ||
788-
mangledEntryPointName.contains("_PyKernelEntryPointRewrite")) {
788+
mangledEntryPointName.contains("_PyKernelEntryPointRewrite") ||
789+
funcOp.empty()) {
789790
// No host entry point needed.
790791
return {false, func::FuncOp{}};
791792
}

lib/Optimizer/Transforms/GenKernelExecution.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -869,14 +869,13 @@ class GenerateKernelExecution
869869
for (auto &op : *module.getBody())
870870
if (auto funcOp = dyn_cast<func::FuncOp>(op))
871871
if (funcOp.getName().startswith(cudaq::runtime::cudaqGenPrefixName) &&
872-
cudaq::opt::marshal::hasLegalType(funcOp.getFunctionType()))
872+
cudaq::opt::marshal::hasLegalType(funcOp.getFunctionType()) &&
873+
!funcOp.empty() && !funcOp->hasAttr(cudaq::generatorAnnotation))
873874
workList.push_back(funcOp);
874875

875876
LLVM_DEBUG(llvm::dbgs()
876877
<< workList.size() << " kernel entry functions to process\n");
877878
for (auto funcOp : workList) {
878-
if (funcOp->hasAttr(cudaq::generatorAnnotation))
879-
continue;
880879
auto loc = funcOp.getLoc();
881880
[[maybe_unused]] auto className =
882881
funcOp.getName().drop_front(cudaq::runtime::cudaqGenPrefixLength);

lib/Optimizer/Transforms/LoopAnalysis.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ using namespace mlir;
3030
/// A \em monotonic loop: a loop that counts from $i$ up to (down to) $j$
3131
/// stepping by positive (negative) integral values; mathematically, it is a
3232
/// strictly monotonic sequence. If the step is a compile-time constant, $k$,
33-
/// then a closed iterval monotonic loop must execute exactly $\max(0, \floor{(j
34-
/// - i + k) / k})$ iterations. By normalizing a monotonic loop and constant
35-
/// folding and propagation, we may be able to convert it to static control
36-
/// flow.
33+
/// then a closed iterval definite monotonic loop must execute exactly $\max(0,
34+
/// \floor{(j - i + k) / k})$ iterations. By normalizing a monotonic loop and
35+
/// constant folding and propagation, we may be able to convert it to static
36+
/// control flow.
3737
///
3838
/// For completeness, a \em{conditionally iterated} loop is a monotonic loop
3939
/// that has a second auxilliary condition to determine if a given loop
@@ -309,10 +309,9 @@ bool opt::isaCountedLoop(cc::LoopOp loop, bool allowClosedInterval) {
309309
isaConstant(c.compareValue);
310310
}
311311

312-
bool opt::isaConstantUpperBoundLoop(cc::LoopOp loop, bool allowClosedInterval) {
312+
bool opt::isaIndefiniteCountedLoop(cc::LoopOp loop, bool allowClosedInterval) {
313313
LoopComponents c;
314-
return isaInvariantLoop(loop, allowClosedInterval, /*allowEarlyExit=*/true,
315-
&c) &&
314+
return isaIndefiniteInvariantLoop(loop, allowClosedInterval, &c) &&
316315
isaConstant(c.compareValue);
317316
}
318317

lib/Optimizer/Transforms/LoopAnalysis.h

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ bool isSignedPredicate(mlir::arith::CmpIPredicate p);
7474
bool isaCountedLoop(cc::LoopOp op, bool allowClosedInterval = true);
7575

7676
bool loopContainsBreak(cc::LoopOp op);
77-
bool isaConstantUpperBoundLoop(cc::LoopOp op, bool allowClosedInterval = true);
77+
78+
/// An indefinite counted loop is a counted loop which may have early exits.
79+
bool isaIndefiniteCountedLoop(cc::LoopOp op, bool allowClosedInterval = true);
7880

7981
/// An invariant loop is defined to be a loop that will execute some run-time
8082
/// invariant number of iterations. We recognize a normalized, semi-open
@@ -88,6 +90,23 @@ bool isaInvariantLoop(cc::LoopOp op, bool allowClosedInterval = true,
8890
bool allowEarlyExit = false, LoopComponents *c = nullptr);
8991
bool isaInvariantLoop(const LoopComponents &c, bool allowClosedInterval);
9092

93+
/// An indefinite invariant loop is an invariant loop which may have early
94+
/// exits. The number of iterations will be at most the upper bound expression.
95+
/// We recognize the normalized, semi-open interval loop such as
96+
/// ```
97+
/// for(i = 0; i < invariant_expression; ++i) {
98+
/// ...
99+
/// break;
100+
/// ...
101+
/// }
102+
/// ```
103+
/// is a canonical indefinite loop.
104+
inline bool isaIndefiniteInvariantLoop(cc::LoopOp op,
105+
bool allowClosedInterval = true,
106+
LoopComponents *c = nullptr) {
107+
return isaInvariantLoop(op, allowClosedInterval, /*allowEarlyExit=*/true, c);
108+
}
109+
91110
// We expect the loop control value to have the following form.
92111
//
93112
// %final = cc.loop while ((%iter = %initial) -> (iN)) {
@@ -118,8 +137,9 @@ bool hasMonotonicControlInduction(cc::LoopOp loop, LoopComponents *c = nullptr);
118137
/// ```
119138
/// for(i = start; i < stop; i += step)
120139
/// ```
121-
/// is a monotonic loop that must execute a number of iterations as given
122-
/// by the following equation. Early exits (break statements) are not permitted.
140+
/// is a (definite) monotonic loop that must execute a number of iterations as
141+
/// given by the following equation. Early exits (break statements) are
142+
/// permitted in \e indefinite monotonic loops.
123143
/// ```
124144
/// let iterations = (stop - 1 - start + step) / step
125145
/// iterations : if iterations > 0
@@ -130,6 +150,12 @@ bool hasMonotonicControlInduction(cc::LoopOp loop, LoopComponents *c = nullptr);
130150
bool isaMonotonicLoop(mlir::Operation *op, bool allowEarlyExit = false,
131151
LoopComponents *c = nullptr);
132152

153+
/// An indefinite monotonic loop is a monotonic loop that may have early exits.
154+
inline bool isaIndefiniteMonotonicLoop(mlir::Operation *op,
155+
LoopComponents *c = nullptr) {
156+
return isaMonotonicLoop(op, /*allowEarlyExit=*/true, c);
157+
}
158+
133159
/// Recover the different subexpressions from the loop if it conforms to the
134160
/// pattern. Given a LoopOp where induction is in a register:
135161
/// ```

lib/Optimizer/Transforms/LoopUnrollPatterns.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct UnrollCountedLoop : public OpRewritePattern<cudaq::cc::LoopOp> {
7272
loop.emitOpError("not a simple counted loop");
7373
return failure();
7474
}
75-
if (allowBreak && !cudaq::opt::isaConstantUpperBoundLoop(loop)) {
75+
if (allowBreak && !cudaq::opt::isaIndefiniteCountedLoop(loop)) {
7676
if (signalFailure)
7777
loop.emitOpError("not a constant upper bound loop");
7878
return failure();

0 commit comments

Comments
 (0)