Skip to content

Commit e2f4e86

Browse files
committed
fix: move ONNX/InclKinML print_shape into anon namespace with unique ID
1 parent b30a941 commit e2f4e86

File tree

3 files changed

+76
-48
lines changed

3 files changed

+76
-48
lines changed

.github/workflows/linux-eic-shell.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ jobs:
150150
platform-release: "${{ env.platform }}:${{ matrix.release }}"
151151
run: |
152152
# install this repo
153-
CXX="${{ matrix.CXX }}" CXXFLAGS="${{ matrix.CXXFLAGS }}" cmake --warn-uninitialized -B build -S . -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=24 -DCMAKE_INSTALL_PREFIX=install -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_BUILD_TYPE=${{ matrix.CMAKE_BUILD_TYPE }} -DUSE_ASAN=${{matrix.USE_ASAN}} -DUSE_TSAN=${{matrix.USE_TSAN}} -DUSE_UBSAN=${{matrix.USE_UBSAN}}
153+
CXX="${{ matrix.CXX }}" CXXFLAGS="${{ matrix.CXXFLAGS }}" cmake --warn-uninitialized -B build -S . -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=24 -DCMAKE_UNITY_BUILD_UNIQUE_ID=UNITY_BUILD_UNIQUE_ID -DCMAKE_INSTALL_PREFIX=install -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_BUILD_TYPE=${{ matrix.CMAKE_BUILD_TYPE }} -DUSE_ASAN=${{matrix.USE_ASAN}} -DUSE_TSAN=${{matrix.USE_TSAN}} -DUSE_UBSAN=${{matrix.USE_UBSAN}}
154154
cmake --build build -j $(getconf _NPROCESSORS_ONLN) --target install
155155
ccache --show-stats --verbose
156156
ccache --evict-older-than 7d

src/algorithms/onnx/InclusiveKinematicsML.cc

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,37 @@
1515

1616
namespace eicrecon {
1717

18-
static std::string print_shape(const std::vector<std::int64_t>& v) {
19-
std::stringstream ss("");
20-
for (std::size_t i = 0; i < v.size() - 1; i++) {
21-
ss << v[i] << "x";
22-
}
23-
ss << v[v.size() - 1];
24-
return ss.str();
25-
}
18+
#ifndef UNITY_BUILD_UNIQUE_ID
19+
#define UNITY_BUILD_UNIQUE_ID
20+
#endif
2621

27-
template <typename T>
28-
Ort::Value vec_to_tensor(std::vector<T>& data, const std::vector<std::int64_t>& shape) {
29-
Ort::MemoryInfo mem_info = Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtArenaAllocator,
30-
OrtMemType::OrtMemTypeDefault);
31-
auto tensor =
32-
Ort::Value::CreateTensor<T>(mem_info, data.data(), data.size(), shape.data(), shape.size());
33-
return tensor;
34-
}
22+
namespace {
23+
namespace UNITY_BUILD_UNIQUE_ID {
24+
25+
static std::string print_shape(const std::vector<std::int64_t>& v) {
26+
std::stringstream ss("");
27+
for (std::size_t i = 0; i < v.size() - 1; i++) {
28+
ss << v[i] << "x";
29+
}
30+
ss << v[v.size() - 1];
31+
return ss.str();
32+
}
33+
34+
template <typename T>
35+
Ort::Value vec_to_tensor(std::vector<T>& data, const std::vector<std::int64_t>& shape) {
36+
Ort::MemoryInfo mem_info = Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtArenaAllocator,
37+
OrtMemType::OrtMemTypeDefault);
38+
auto tensor = Ort::Value::CreateTensor<T>(mem_info, data.data(), data.size(), shape.data(),
39+
shape.size());
40+
return tensor;
41+
}
42+
43+
} // namespace UNITY_BUILD_UNIQUE_ID
44+
} // namespace
3545

3646
void InclusiveKinematicsML::init() {
47+
using namespace UNITY_BUILD_UNIQUE_ID;
48+
3749
// onnxruntime setup
3850
m_env = Ort::Env(ORT_LOGGING_LEVEL_WARNING, "inclusive-kinematics-ml");
3951
Ort::SessionOptions session_options;
@@ -89,6 +101,8 @@ void InclusiveKinematicsML::init() {
89101
void InclusiveKinematicsML::process(const InclusiveKinematicsML::Input& input,
90102
const InclusiveKinematicsML::Output& output) const {
91103

104+
using namespace UNITY_BUILD_UNIQUE_ID;
105+
92106
const auto [electron, da] = input;
93107
auto [ml] = output;
94108

src/algorithms/onnx/ONNXInference.cc

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,54 @@
1818

1919
namespace eicrecon {
2020

21-
static std::string print_shape(const std::vector<std::int64_t>& v) {
22-
std::stringstream ss("");
23-
for (std::size_t i = 0; i < v.size() - 1; i++) {
24-
ss << v[i] << " x ";
25-
}
26-
ss << v[v.size() - 1];
27-
return ss.str();
28-
}
21+
#ifndef UNITY_BUILD_UNIQUE_ID
22+
#define UNITY_BUILD_UNIQUE_ID
23+
#endif
2924

30-
static bool check_shape_consistency(const std::vector<std::int64_t>& shape1,
31-
const std::vector<std::int64_t>& shape2) {
32-
if (shape2.size() != shape1.size()) {
33-
return false;
34-
}
35-
for (std::size_t ix = 0; ix < shape1.size(); ix++) {
36-
if ((shape1[ix] != -1) && (shape2[ix] != -1) && (shape1[ix] != shape2[ix])) {
37-
return false;
25+
namespace {
26+
namespace UNITY_BUILD_UNIQUE_ID {
27+
28+
static std::string print_shape(const std::vector<std::int64_t>& v) {
29+
std::stringstream ss("");
30+
for (std::size_t i = 0; i < v.size() - 1; i++) {
31+
ss << v[i] << " x ";
32+
}
33+
ss << v[v.size() - 1];
34+
return ss.str();
3835
}
39-
}
40-
return true;
41-
}
4236

43-
template <typename T>
44-
static Ort::Value iters_to_tensor(typename std::vector<T>::const_iterator data_begin,
45-
typename std::vector<T>::const_iterator data_end,
46-
std::vector<int64_t>::const_iterator shape_begin,
47-
std::vector<int64_t>::const_iterator shape_end) {
48-
Ort::MemoryInfo mem_info = Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtArenaAllocator,
49-
OrtMemType::OrtMemTypeDefault);
50-
auto tensor =
51-
Ort::Value::CreateTensor<T>(mem_info, const_cast<T*>(&*data_begin), data_end - data_begin,
52-
&*shape_begin, shape_end - shape_begin);
53-
return tensor;
54-
}
37+
static bool check_shape_consistency(const std::vector<std::int64_t>& shape1,
38+
const std::vector<std::int64_t>& shape2) {
39+
if (shape2.size() != shape1.size()) {
40+
return false;
41+
}
42+
for (std::size_t ix = 0; ix < shape1.size(); ix++) {
43+
if ((shape1[ix] != -1) && (shape2[ix] != -1) && (shape1[ix] != shape2[ix])) {
44+
return false;
45+
}
46+
}
47+
return true;
48+
}
49+
50+
template <typename T>
51+
static Ort::Value iters_to_tensor(typename std::vector<T>::const_iterator data_begin,
52+
typename std::vector<T>::const_iterator data_end,
53+
std::vector<int64_t>::const_iterator shape_begin,
54+
std::vector<int64_t>::const_iterator shape_end) {
55+
Ort::MemoryInfo mem_info = Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtArenaAllocator,
56+
OrtMemType::OrtMemTypeDefault);
57+
auto tensor =
58+
Ort::Value::CreateTensor<T>(mem_info, const_cast<T*>(&*data_begin), data_end - data_begin,
59+
&*shape_begin, shape_end - shape_begin);
60+
return tensor;
61+
}
62+
63+
} // namespace UNITY_BUILD_UNIQUE_ID
64+
} // namespace
5565

5666
void ONNXInference::init() {
67+
using namespace UNITY_BUILD_UNIQUE_ID;
68+
5769
// onnxruntime setup
5870
m_env = Ort::Env(ORT_LOGGING_LEVEL_WARNING, name().data());
5971
Ort::SessionOptions session_options;
@@ -106,6 +118,8 @@ void ONNXInference::init() {
106118
void ONNXInference::process(const ONNXInference::Input& input,
107119
const ONNXInference::Output& output) const {
108120

121+
using namespace UNITY_BUILD_UNIQUE_ID;
122+
109123
const auto [in_tensors] = input;
110124
auto [out_tensors] = output;
111125

0 commit comments

Comments
 (0)