Skip to content

Commit d8bbaeb

Browse files
authored
Python logging & changed Python class names (#245)
1 parent eb300e6 commit d8bbaeb

Some content is hidden

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

41 files changed

+804
-476
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ build/
66
*.pyc
77
*.pyo
88
*.pyd
9+
.pytest_cache/
910

1011
# Git
1112
**/.git

.github/workflows/codeql.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: Build
5050
run: |
5151
mkdir build && cd build
52-
cmake -DCMAKE_BUILD_TYPE=Debug -DARK_BUILD_PYTHON=ON -DARK_BYPASS_GPU_CHECK=ON -DARK_USE_CUDA=ON -DARK_BUILD_TESTS=OFF ..
52+
cmake -DCMAKE_BUILD_TYPE=Debug -DARK_BYPASS_GPU_CHECK=ON -DARK_USE_CUDA=ON -DARK_BUILD_TESTS=OFF ..
5353
make build ark_py
5454
5555
- name: Perform CodeQL Analysis
@@ -95,7 +95,7 @@ jobs:
9595
- name: Build
9696
run: |
9797
mkdir build && cd build
98-
CXX=/opt/rocm/bin/hipcc cmake -DCMAKE_BUILD_TYPE=Debug -DARK_BUILD_PYTHON=ON -DARK_BYPASS_GPU_CHECK=ON -DARK_USE_ROCM=ON -DARK_BUILD_TESTS=OFF ..
98+
CXX=/opt/rocm/bin/hipcc cmake -DCMAKE_BUILD_TYPE=Debug -DARK_BYPASS_GPU_CHECK=ON -DARK_USE_ROCM=ON -DARK_BUILD_TESTS=OFF ..
9999
make -j build ark_py
100100
101101
- name: Perform CodeQL Analysis

.github/workflows/ut-cuda.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- name: Build
4545
run: |
4646
mkdir build && cd build
47-
cmake -DCMAKE_BUILD_TYPE=Debug -DARK_BUILD_PYTHON=ON ..
47+
cmake -DCMAKE_BUILD_TYPE=Debug ..
4848
make -j ut ark_py
4949
5050
- name: Run C++ UT
@@ -71,7 +71,11 @@ jobs:
7171
- name: Run Python UT
7272
run: |
7373
cd build
74-
ARK_ROOT=$PWD pytest --cov=../python/ark --cov-report lcov:py_coverage.info --verbose ../python/unittest/test.py
74+
PYTHONPATH=$PWD/python ARK_ROOT=$PWD python3 -m pytest \
75+
--cov=python/ark \
76+
--cov-report lcov:py_coverage.info \
77+
--verbose \
78+
../python/unittest/test.py
7579
7680
- name: Report Coverage
7781
env:

.vscode/settings.json

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
"cmake.environment": {
44
"ARK_ROOT": "${workspaceFolder}/build",
55
"ARK_IGNORE_BINARY_CACHE": "1",
6-
"ARK_DISABLE_GRAPH_OPT": "0",
7-
"ARK_IPC_LISTEN_PORT_BASE": "42000",
86
// "ARK_LOG_LEVEL": "DEBUG"
97
},
108
"cmake.ctestArgs": [

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ option(ARK_USE_CUDA "Use NVIDIA/CUDA." OFF)
1717
option(ARK_USE_ROCM "Use AMD/ROCm." OFF)
1818
option(ARK_BYPASS_GPU_CHECK "Bypass GPU check." OFF)
1919
option(ARK_BUILD_TESTS "Build unit tests." ON)
20+
option(ARK_BUILD_PYTHON "Build Python module." ON)
2021

2122
if(ARK_BYPASS_GPU_CHECK)
2223
if(ARK_USE_CUDA)

ark/api/log.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
#include "ark/log.hpp"
5+
6+
#include "logging.hpp"
7+
8+
namespace ark {
9+
10+
void log(LogLevel level, const std::string &file, int line,
11+
const std::string &msg) {
12+
_log(level, file, line, msg);
13+
}
14+
15+
} // namespace ark

ark/include/ark/log.hpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
#ifndef ARK_LOG_HPP
5+
#define ARK_LOG_HPP
6+
7+
#include <string>
8+
9+
namespace ark {
10+
11+
typedef enum { DEBUG, INFO, WARN, ERROR } LogLevel;
12+
13+
void log(LogLevel level, const std::string &file, int line,
14+
const std::string &msg);
15+
16+
} // namespace ark
17+
18+
#endif // ARK_LOG_HPP

ark/logging.hpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
#include <string>
1010

1111
#include "ark/error.hpp"
12+
#include "ark/log.hpp"
1213

1314
namespace ark {
1415

15-
typedef enum { DEBUG, INFO, WARN, ERROR } LogLevel;
16-
1716
class Logging {
1817
public:
1918
Logging(const std::string &lv);
@@ -46,43 +45,44 @@ void _log_helper(std::stringstream &ss, T value, Args... args) {
4645
_log_helper(ss, args...);
4746
}
4847

49-
template <LogLevel Level, bool AppendNewLine, typename T, typename... Args>
50-
inline std::string _log_msg(const std::string &file, int line, T value,
48+
template <typename T, typename... Args>
49+
inline std::string _log_msg(LogLevel level, bool append_newline,
50+
const std::string &file, int line, T value,
5151
Args... args) {
5252
std::stringstream ss;
53-
_log_header(ss, Level, file, line);
53+
_log_header(ss, level, file, line);
5454
_log_helper(ss, value, args...);
55-
if constexpr (AppendNewLine) ss << std::endl;
55+
if (append_newline) ss << std::endl;
5656
return ss.str();
5757
}
5858

59-
template <LogLevel Level, typename T, typename... Args>
60-
inline void _log(const std::string &file, int line, T value, Args... args) {
61-
if (Level >= get_logging().get_level()) {
62-
std::clog << _log_msg<Level, true>(file, line, value, args...);
59+
template <typename T, typename... Args>
60+
inline void _log(LogLevel level, const std::string &file, int line, T value,
61+
Args... args) {
62+
if (level >= get_logging().get_level()) {
63+
std::clog << _log_msg(level, true, file, line, value, args...);
6364
}
64-
if constexpr (Level == ERROR) {
65+
if (level == ERROR) {
6566
throw std::runtime_error("ARK runtime error");
6667
}
6768
}
6869

6970
template <typename Exception, typename T, typename... Args>
7071
inline void _err(const std::string &file, int line, T value, Args... args) {
71-
throw Exception(_log_msg<ERROR, false>(file, line, value, args...));
72+
throw Exception(_log_msg(ERROR, false, file, line, value, args...));
7273
}
7374

7475
// Logging.
7576
#define LOG(level, ...) \
7677
do { \
77-
ark::_log<level>(__FILE__, __LINE__, __VA_ARGS__); \
78+
ark::_log(level, __FILE__, __LINE__, __VA_ARGS__); \
7879
break; \
7980
} while (0)
8081

81-
#define ERR(exception, ...) \
82-
do { \
83-
std::string exc_str = " (" #exception ")"; \
84-
ark::_err<exception>(__FILE__, __LINE__, __VA_ARGS__, exc_str); \
85-
break; \
82+
#define ERR(exception, ...) \
83+
do { \
84+
ark::_err<exception>(__FILE__, __LINE__, __VA_ARGS__); \
85+
break; \
8686
} while (0)
8787

8888
#define CHECK(cond) \

ark/ops/ops_test_common.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ float reduction_abs_error_bound(float max_abs, int reduction_length) {
6060
// If the reduction length is too large, the error will be dominated by
6161
// the rounding error of the reduction itself.
6262
if (reduction_length > (1 << (NumFracBits + 1))) {
63-
UNITTEST_FEXIT("reduction length is too large");
63+
UNITTEST_FAIL("reduction length is too large");
6464
}
6565
float max_diff =
6666
reduction_length * 2 * max_abs * 1.0f / (1 << (NumFracBits + 1));

ark/unittest/unittest_utils.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// Grep SIGALRM and exit.
1717
static void sigalrm_timeout_handler(int) {
1818
signal(SIGALRM, SIG_IGN);
19-
UNITTEST_FEXIT("timeout");
19+
UNITTEST_FAIL("timeout");
2020
}
2121

2222
namespace ark {
@@ -64,7 +64,7 @@ void wait_all_threads() {
6464
int spawn_process(std::function<State()> func) {
6565
pid_t pid = fork();
6666
if (pid < 0) {
67-
UNITTEST_UEXIT("fork() failed");
67+
UNITTEST_UNEXPECTED("fork() failed");
6868
} else if (pid == 0) {
6969
State ret = func();
7070
std::exit(ret);
@@ -82,7 +82,7 @@ void wait_all_processes() {
8282
do {
8383
pid = wait(&status);
8484
if (pid == -1) {
85-
UNITTEST_UEXIT("wait() failed");
85+
UNITTEST_UNEXPECTED("wait() failed");
8686
}
8787
} while (!WIFEXITED(status));
8888
status = WEXITSTATUS(status);

0 commit comments

Comments
 (0)