Skip to content

Commit

Permalink
Fix performance issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatdongdang committed Jun 25, 2024
1 parent 6f77e3b commit bfc48ac
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 8,851 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: CI
on:
push:
branches: main
paths: ['**.c','**.cpp', '**.h', '**CMakeLists.txt']
paths: ['**.cu','**.c','**.cpp', '**.h', '**CMakeLists.txt']
pull_request:
branches: main
paths: ['**.c','**.cpp', '**.h', '**CMakeLists.txt']
paths: ['**.cu','**.c','**.cpp', '**.h', '**CMakeLists.txt']

jobs:
build-and-test:
Expand All @@ -29,7 +29,6 @@ jobs:
run: |
make build
- name: Run test suite
run: |
make test
4 changes: 2 additions & 2 deletions .github/workflows/cpp-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: cpp-linter
on:
pull_request:
branches: main
paths: ['**.cpp','**.c', '**.h', '**CMakeLists.txt']
paths: ['**.cu','**.cpp','**.c', '**.h', '**CMakeLists.txt']
push:
branches: main
paths: ['**.cpp','**.c', '**.h', '**CMakeLists.txt']
paths: ['**.cu','**.cpp','**.c', '**.h', '**CMakeLists.txt']

permissions:
contents: write
Expand Down
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@
*.exe
*.out
*.app
*
!*/
!*.*

# misc
.vscode
*.csv
build
results.csv
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ set(CMAKE_C_STANDARD_REQUIRED True)
set(SRC_DIR src)
set(INC_DIR include)


# Source files
file(GLOB_RECURSE INCLUDE_FILES ${INC_DIR}/*.h)
file(GLOB_RECURSE SOURCE_FILES ${SRC_DIR}/*.c)
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
clean:
rm -rf build
rm speed_cpu

build:
cmake -Bbuild
$(MAKE) -C ./build
Expand Down
5 changes: 1 addition & 4 deletions include/matrix.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef MATRIX_H
#define MATRIX_H
#pragma once

typedef struct {
int rows;
Expand All @@ -16,5 +15,3 @@ void addMatrix(matrix* a, const matrix* b);
void ReLU(matrix* a);

void softmax(matrix* a);

#endif
8,837 changes: 1 addition & 8,836 deletions include/util.h

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

matrix* weight[7];
matrix* biase[7];
int results[1000000];

void processWeight(char* line, int layer) {
char* token;
Expand Down Expand Up @@ -166,6 +165,13 @@ int main(int argc, char* argv[]) {
while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_REG) {
size++;
}
}

int* results = (int*)malloc((size + 1) * sizeof(int));
dir = opendir(directory_path);
while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_REG) {
strcpy(fileNumStr, entry->d_name);
fileNumStr[strlen(entry->d_name) - 7] = '\0';
fileNum = atoi(entry->d_name);
Expand All @@ -176,6 +182,7 @@ int main(int argc, char* argv[]) {
results[fileNum] = inference(input);
}
}

free(fileName);
free(fileNumStr);
closedir(dir);
Expand Down
53 changes: 53 additions & 0 deletions test/expected_results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
image_number, guess
1, A
2, a
3, B
4, b
5, C
6, c
7, D
8, d
9, E
10, e
11, F
12, f
13, G
14, g
15, H
16, h
17, I
18, i
19, J
20, j
21, K
22, k
23, L
24, l
25, M
26, m
27, N
28, n
29, O
30, o
31, P
32, p
33, Q
34, q
35, R
36, r
37, S
38, s
39, T
40, t
41, U
42, u
43, V
44, v
45, W
46, w
47, X
48, x
49, Y
50, y
51, Z
52, z

0 comments on commit bfc48ac

Please sign in to comment.