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

chore(compiler): make formatters and linters happy #1205

Merged
merged 1 commit into from
Jan 21, 2025
Merged
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
6 changes: 6 additions & 0 deletions .github/workflows/concrete_compiler_test_cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ jobs:
sudo apt install moreutils
cd compilers/concrete-compiler/compiler
./scripts/format_cpp.sh
- name: Upload format diff
if: failure()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: format_diff
path: compilers/concrete-compiler/compiler/format_diff.patch
- name: Format with cmake-format (Cmake)
run: |
pip3 install cmakelang
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ void emitErrorBadLutSize(Op &op, std::string lutName, std::string inputName,
auto s = op.emitOpError();
s << ": `" << lutName << "` (operand #2)"
<< " inner dimension should have size " << expectedSize << "(=2^"
<< bitWidth << ") to match "
<< "`" << inputName << "` (operand #1)"
<< bitWidth << ") to match " << "`" << inputName << "` (operand #1)"
<< " elements bitwidth (" << bitWidth << ")";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#ifndef CONCRETELANG_SUPPORT_VARIANTS_H_
#define CONCRETELANG_SUPPORT_VARIANTS_H_

template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template <class... Ts> struct overloaded : Ts... {
using Ts::operator()...;
};
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;

#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
black==24.4.0
pylint==2.11.1
pylint==3.3.3
mypy==1.11.2
numpy>=1.23,<2.0
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ LogicalResult verifyTensorBroadcastingRules(
op->emitOpError() << "has the dimension #"
<< (operandsShapes[j].size() - k)
<< " of the operand #" << j
<< " incompatible with other operands"
<< ", got " << operandDim << " expect 1 or "
<< expectedResultDim;
<< " incompatible with other operands" << ", got "
<< operandDim << " expect 1 or " << expectedResultDim;
return mlir::failure();
}

Expand Down Expand Up @@ -706,9 +705,9 @@ template <typename MatMulOp> mlir::LogicalResult verifyMatmul(MatMulOp &op) {
// 1xMxN @ KxLxNxP -> KxLxMxP

if (lhsShape[lhsDims - 1] != rhsShape[rhsDims - 2]) {
op.emitOpError() << "should have the same size "
<< "on dimension #" << lhsDims - 1 << " of operand #0 "
<< "and dimension #" << rhsDims - 2 << " of operand #1";
op.emitOpError() << "should have the same size " << "on dimension #"
<< lhsDims - 1 << " of operand #0 " << "and dimension #"
<< rhsDims - 2 << " of operand #1";
return mlir::failure();
}

Expand Down Expand Up @@ -759,8 +758,8 @@ template <typename MatMulOp> mlir::LogicalResult verifyMatmul(MatMulOp &op) {

if (rhsShape[rhsDims - 2] != lhsShape[0]) {
op.emitOpError() << "should have the same size "
<< "on dimension #0 of operand #0 "
<< "and dimension #" << rhsDims - 2 << " of operand #1";
<< "on dimension #0 of operand #0 " << "and dimension #"
<< rhsDims - 2 << " of operand #1";
return mlir::failure();
}

Expand All @@ -777,8 +776,8 @@ template <typename MatMulOp> mlir::LogicalResult verifyMatmul(MatMulOp &op) {
// KxLxMxN @ N -> KxLxM

if (lhsShape[lhsDims - 1] != rhsShape[0]) {
op.emitOpError() << "should have the same size "
<< "on dimension #" << lhsDims - 1 << " of operand #0 "
op.emitOpError() << "should have the same size " << "on dimension #"
<< lhsDims - 1 << " of operand #0 "
<< "and dimension #0 of operand #1";
return mlir::failure();
}
Expand Down Expand Up @@ -1091,11 +1090,10 @@ mlir::LogicalResult Maxpool2dOp::verify() {
const FHE::FheIntegerInterface outputElementTy = outputTy.getElementType();

if (inputElementTy != outputElementTy) {
this->emitOpError() << "expected output element type "
<< "(" << outputElementTy << ") "
<< "to be the same with input element type "
<< "(" << inputElementTy << ") "
<< "but it is not";
this->emitOpError() << "expected output element type " << "("
<< outputElementTy << ") "
<< "to be the same with input element type " << "("
<< inputElementTy << ") " << "but it is not";
return mlir::failure();
}

Expand Down Expand Up @@ -1125,10 +1123,9 @@ mlir::LogicalResult Maxpool2dOp::verify() {
kernelShapeAttrTy.getShape();

if (kernelShapeAttrShape.size() != 1 || kernelShapeAttrShape[0] != 2) {
this->emitOpError() << "expected kernel shape to be of shape "
<< "(2) "
<< "but it is of shape "
<< "(" << kernelShapeAttrShape << ")";
this->emitOpError() << "expected kernel shape to be of shape " << "(2) "
<< "but it is of shape " << "(" << kernelShapeAttrShape
<< ")";
return mlir::failure();
}

Expand All @@ -1149,10 +1146,9 @@ mlir::LogicalResult Maxpool2dOp::verify() {
const llvm::ArrayRef<int64_t> stridesAttrShape = stridesAttrTy.getShape();

if (stridesAttrShape.size() != 1 || stridesAttrShape[0] != 2) {
this->emitOpError() << "expected strides to be of shape "
<< "(2) "
<< "but it is of shape "
<< "(" << stridesAttrShape << ")";
this->emitOpError() << "expected strides to be of shape " << "(2) "
<< "but it is of shape " << "(" << stridesAttrShape
<< ")";
return mlir::failure();
}

Expand Down Expand Up @@ -1183,10 +1179,9 @@ mlir::LogicalResult Maxpool2dOp::verify() {
dilationsAttrTy.getShape();

if (dilationsAttrShape.size() != 1 || dilationsAttrShape[0] != 2) {
this->emitOpError() << "expected dilations to be of shape "
<< "(2) "
<< "but it is of shape "
<< "(" << dilationsAttrShape << ")";
this->emitOpError() << "expected dilations to be of shape " << "(2) "
<< "but it is of shape " << "(" << dilationsAttrShape
<< ")";
return mlir::failure();
}

Expand Down Expand Up @@ -1218,9 +1213,8 @@ mlir::LogicalResult Maxpool2dOp::verify() {
};

if (outputShape != llvm::ArrayRef(expectedOutputShape)) {
this->emitOpError() << "expected output to be of shape "
<< "(" << expectedOutputShape << ") "
<< "but it is of shape "
this->emitOpError() << "expected output to be of shape " << "("
<< expectedOutputShape << ") " << "but it is of shape "
<< "(" << outputShape << ")";
return mlir::failure();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ void displayOptimizer(const Solution &solution,
}
// Print the actual correctness of the solution
llvm::errs() << "-- Solution correctness\n"
<< " For each pbs call: "
<< " 1/" << int(1.0 / solution.p_error) << ", p_error ("
<< " For each pbs call: " << " 1/"
<< int(1.0 / solution.p_error) << ", p_error ("
<< solution.p_error << ")\n";
if (descr.dag && !std::isnan(solution.global_p_error)) {
llvm::errs() << " For the full circuit:"
<< " 1/" << int(1.0 / solution.global_p_error)
<< " global_p_error(" << solution.global_p_error << ")\n";
llvm::errs() << " For the full circuit:" << " 1/"
<< int(1.0 / solution.global_p_error) << " global_p_error("
<< solution.global_p_error << ")\n";
}
auto complexity_label =
descr.dag ? "for the full circuit" : "for each Pbs call";
Expand Down
12 changes: 9 additions & 3 deletions compilers/concrete-compiler/compiler/scripts/format_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

set -e -o pipefail

EXCLUDE_DIRS="-path ./include/boost-single-header -prune -o"
echo "Formatting with " $(clang-format --version)

find ./{include,lib,src,tests} $EXCLUDE_DIRS -iregex '^.*\.\(cpp\|cc\|h\|hpp\)$' -print | xargs clang-format -i -style='file'
find ./{include,lib,src,tests} \
\( -name "*.h" -or -name "*.hpp" -or -name "*.cpp" -or -name "*.cc" \) \
-and -not -path "./include/boost-single-header*" \
-and -not -path "./lib/Bindings/Rust*" \
| xargs clang-format -i -style='file'

# show changes if any
git --no-pager diff --patience

# success if the diff is empty
git --no-pager diff --exit-code && exit 0

# write diff to file
git diff > format_diff.patch

echo
echo "Formatting issue: Please run 'scripts/format_cpp.sh' in compilers/concrete-compiler/compiler and 'git add -p'"
exit 1
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace {

TEST(WrappersDeathTest, bad_alloc) {
ASSERT_DEATH({ concrete_checked_malloc(SIZE_MAX); },
"bad alloc: nullptr while calling "
"malloc\\(17179869183 GB\\).*Backtrace:.*");
ASSERT_DEATH(
{ concrete_checked_malloc(SIZE_MAX); },
"bad alloc: nullptr while calling "
"malloc\\(17179869183 GB\\).*Backtrace:.*");
}

} // namespace
Loading