Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
da65160
Merge pull request #23 from keplertech/main
nanocoh Nov 27, 2025
ded48aa
Merge pull request #24 from keplertech/main
nanocoh Nov 29, 2025
73ee2de
yaml support
nanocoh Nov 29, 2025
8ba52c3
update testing
nanocoh Nov 29, 2025
5d3d957
update testing
nanocoh Nov 29, 2025
b3fcd18
yaml dep
nanocoh Nov 29, 2025
f27fe6e
spdlog dep
nanocoh Nov 29, 2025
12c5291
fix
nanocoh Nov 29, 2025
7b09ff1
fix
nanocoh Nov 29, 2025
cf00ac0
fix
nanocoh Nov 29, 2025
94c2e7f
fix
nanocoh Nov 29, 2025
daf8366
fix
nanocoh Nov 29, 2025
611bca8
fix
nanocoh Nov 29, 2025
28f4f77
fix
nanocoh Nov 29, 2025
eeee7d2
fix
nanocoh Nov 29, 2025
f590a8a
fix
nanocoh Nov 29, 2025
a6efcab
fix
nanocoh Nov 29, 2025
0374345
fix
nanocoh Nov 29, 2025
ec8a27d
fix
nanocoh Nov 29, 2025
9eb5809
fix
nanocoh Nov 29, 2025
29f304d
fix
nanocoh Nov 29, 2025
670f3ea
fix
nanocoh Nov 30, 2025
c707644
fix
nanocoh Nov 30, 2025
717078f
fix
nanocoh Nov 30, 2025
48a927e
fix
nanocoh Nov 30, 2025
ceaa20e
fix
nanocoh Nov 30, 2025
4c125b1
fix
nanocoh Nov 30, 2025
b1f97ce
fix
nanocoh Nov 30, 2025
8028637
test update
nanocoh Nov 30, 2025
301ddf6
update logs
nanocoh Nov 30, 2025
fe0dd45
Update README.md
nanocoh Nov 30, 2025
075dd2c
Update README with config file usage for kepler_formal
nanocoh Nov 30, 2025
b503974
Merge branch 'main' into verilog
nanocoh Nov 30, 2025
b04716a
Update README.md
nanocoh Nov 30, 2025
46a3b1c
Update regress.yml
nanocoh Nov 30, 2025
fe4a98e
regress update
nanocoh Nov 30, 2025
cb7dba3
regress update
nanocoh Nov 30, 2025
6b16bf1
wf update
nanocoh Nov 30, 2025
e5c7970
wf update
nanocoh Nov 30, 2025
bd78759
fix wf + const ref
nanocoh Nov 30, 2025
399526d
sync (#27)
nanocoh Nov 30, 2025
5c06eb7
ct
nanocoh Nov 30, 2025
7c0d0b9
Merge branch 'verilog' of https://github.com/keplertech/kepler-formal…
nanocoh Nov 30, 2025
fba276b
Merge branch 'main' into verilog
nanocoh Nov 30, 2025
d5108ae
sync (#29)
nanocoh Dec 5, 2025
b96bfcd
prints
nanocoh Dec 5, 2025
7899ca6
remove prints
nanocoh Dec 5, 2025
43ed29b
sync (#30)
nanocoh Dec 5, 2025
f7a0003
Merge pull request #31 from keplertech/main
nanocoh Dec 5, 2025
9153707
sync (#33)
nanocoh Dec 21, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
sudo apt-get install -yq \
build-essential cmake ninja-build clang pkg-config \
libboost-dev libfl-dev libtbb-dev capnproto libcapnp-dev \
libgtest-dev libspdlog-dev libfmt-dev
libgtest-dev libspdlog-dev libfmt-dev libboost-iostreams-dev zlib1g-dev

- name: Configure CMake
working-directory: ${{github.workspace}}/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: git submodule update --init --recursive
# install dependencies
- name: Install dependencies
run: brew install cmake doxygen capnp tbb bison flex boost spdlog
run: brew install cmake doxygen capnp tbb bison flex boost spdlog zlib
- name: set env variable
run: |
echo "/usr/local/opt/flex/bin" >> $GITHUB_PATH; echo "/usr/local/opt/bison/bin" >> $GITHUB_PATH;
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/regress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Checkout submodules
run: git submodule update --init --recursive
- name: Install boost & capnproto
run: sudo apt-get update && sudo apt-get install -y pkg-config libboost-dev libfl-dev capnproto libcapnp-dev ninja-build clang libtbb-dev libspdlog-dev
run: sudo apt-get update && sudo apt-get install -y pkg-config libboost-dev libfl-dev capnproto libcapnp-dev ninja-build clang libtbb-dev libspdlog-dev libboost-iostreams-dev zlib1g-dev

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja -DCMAKE_C_COMPILER=clang -DENABLE_SANITIZERS=ON -DPYTHON_INTERFACE=OFF -DCMAKE_CXX_STANDARD=20
Expand All @@ -51,7 +51,7 @@ jobs:
run: |
mkdir -p regress-output
# Run kepler-formal on the example files (files are in example/)
./build/src/bin/kepler_formal -naja_if \
./build/src/bin/kepler-formal -naja_if \
./example/tinyrocket_naja.if \
./example/tinyrocket_naja.if \
./example/NangateOpenCellLibrary_typical.lib \
Expand All @@ -63,7 +63,7 @@ jobs:
run: |
mkdir -p regress-output
# Run kepler-formal on the example files (files are in example/)
./build/src/bin/kepler_formal -verilog \
./build/src/bin/kepler-formal -verilog \
./example/tinyrocket.v \
./example/tinyrocket.v \
./example/NangateOpenCellLibrary_typical.lib \
Expand All @@ -82,14 +82,14 @@ jobs:
run: |
mkdir -p regress-output
# Run kepler-formal on the example files (files are in example/)
../build/src/bin/kepler_formal --config test_config_naja_if.yaml
../build/src/bin/kepler-formal --config test_config_naja_if.yaml

- name: Run on verilog edited
working-directory: ${{github.workspace}}/example
run: |
mkdir -p regress-output
# Run kepler-formal on the example files (files are in example/)
../build/src/bin/kepler_formal --config test_config_verilog.yaml
../build/src/bin/kepler-formal --config test_config_verilog.yaml



Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ cmake .. -DCMAKE_BUILD_TYPE=Release \

```bash
# Classic
"build/src/bin/kepler_formal <-verilog/-naja_if> <netlist1> <netlist2> [<liberty-file>...]"
"build/src/bin/kepler-formal <-verilog/-naja_if> <netlist1> <netlist2> [<liberty-file>...]"
# Through yaml config file
"build/src/bin/kepler_formal --config <yaml file>"
"build/src/bin/kepler-formal --config <yaml file>"
```

## Example
Expand Down
8 changes: 4 additions & 4 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ cd example
pip install najaeda
python edit.py
# For naja_if
../build/src/bin/kepler_formal -naja_if tinyrocket_naja.if tinyrocket_naja_edited.if NangateOpenCellLibrary_typical.lib fakeram45_1024x32.lib fakeram45_64x32.lib
../build/src/bin/kepler-formal -naja_if tinyrocket_naja.if tinyrocket_naja_edited.if NangateOpenCellLibrary_typical.lib fakeram45_1024x32.lib fakeram45_64x32.lib
# For verilog
../build/src/bin/kepler_formal -verilog tinyrocket_pre_edited.v tinyrocket_edited.v NangateOpenCellLibrary_typical.lib fakeram45_1024x32.lib /example/fakeram45_64x32.lib
../build/src/bin/kepler-formal -verilog tinyrocket_pre_edited.v tinyrocket_edited.v NangateOpenCellLibrary_typical.lib fakeram45_1024x32.lib /example/fakeram45_64x32.lib
# Through config file
../build/src/bin/kepler_formal --config test_config_naja_if.yaml
../build/src/bin/kepler_formal --config test_config_verilog.yaml
../build/src/bin/kepler-formal --config test_config_naja_if.yaml
../build/src/bin/kepler-formal --config test_config_verilog.yaml
```
10 changes: 5 additions & 5 deletions src/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2024-2025 keplertech.io
# SPDX-License-Identifier: GPL-3.0-only

add_executable(kepler_formal KeplerFormal.cpp)
target_include_directories(kepler_formal SYSTEM BEFORE PUBLIC ${Boost_INCLUDE_DIR})
target_include_directories(kepler_formal PUBLIC ${ARGPARSE_DIR})
add_executable(kepler-formal KeplerFormal.cpp)
target_include_directories(kepler-formal SYSTEM BEFORE PUBLIC ${Boost_INCLUDE_DIR})
target_include_directories(kepler-formal PUBLIC ${ARGPARSE_DIR})

target_link_libraries(kepler_formal
target_link_libraries(kepler-formal
PRIVATE
naja_snl_pyloader
naja_dnl
Expand All @@ -15,5 +15,5 @@ target_link_libraries(kepler_formal
${SPDLOG_TARGET}
)

install(TARGETS kepler_formal DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS kepler-formal DESTINATION ${CMAKE_INSTALL_BINDIR})

10 changes: 9 additions & 1 deletion src/bin/KeplerFormal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ int main(int argc, char** argv) {

// Check for config mode (--config or -c). If present, YAML takes precedence.
bool usedConfig = false;

std::string logFileName;

for (int i = 1; i < argc; ++i) {
std::string a = argv[i];
if (a == "--config" || a == "-c") {
Expand Down Expand Up @@ -94,6 +97,11 @@ int main(int argc, char** argv) {
logLevel = cfg["log_level"].as<std::string>();
}

// Add log file name
if (cfg["log_file"] && cfg["log_file"].IsScalar()) {
logFileName = cfg["log_file"].as<std::string>();
}

usedConfig = true;
} catch (const std::exception& e) {
SPDLOG_CRITICAL("Failed to parse config {}: {}", cfgPath, e.what());
Expand Down Expand Up @@ -253,7 +261,7 @@ int main(int argc, char** argv) {
// 4. Hand off to the rest of the editing/analysis workflow
// --------------------------------------------------------------------------
try {
KEPLER_FORMAL::MiterStrategy MiterS(top0, top1);
KEPLER_FORMAL::MiterStrategy MiterS(top0, top1, logFileName);
if (MiterS.run()) {
SPDLOG_INFO("No difference was found.");
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/strategies/miter/BuildPrimaryOutputClauses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void BuildPrimaryOutputClauses::collect() {
KeyT key{ path, std::move(ids) };
outputsMap_[std::move(key)] =
output;
printf("Output collected: %s\n", naja::DNL::get()
DEBUG_LOG("Output collected: %s\n", naja::DNL::get()
->getDNLTerminalFromID(output)
.getSnlBitTerm()
->getName()
Expand Down Expand Up @@ -395,7 +395,7 @@ void BuildPrimaryOutputClauses::build() {
tbb::task_arena arena(40);
auto processOutput = [&](size_t i) {
DNLID out = outputs_[i];
printf("Procssing output %zu/%zu: %s\n", ++processedOutputs,
DEBUG_LOG("Procssing output %zu/%zu: %s\n", ++processedOutputs,
outputs_.size(),
get()
->getDNLTerminalFromID(out)
Expand Down
74 changes: 72 additions & 2 deletions src/strategies/miter/MiterStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using namespace KEPLER_FORMAL;

SNLDesign* MiterStrategy::top0_ = nullptr;
SNLDesign* MiterStrategy::top1_ = nullptr;
std::string MiterStrategy::logFileName_ = "";
namespace {

static std::shared_ptr<spdlog::logger> logger;
Expand All @@ -45,6 +46,10 @@ void ensureLoggerInitialized() {
// already exist and then crete mitter_log_(x+1).txt
int logIndex = 0;
while (true) {
if (MiterStrategy::logFileName_ != "") {
logIndex = -1;
break;
}
std::string logFileName =
"miter_log_" + std::to_string(logIndex) + ".txt";
std::ifstream infile(logFileName);
Expand All @@ -56,6 +61,13 @@ void ensureLoggerInitialized() {
}
std::string logFileName =
"miter_log_" + std::to_string(logIndex) + ".txt";
if (MiterStrategy::logFileName_ != "") {
if (!MiterStrategy::logFileName_.empty()) {
std::filesystem::path p(MiterStrategy::logFileName_);
std::filesystem::create_directories(p.parent_path());
logFileName = p.string();
}
}
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(
logFileName, true);
logger = std::make_shared<spdlog::logger>("miter_logger", file_sink);
Expand Down Expand Up @@ -225,6 +237,13 @@ Glucose::Lit tseitinEncode(

} // namespace

MiterStrategy::MiterStrategy(naja::NL::SNLDesign* top0, naja::NL::SNLDesign* top1, const std::string& logFileName, const std::string& prefix)
: prefix_(prefix) {
top0_ = top0;
top1_ = top1;
logFileName_ = logFileName;
}

void MiterStrategy::normalizeInputs(
std::vector<naja::DNL::DNLID>& inputs0,
std::vector<naja::DNL::DNLID>& inputs1,
Expand Down Expand Up @@ -328,24 +347,38 @@ void MiterStrategy::normalizeOutputs(
for (const auto& [path0, output0] : outputs0Map) {
if (pathsCommon.find(path0) == pathsCommon.end()) {
diff0.push_back(output0);
std::string fullName;
for (const auto& name : path0.first) {
fullName += name.getString() + ".";
}
fullName += std::to_string(path0.second[0]) + ".";
fullName += std::to_string(path0.second[1]);
logger->info("Will ignore the analysis for: {} from netlist 0 as it does not exist in netlist 1", fullName);
}
}
std::vector<naja::DNL::DNLID> diff1;
for (const auto& [path1, output1] : outputs1Map) {
if (pathsCommon.find(path1) == pathsCommon.end()) {
std::string fullName;
for (const auto& name : path1.first) {
fullName += name.getString() + ".";
}
fullName += std::to_string(path1.second[0]) + ".";
fullName += std::to_string(path1.second[1]);
logger->info("Will ignore the analysis for: {} from netlist 1 as it does not exist in netlist 0", fullName);
diff1.push_back(output1);
}
}
outputs0.clear();
for (const auto& path : pathsCommon) {
outputs0.push_back(outputs0Map.at(path));
}
outputs0.insert(outputs0.end(), diff0.begin(), diff0.end());
//outputs0.insert(outputs0.end(), diff0.begin(), diff0.end());
outputs1.clear();
for (const auto& path : pathsCommon) {
outputs1.push_back(outputs1Map.at(path));
}
outputs1.insert(outputs1.end(), diff1.begin(), diff1.end());
//outputs1.insert(outputs1.end(), diff1.begin(), diff1.end());
logger->debug("size of common outputs: {}", pathsCommon.size());
logger->debug("size of diff0 outputs: {}", diff0.size());
logger->debug("size of diff1 outputs: {}", diff1.size());
Expand Down Expand Up @@ -484,6 +517,24 @@ bool MiterStrategy::run() {
for (size_t i = 0; i < POs0.size(); ++i) {
if (builder0.getOutputs2OutputsIDs().at(builder0.getDNLIDforOutput(i)) !=
builder1.getOutputs2OutputsIDs().at(builder1.getDNLIDforOutput(i))) {
auto path0 = builder0.getOutputs2OutputsIDs().at(builder0.getDNLIDforOutput(i));
auto path1 = builder1.getOutputs2OutputsIDs().at(builder1.getDNLIDforOutput(i));
// print path0
for (const auto& name : path0.first) {
logger->info("%s.", name.getString().c_str());
}
for (const auto& id : path0.second) {
logger->info("%lu.", id);
}
logger->info("\n");
// print path1
for (const auto& name : path1.first) {
logger->info("%s.", name.getString().c_str());
}
for (const auto& id : path1.second) {
logger->info("%lu.", id);
}
logger->info("\n");
throw std::runtime_error("Miter PO index " + std::to_string(i) +
" DNLIDs do not match");
}
Expand All @@ -506,6 +557,25 @@ bool MiterStrategy::run() {
logger->info("Found difference for PO: {}", i);
// logger->info("Clause 0 {}", POs0[i]->toString());
// logger->info("Clause 1 {}", POs1[i]->toString());
// print path of index i
auto path0 = builder0.getOutputs2OutputsIDs().at(builder0.getDNLIDforOutput(i));
std::string pathString = "";
for (const auto& name : path0.first) {
pathString += name.getString() + ".";
}
for (const auto& id : path0.second) {
pathString += std::to_string(id) + ".";
}
logger->info("Path of differing PO {}: {}", i, pathString);
auto path1 = builder1.getOutputs2OutputsIDs().at(builder1.getDNLIDforOutput(i));
std::string pathString1 = "";
for (const auto& name : path1.first) {
pathString1 += name.getString() + ".";
}
for (const auto& id : path1.second) {
pathString1 += std::to_string(id) + ".";
}
logger->info("Path of differing PO {}: {}", i, pathString1);
std::vector<naja::NL::SNLDesign*> topModels;
topModels.push_back(top0_);
topModels.push_back(top1_);
Expand Down
10 changes: 3 additions & 7 deletions src/strategies/miter/MiterStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ namespace KEPLER_FORMAL {

class MiterStrategy {
public:
MiterStrategy(naja::NL::SNLDesign* top0, naja::NL::SNLDesign* top1, const std::string& prefix = "")
: prefix_(prefix) {
top0_ = top0;
top1_ = top1;
}
MiterStrategy(naja::NL::SNLDesign* top0, naja::NL::SNLDesign* top1, const std::string& logFileName = "", const std::string& prefix = "");

bool run();

Expand All @@ -36,12 +32,12 @@ class MiterStrategy {
const std::map<std::pair<std::vector<NLName>, std::vector<NLID::DesignObjectID>>, naja::DNL::DNLID>& outputs0Map,
const std::map<std::pair<std::vector<NLName>, std::vector<NLID::DesignObjectID>>, naja::DNL::DNLID>& outputs1Map);


static std::string logFileName_;
private:
std::shared_ptr<BoolExpr> buildMiter(
const tbb::concurrent_vector<std::shared_ptr<BoolExpr>>& A,
const tbb::concurrent_vector<std::shared_ptr<BoolExpr>>& B) const;

static naja::NL::SNLDesign* top0_;
static naja::NL::SNLDesign* top1_;
tbb::concurrent_vector<BoolExpr> POs0_;
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/naja
Submodule naja updated 148 files
Loading