Skip to content

Commit 4d83114

Browse files
authored
EWLayer && oneDNN (#217)
#213
1 parent 3d2f33b commit 4d83114

18 files changed

Lines changed: 679 additions & 100 deletions

File tree

.github/workflows/ci.yml

Lines changed: 55 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
max-size: 2G
4141
- name: Build
4242
run: |
43-
cmake -S . -B build \
43+
cmake -S . -B build -G Ninja \
4444
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
4545
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
4646
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
@@ -51,19 +51,18 @@ jobs:
5151
cmake --build build --parallel
5252
env:
5353
CTEST_OUTPUT_ON_FAILURE: 1
54-
- name: Prepare OpenCV libs
54+
- name: Prepare ALL libs
5555
run: |
56-
mkdir -p build/bin/opencv_libs
57-
cp -a build/3rdparty/opencv_build/lib/libopencv_* build/bin/opencv_libs/
58-
echo "Library permissions after copy:"
59-
stat -c "%A %n" build/bin/opencv_libs/libopencv_imgcodecs.so*
60-
56+
mkdir -p build/bin/all_libs
57+
cp -a build/3rdparty/opencv_build/lib/* build/bin/all_libs/ 2>/dev/null || true
58+
ldd build/bin/ACC | grep "=> /" | awk '{print $3}' | xargs -I {} cp {} build/bin/all_libs/ 2>/dev/null || true
6159
- name: Upload artifacts
6260
uses: actions/upload-artifact@v4
6361
with:
6462
name: mnist-${{ matrix.build_type }}${{ matrix.stats && '-stats' || '' }}
6563
path: |
6664
${{ steps.set_binaries.outputs.ACC_BINARY }}
65+
build/bin/all_libs/*
6766
build/bin/opencv_libs/*
6867
build/setenv.sh
6968
- name: Test
@@ -92,7 +91,7 @@ jobs:
9291
key: ccache-${{ github.job }}
9392
- name: Build
9493
run: |
95-
cmake -S . -B build \
94+
cmake -S . -B build -G Ninja \
9695
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
9796
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
9897
-DCMAKE_C_COMPILER=clang \
@@ -117,20 +116,33 @@ jobs:
117116
submodules: true
118117
- name: Install prerequisites
119118
run: |
120-
brew install libomp
119+
brew install libomp ninja
121120
brew link libomp --overwrite --force
122121
- name: Setup ccache
123122
uses: hendrikmuhs/ccache-action@v1.2
124123
with:
125124
key: ccache-${{ github.job }}
126125
- name: Build
127126
run: |
128-
cmake -S . -B build \
127+
OPENMP_PATH=$(brew --prefix libomp)
128+
echo "OpenMP path: $OPENMP_PATH"
129+
cmake -S . -B build -G Ninja \
129130
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
130131
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
131-
-DCMAKE_C_FLAGS="-I$(brew --prefix libomp)/include" \
132-
-DCMAKE_CXX_FLAGS="-I$(brew --prefix libomp)/include"
132+
-DCMAKE_PREFIX_PATH=$OPENMP_PATH \
133+
-DCMAKE_INCLUDE_PATH=$OPENMP_PATH/include \
134+
-DCMAKE_LIBRARY_PATH=$OPENMP_PATH/lib \
135+
-DOpenMP_C_FLAGS="-Xclang -fopenmp -I$OPENMP_PATH/include" \
136+
-DOpenMP_CXX_FLAGS="-Xclang -fopenmp -I$OPENMP_PATH/include" \
137+
-DOpenMP_C_LIB_NAMES="omp" \
138+
-DOpenMP_CXX_LIB_NAMES="omp" \
139+
-DOpenMP_omp_LIBRARY="$OPENMP_PATH/lib/libomp.dylib" \
140+
-DCMAKE_EXE_LINKER_FLAGS="-L$OPENMP_PATH/lib -lomp" \
141+
-DCMAKE_SHARED_LINKER_FLAGS="-L$OPENMP_PATH/lib -lomp"
133142
cmake --build build --parallel
143+
env:
144+
LDFLAGS: "-L$(brew --prefix libomp)/lib -lomp"
145+
CPPFLAGS: "-I$(brew --prefix libomp)/include"
134146
- name: Test
135147
run: cmake --build build -t test
136148
env:
@@ -175,7 +187,7 @@ jobs:
175187
key: ccache-${{ github.job }}
176188
- name: Build and Test
177189
run: |
178-
cmake -S . -B build \
190+
cmake -S . -B build -G Ninja \
179191
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
180192
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
181193
-DCMAKE_BUILD_TYPE=Release
@@ -201,7 +213,7 @@ jobs:
201213
max-size: 2G
202214
- name: Build
203215
run: |
204-
cmake -S . -B build \
216+
cmake -S . -B build -G Ninja \
205217
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
206218
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
207219
-DCMAKE_C_FLAGS="--coverage" \
@@ -222,32 +234,36 @@ jobs:
222234
slug: embedded-dev-research/ITLabAI
223235

224236
evaluate-model:
225-
runs-on: ubuntu-latest
226-
needs: [build-linux]
227-
permissions:
228-
contents: write
237+
runs-on: ubuntu-latest
238+
needs: [build-linux]
239+
permissions:
240+
contents: write
229241

230-
steps:
242+
steps:
231243
- uses: actions/checkout@v4
232244
with:
233245
fetch-depth: 0
246+
247+
- name: Download binary and libs
248+
uses: actions/download-artifact@v4
249+
with:
250+
name: mnist-RELEASE
251+
path: build/
252+
234253
- name: Set binary path
235254
id: set_eval_binary
236255
run: |
237256
echo "EVAL_BINARY=build/bin/ACC" >> $GITHUB_OUTPUT
257+
238258
- name: Install system dependencies
239259
run: |
240260
sudo apt-get update
241-
sudo apt-get install -y \
242-
libgtk-3-0 \
243-
libtbb12 \
244-
libjpeg-dev \
245-
libpng-dev \
246-
libtiff-dev
261+
sudo apt-get install -y libgtk-3-0 libtbb12 libjpeg-dev libpng-dev libtiff-dev libopenjp2-7 libdnnl3
247262
sudo ldconfig
263+
248264
- name: Generate model JSON
249265
run: |
250-
cd docs && mkdir jsons
266+
cd docs && mkdir -p jsons
251267
cd ..
252268
cd app/Converters
253269
pip install -r requirements.txt
@@ -264,76 +280,46 @@ jobs:
264280
- name: Download MNIST test dataset
265281
if: steps.cache-mnist.outputs.cache-hit != 'true'
266282
run: |
267-
set -e
268283
mkdir -p docs/mnist/mnist/test
269-
echo "Downloading test images..."
270284
wget -q https://github.com/DeepTrackAI/MNIST_dataset/archive/main.zip -O main.zip
271285
unzip -q main.zip
272286
cp MNIST_dataset-main/mnist/test/*.png docs/mnist/mnist/test/
273287
rm -rf main.zip MNIST_dataset-main
274-
echo "Downloaded $(ls docs/mnist/mnist/test | wc -l) images"
275-
276-
- name: Download binary and libs
277-
uses: actions/download-artifact@v4
278-
with:
279-
name: mnist-RELEASE
280-
path: build/
281288
282289
- name: Prepare environment
283290
run: |
284291
chmod +x "${{ steps.set_eval_binary.outputs.EVAL_BINARY }}"
292+
export LD_LIBRARY_PATH=$PWD/build/bin/all_libs:/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
285293
286-
export LD_LIBRARY_PATH=$PWD/build/bin/opencv_libs:/usr/lib/x86_64-linux-gnu
287-
echo "Final LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
288-
289-
- name: Verify library integrity
290-
run: |
291-
echo "### Library verification ###"
292-
file build/bin/opencv_libs/libopencv_imgcodecs.so.4.12.0 | grep "shared object"
293-
294294
- name: Run evaluation
295295
run: |
296-
echo "### Pre-run checks ###"
297-
export LD_LIBRARY_PATH=$PWD/build/bin/opencv_libs:/usr/lib/x86_64-linux-gnu
298-
echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
299-
300-
LD_DEBUG=files "${{ steps.set_eval_binary.outputs.EVAL_BINARY }}" --model alexnet_mnist 2> ld_debug.log
301-
echo "### Library loading debug ###"
302-
grep -i "opencv_imgcodecs" ld_debug.log
303-
304-
"${{ steps.set_eval_binary.outputs.EVAL_BINARY }}" > accuracy.txt
305-
echo "Accuracy: $(cat accuracy.txt)"
296+
export LD_LIBRARY_PATH=$PWD/build/bin/all_libs:/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
297+
"${{ steps.set_eval_binary.outputs.EVAL_BINARY }}" --model alexnet_mnist > accuracy.txt 2>&1
298+
if [ $? -ne 0 ]; then
299+
exit 1
300+
fi
306301
302+
- name: Extract accuracy value
303+
run: |
304+
ACCURACY=$(grep -oE '[0-9]+\.?[0-9]*%' accuracy.txt | head -1 || echo "0%")
305+
echo "$ACCURACY" > accuracy_value.txt
306+
307307
- name: Update README (master only)
308308
if: github.ref == 'refs/heads/master'
309309
run: |
310-
ACCURACY=$(cat accuracy.txt | sed 's/%//g')
310+
ACCURACY=$(cat accuracy_value.txt | sed 's/%//g')
311311
DATE=$(date '+%Y-%m-%d')
312-
313-
echo "Updating README with:"
314-
echo "Accuracy: $ACCURACY"
315-
echo "Date: $DATE"
316-
317-
echo "Current README content:"
318-
grep -A 2 -B 2 "ACCURACY_PLACEHOLDER" README.md || echo "Placeholder not found"
319-
320312
sed -i "s/<!--ACCURACY_PLACEHOLDER-->.*<!--END_ACCURACY-->/<!--ACCURACY_PLACEHOLDER-->Accuracy: ${ACCURACY}% (updated: ${DATE})<!--END_ACCURACY-->/" README.md
321-
322-
echo "Updated README content:"
323-
grep -A 2 -B 2 "ACCURACY_PLACEHOLDER" README.md
324313
325314
- name: Commit and push changes (master only)
326315
if: github.ref == 'refs/heads/master'
327316
run: |
328317
git config --global user.name "GitHub Actions"
329318
git config --global user.email "actions@github.com"
330-
331319
git add README.md
332-
333320
if git diff-index --quiet HEAD --; then
334321
echo "No changes to commit"
335322
else
336-
git commit -m "[CI] Update accuracy: $(cat accuracy.txt)%"
323+
git commit -m "[CI] Update accuracy: $(cat accuracy_value.txt)"
337324
git push origin master
338-
echo "Changes pushed to master branch"
339325
fi

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
key: ccache-${{ github.job }}
3333
- name: Build
3434
run: |
35-
cmake -S . -B build \
35+
cmake -S . -B build -G Ninja \
3636
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
3737
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
3838
-DCMAKE_C_COMPILER=clang \

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
[submodule "3rdparty/Json"]
1111
path = 3rdparty/Json
1212
url = https://github.com/nlohmann/json
13+
[submodule "3rdparty/oneDNN"]
14+
path = 3rdparty/oneDNN
15+
url = https://github.com/uxlfoundation/oneDNN

3rdparty/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
add_subdirectory(googletest)
22

3+
add_subdirectory(oneDNN)
4+
35
# Unified TBB Configuration
46
option(TBB_TEST "Build TBB tests" OFF)
57
option(TBB_EXAMPLES "Build TBB examples" OFF)

3rdparty/oneDNN

Submodule oneDNN added at ceb0d6c

app/Graph/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ target_link_libraries(BuildGraph PUBLIC ${OpenCV_LIBS})
1111
target_link_libraries(BuildGraph PUBLIC reader_lib)
1212
target_link_libraries(BuildGraph PUBLIC TBB_unified)
1313
target_link_libraries(BuildGraph PUBLIC layers_lib)
14+
target_link_libraries(BuildGraph PUBLIC layers_oneDNN_lib)
1415
target_link_libraries(BuildGraph PUBLIC gtest_main)
1516

1617
target_include_directories(BuildGraph PUBLIC ${CMAKE_SOURCE_DIR}/3rdparty/Json/include)

app/Graph/acc_check.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ using namespace it_lab_ai;
1414
int main(int argc, char* argv[]) {
1515
std::string model_name = "alexnet_mnist";
1616
bool parallel = false;
17-
17+
bool onednn = false;
1818
for (int i = 1; i < argc; ++i) {
1919
if (std::string(argv[i]) == "--parallel") {
2020
parallel = true;
2121
} else if (std::string(argv[i]) == "--model" && i + 1 < argc) {
2222
model_name = argv[++i];
23+
} else if (std::string(argv[i]) == "--onednn") {
24+
onednn = true;
2325
}
2426
}
2527

@@ -78,7 +80,7 @@ int main(int argc, char* argv[]) {
7880
Shape sh({static_cast<size_t>(count_pic), 1, 28, 28});
7981
Tensor t = make_tensor<float>(res, sh);
8082
input = t;
81-
build_graph_linear(input, output, false, parallel);
83+
build_graph_linear(input, output, false, parallel, onednn);
8284
std::vector<std::vector<float>> tmp_output =
8385
softmax<float>(*output.as<float>(), 10);
8486
std::vector<size_t> indices;
@@ -185,7 +187,7 @@ int main(int argc, char* argv[]) {
185187
it_lab_ai::Tensor output =
186188
it_lab_ai::Tensor(output_shape, it_lab_ai::Type::kFloat);
187189

188-
build_graph(input, output, json_path, false, parallel);
190+
build_graph(input, output, json_path, false, parallel, onednn);
189191
std::vector<std::vector<float>> processed_outputs;
190192
const std::vector<float>& raw_output = *output.as<float>();
191193

0 commit comments

Comments
 (0)