Skip to content

Commit 1ce2095

Browse files
committed
Move processor querying from CommonFramework/ -> Common/
1 parent 8eb269e commit 1ce2095

14 files changed

Lines changed: 106 additions & 63 deletions

File tree

Common/Cpp/Hardware/Hardware.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* Hardware
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include <algorithm>
8+
#include "Common/Cpp/CpuId/CpuId.h"
9+
#include "Hardware.h"
10+
11+
#if _M_IX86 || _M_X64 || __i386__ || __x86_64__
12+
#include "Hardware_x86.tpp"
13+
#endif
14+
15+
#if _WIN32
16+
#ifdef PA_ARCH_x86
17+
#include "Hardware_x86_Windows.tpp"
18+
#endif
19+
#endif
20+
21+
#if defined(__linux) || defined(__APPLE__)
22+
#ifdef PA_ARCH_x86
23+
#include "Hardware_x86_Linux.tpp"
24+
#elif PA_ARCH_arm64
25+
#include "Hardware_arm64_Linux.tpp"
26+
#endif
27+
#endif
28+
29+
30+
namespace PokemonAutomation{
31+
32+
33+
34+
35+
36+
37+
}

Common/Cpp/Hardware/Hardware.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* Hardware
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_Hardware_H
8+
#define PokemonAutomation_Hardware_H
9+
10+
#include <string>
11+
12+
13+
namespace PokemonAutomation{
14+
15+
16+
17+
18+
std::string get_processor_name();
19+
struct ProcessorSpecs{
20+
std::string name;
21+
size_t threads = 0;
22+
size_t cores = 0;
23+
size_t sockets = 0;
24+
size_t numa_nodes = 0;
25+
size_t base_frequency = 0;
26+
};
27+
ProcessorSpecs get_processor_specs();
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
}
38+
#endif

SerialPrograms/Source/CommonFramework/Environment/Environment_arm64_Linux.tpp renamed to Common/Cpp/Hardware/Hardware_arm64_Linux.tpp

File renamed without changes.

SerialPrograms/Source/CommonFramework/Environment/Environment_x86.tpp renamed to Common/Cpp/Hardware/Hardware_x86.tpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
#include "Common/Cpp/CpuId/CpuId_x86.h"
8-
#include "Environment.h"
8+
#include "Hardware.h"
99

1010
namespace PokemonAutomation{
1111

SerialPrograms/Source/CommonFramework/Environment/Environment_x86_Linux.tpp renamed to Common/Cpp/Hardware/Hardware_x86_Linux.tpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
#include "Common/Cpp/Exceptions.h"
1616
#include "Common/Cpp/Time.h"
1717
#include "CommonFramework/Logging/Logger.h"
18-
#include "Environment.h"
18+
#include "Hardware.h"
1919

2020
#ifndef cpuid_H
2121
#define cpuid_H
2222
#include <cpuid.h>
2323
#endif
2424

25-
#include "Environment.h"
26-
2725
namespace PokemonAutomation{
2826

2927

SerialPrograms/Source/CommonFramework/Environment/Environment_x86_Windows.tpp renamed to Common/Cpp/Hardware/Hardware_x86_Windows.tpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <thread>
1818
#include <nmmintrin.h>
1919
#include "Common/Cpp/Exceptions.h"
20-
#include "Environment.h"
20+
#include "Hardware.h"
2121

2222
namespace PokemonAutomation{
2323

SerialPrograms/CMakeLists.txt

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -343,26 +343,25 @@ if (WIN32)
343343
else() # macOS and Linux
344344
find_package(PkgConfig REQUIRED) # required to execute `pkg_search_module()` below
345345
if (APPLE)
346-
# prepare onnxruntime if needed
347-
set(ONNXRUNTIME_VERSION "1.23.2")
348-
set(ONNXRUNTIME_WORK_DIR "${REPO_ROOT_DIR}/3rdPartyBinaries")
349-
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
350-
set(ONNXRUNTIME_ARCH "arm64")
346+
# ==== Get ONNX Runtime paths ====
347+
# First, try to see if there is an ONNX Runtime library built from source.
348+
# Assume the onnxruntime repo, https://github.com/microsoft/onnxruntime is placed in the same folder as
349+
# this Arduino-Source repo:
350+
set(ONNXRUNTIME_ROOTDIR "${REPO_ROOT_DIR}../onnxruntime/")
351+
set(ONNXRUNTIME_HEADER_DIR "${ONNXRUNTIME_ROOTDIR}include/onnxruntime/core/session/")
352+
if(EXISTS "${ONNXRUNTIME_HEADER_DIR}")
353+
# we have ONNX Runtime built from source
354+
message("Use ONNX Runtime built from source at ${ONNXRUNTIME_ROOTDIR}")
355+
target_include_directories(SerialProgramsLib PRIVATE ${ONNXRUNTIME_HEADER_DIR})
356+
target_link_libraries(SerialProgramsLib PRIVATE ${ONNXRUNTIME_ROOTDIR}/build/MacOS/Release/libonnxruntime.dylib)
351357
else()
352-
set(ONNXRUNTIME_ARCH "x86_64")
358+
message("Built-from-source ONNX Runtime folder ${ONNXRUNTIME_ROOTDIR} does not exist.")
359+
message("Use ONNX Runtime installed by Homebrew.")
360+
pkg_search_module(ONNXRUNTIME REQUIRED libonnxruntime onnxruntime)
361+
target_include_directories(SerialProgramsLib PRIVATE ${ONNXRUNTIME_INCLUDE_DIRS})
362+
target_link_directories(SerialProgramsLib PUBLIC ${ONNXRUNTIME_LIBRARY_DIRS})
363+
target_link_libraries(SerialProgramsLib PUBLIC ${ONNXRUNTIME_LINK_LIBRARIES})
353364
endif()
354-
set(ONNXRUNTIME_LIB_DIR "${ONNXRUNTIME_WORK_DIR}/onnxruntime-osx-${ONNXRUNTIME_ARCH}-${ONNXRUNTIME_VERSION}")
355-
set(ONNXRUNTIME_LIB_TAR "${ONNXRUNTIME_LIB_DIR}.tgz")
356-
set(ONNXRUNTIME_DYLIB "${ONNXRUNTIME_LIB_DIR}/lib/libonnxruntime.dylib")
357-
if (NOT EXISTS "${ONNXRUNTIME_LIB_DIR}")
358-
message(STATUS "ONNXRUNTIME not found, extracting from tgz...")
359-
execute_process(
360-
COMMAND ${CMAKE_COMMAND} -E tar xf "${ONNXRUNTIME_LIB_TAR}"
361-
WORKING_DIRECTORY "${ONNXRUNTIME_WORK_DIR}"
362-
)
363-
endif()
364-
target_include_directories(SerialProgramsLib SYSTEM PRIVATE "${ONNXRUNTIME_LIB_DIR}/include")
365-
target_link_libraries(SerialProgramsLib PRIVATE "${ONNXRUNTIME_DYLIB}")
366365
else() # Linux
367366
# ONNX RUNTIME LINUX CONFIG
368367
# NOTE: users can specify their own ONNX_ROOT_PATH (this is the base folder for ONNX) on the command line when evoking cmake.
@@ -506,7 +505,7 @@ else() # macOS and Linux
506505
target_compile_options(SerialProgramsLib PRIVATE -Wall -Wextra -Wpedantic -Werror -fno-strict-aliasing)
507506
endif()
508507

509-
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
508+
IF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
510509
# Arm CPU
511510
# Run-time ISA dispatching
512511
target_compile_definitions(SerialProgramsLib PRIVATE PA_AutoDispatch_arm64_20_M1)

SerialPrograms/Source/CommonFramework/Environment/Environment.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,14 @@
44
*
55
*/
66

7-
#include <algorithm>
8-
#include "Common/Cpp/CpuId/CpuId.h"
97
#include "Environment.h"
108

11-
#if _M_IX86 || _M_X64 || __i386__ || __x86_64__
12-
#include "Environment_x86.tpp"
13-
#endif
14-
159
#if _WIN32
1610
#include "Environment_Windows.tpp"
17-
#ifdef PA_ARCH_x86
18-
#include "Environment_x86_Windows.tpp"
19-
#endif
2011
#endif
2112

2213
#if defined(__linux) || defined(__APPLE__)
2314
#include "Environment_Linux.tpp"
24-
#ifdef PA_ARCH_x86
25-
#include "Environment_x86_Linux.tpp"
26-
#elif PA_ARCH_arm64
27-
#include "Environment_arm64_Linux.tpp"
28-
#endif
2915
#endif
3016

3117

SerialPrograms/Source/CommonFramework/Environment/Environment.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,6 @@ class ThreadHandle;
3131

3232

3333

34-
std::string get_processor_name();
35-
struct ProcessorSpecs{
36-
std::string name;
37-
size_t threads = 0;
38-
size_t cores = 0;
39-
size_t sockets = 0;
40-
size_t numa_nodes = 0;
41-
size_t base_frequency = 0;
42-
};
43-
ProcessorSpecs get_processor_specs();
44-
45-
46-
4734

4835

4936

SerialPrograms/Source/CommonFramework/Environment/Environment_Windows.tpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
#ifdef _WIN32
88

9-
#include <map>
10-
#include <iostream>
11-
#include <thread>
129
#include <Windows.h>
1310
#include "Common/Cpp/Exceptions.h"
14-
#include "CommonFramework/Logging/Logger.h"
11+
#include "Common/Cpp/Logging/AbstractLogger.h"
1512
#include "Environment.h"
1613
#include "Environment_Windows.h"
1714

0 commit comments

Comments
 (0)