From: HailoRT-Automation <98901220+HailoRT-Automation@users.noreply.github.com>
Date: Thu, 29 Jun 2023 12:02:42 +0000 (+0300)
Subject: v4.14.0 (#9)
X-Git-Tag: accepted/tizen/unified/20250310.024602~9
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9bce73eb42bad4da7876f6bafa2521f3c411937e;p=platform%2Fupstream%2Fhailort.git
v4.14.0 (#9)
---
diff --git a/.hailort.jpg b/.hailort.jpg
new file mode 100644
index 0000000..84d2988
Binary files /dev/null and b/.hailort.jpg differ
diff --git a/.hailort.png b/.hailort.png
deleted file mode 100644
index c9adb26..0000000
Binary files a/.hailort.png and /dev/null differ
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f44f4fc..55d54df 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,20 +14,12 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
In order to build, please create a new `build` directory and run `cmake ..` from there.")
endif()
-# Check build type
-if (NOT CMAKE_BUILD_TYPE)
- message(STATUS "No build type selected, default to Debug")
- set(CMAKE_BUILD_TYPE "Debug")
-endif()
-message(STATUS "Building ${PROJECT_NAME} in ${CMAKE_BUILD_TYPE}")
-
# Set compiler flags in HAILORT_COMPILE_OPTIONS
# TODO: Change HAILORT_COMPILE_OPTIONS to add_compile_options
if(WIN32)
# TODO: set this eventually? set(HAILORT_COMPILE_OPTIONS /Wall)
set(HAILORT_COMPILE_OPTIONS ${HAILORT_COMPILE_OPTIONS}
/W4
- /WX
/DWIN32_LEAN_AND_MEAN
/DNOMINMAX # NOMINMAX is required in order to play nice with std::min/std::max (otherwise Windows.h defines it's own)
/D_HAILO_EXPORTING
@@ -37,9 +29,9 @@ if(WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) # Disable "unsafe function" warnings
elseif(UNIX)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "QCC")
- set(HAILORT_COMPILE_OPTIONS ${HAILORT_COMPILE_OPTIONS} -Werror -Wall -Wextra -Wconversion)
+ set(HAILORT_COMPILE_OPTIONS ${HAILORT_COMPILE_OPTIONS} -Wall -Wextra -Wconversion)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
- set(HAILORT_COMPILE_OPTIONS ${HAILORT_COMPILE_OPTIONS} -Werror -Wall -Wextra
+ set(HAILORT_COMPILE_OPTIONS ${HAILORT_COMPILE_OPTIONS} -Wall -Wextra
# TODO: remove me warnings
-Wno-conversion
-Wno-deprecated-declarations # On c structures with deprecated attribute, clang generates implicit move ctor
diff --git a/README.md b/README.md
index 7e3ad5e..ecfe8e0 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,12 @@
-
+
# HailoRT #
HailoRT is a lightweight, production-grade runtime library that runs on the host processor and provides a robust
-user-space runtime library (the HailoRT Library) with intuitive APIs in C/C++ for optimized performance
+user-space library (the HailoRT Library) with intuitive APIs in C/C++ for optimized performance
HailoRT consists of the following main components:
- HailoRT Library.
@@ -42,8 +42,8 @@ Contact information and support is available at [**hailo.ai**](https://hailo.ai/
## About Hailo-8â¢
-Hailo-8 is a deep learning processor for edge devices. The Hailo-8 provides groundbraking efficiency for neural network deployment.
-The Hailo-8 edge AI processor, featuring up to 26 tera-operations per second (TOPS), significantly outperforms all other edge processors.
+Hailo-8 is a deep learning processor for edge devices. The Hailo-8 provides groundbreaking efficiency for neural network deployment.
+The Hailo-8 edge AI processor, featuring up to 26 Tera-Operations-Per-Second (TOPS), significantly outperforms all other edge processors.
Hailo-8 is available in various form-factors, including the Hailo-8 M.2 Module.
The Hailo-8 AI processor is designed to fit into a multitude of smart machines and devices, for a wide variety of sectors including Automotive, Smart Cities, Industry 4.0,
diff --git a/common/include/context_switch_defs.h b/common/include/context_switch_defs.h
index b7a0fe8..cf4858f 100644
--- a/common/include/context_switch_defs.h
+++ b/common/include/context_switch_defs.h
@@ -54,6 +54,9 @@ extern "C" {
(vdma_channel_index) = ((src) & CONTEXT_SWITCH_DEFS__PACKED_VDMA_CHANNEL_ID__VDMA_CHANNEL_INDEX_MASK); \
} while (0)
+#define CONTEXT_SWITCH_DEFS__WRITE_ACTION_BY_TYPE_MAX_SIZE (4)
+
+
#pragma pack(push, 1)
typedef struct {
uint16_t core_bytes_per_buffer;
@@ -104,6 +107,8 @@ typedef enum __attribute__((packed)) {
CONTEXT_SWITCH_DEFS__ACTION_TYPE_OPEN_BOUNDARY_INPUT_CHANNEL,
CONTEXT_SWITCH_DEFS__ACTION_TYPE_OPEN_BOUNDARY_OUTPUT_CHANNEL,
CONTEXT_SWITCH_DEFS__ACTION_TYPE_ENABLE_NMS,
+ CONTEXT_SWITCH_DEFS__ACTION_TYPE_WRITE_DATA_BY_TYPE,
+ CONTEXT_SWITCH_DEFS__ACTION_TYPE_SWITCH_LCU_BATCH,
/* Must be last */
CONTEXT_SWITCH_DEFS__ACTION_TYPE_COUNT
@@ -358,8 +363,33 @@ typedef struct {
typedef struct {
uint8_t nms_unit_index;
uint8_t network_index;
+ uint16_t number_of_classes;
+ uint16_t burst_size;
} CONTEXT_SWITCH_DEFS__enable_nms_action_t;
+typedef enum {
+ WRITE_ACTION_TYPE_GENERAL = 0,
+ WRITE_ACTION_TYPE_WRITE_BATCH = 1,
+
+ /* Must be last */
+ WRITE_ACTION_BY_TYPE_COUNT
+} CONTEXT_SWITCH_DEFS__WRITE_ACTION_TYPE_t;
+
+typedef struct {
+ uint32_t address;
+ uint8_t data_type; //CONTEXT_SWITCH_DEFS__WRITE_ACTION_TYPE_t
+ uint32_t data;
+ uint8_t shift;
+ uint32_t mask;
+ uint8_t network_index;
+} CONTEXT_SWITCH_DEFS__write_data_by_type_action_t;
+
+typedef struct {
+ uint8_t packed_lcu_id;
+ uint8_t network_index;
+ uint32_t kernel_done_count;
+} CONTEXT_SWITCH_DEFS__switch_lcu_batch_action_data_t;
+
#pragma pack(pop)
#ifdef __cplusplus
diff --git a/common/include/control_protocol.h b/common/include/control_protocol.h
index c5889ec..73d31d5 100644
--- a/common/include/control_protocol.h
+++ b/common/include/control_protocol.h
@@ -1017,6 +1017,7 @@ typedef enum {
CONTROL_PROTOCOL__CONTEXT_SWITCH_STATUS_COUNT,
} CONTROL_PROTOCOL__CONTEXT_SWITCH_STATUS_t;
+#define CONTROL_PROTOCOL__INIFINITE_BATCH_COUNT (0)
typedef struct {
uint32_t state_machine_status_length;
uint8_t state_machine_status;
@@ -1024,6 +1025,8 @@ typedef struct {
uint8_t application_index;
uint32_t dynamic_batch_size_length;
uint16_t dynamic_batch_size;
+ uint32_t batch_count_length;
+ uint16_t batch_count;
uint32_t keep_nn_config_during_reset_length;
uint8_t keep_nn_config_during_reset;
} CONTROL_PROTOCOL__change_context_switch_status_request_t;
@@ -1315,6 +1318,8 @@ typedef struct {
uint8_t application_index;
uint32_t dynamic_batch_size_length;
uint16_t dynamic_batch_size;
+ uint32_t batch_count_length;
+ uint16_t batch_count;
uint32_t channels_info_length;
CONTROL_PROTOCOL__hw_infer_channels_info_t channels_info;
} CONTROL_PROTOCOL__change_hw_infer_status_request_t;
diff --git a/common/include/d2h_events.h b/common/include/d2h_events.h
index 6eff396..b9009ef 100644
--- a/common/include/d2h_events.h
+++ b/common/include/d2h_events.h
@@ -57,6 +57,8 @@ typedef enum {
HEALTH_MONITOR_CPU_ECC_FATAL_EVENT_ID,
CONTEXT_SWITCH_BREAKPOINT_REACHED,
HEALTH_MONITOR_CLOCK_CHANGED_EVENT_ID,
+ HW_INFER_MANAGER_INFER_DONE,
+
D2H_EVENT_ID_COUNT /* Must be last*/
} D2H_EVENT_ID_t;
@@ -138,6 +140,12 @@ typedef struct {
#define D2H_EVENT_HEALTH_MONITOR_CLOCK_CHANGED_EVENT_PARAMETER_COUNT (2)
+typedef struct {
+ uint32_t infer_cycles;
+} D2H_EVENT_hw_infer_mamager_infer_done_message_t;
+
+#define D2H_EVENT_HW_INFER_MANAGER_INFER_DONE_PARAMETER_COUNT (1)
+
/* D2H_EVENT__message_parameters_t should be in the same order as hailo_notification_message_parameters_t */
typedef union {
D2H_EVENT_rx_error_event_message_t rx_error_event;
@@ -149,6 +157,7 @@ typedef union {
D2H_EVENT_health_monitor_cpu_ecc_event_message_t health_monitor_cpu_ecc_event;
D2H_EVENT_context_switch_breakpoint_reached_event_massage_t context_switch_breakpoint_reached_event;
D2H_EVENT_health_monitor_clock_changed_event_message_t health_monitor_clock_changed_event;
+ D2H_EVENT_hw_infer_mamager_infer_done_message_t hw_infer_manager_infer_done_event;
} D2H_EVENT__message_parameters_t;
typedef struct {
diff --git a/common/include/firmware_status.h b/common/include/firmware_status.h
index 193bfef..f45d9c1 100644
--- a/common/include/firmware_status.h
+++ b/common/include/firmware_status.h
@@ -411,6 +411,7 @@ Updating rules:
FIRMWARE_STATUS__X(CONTROL_PROTOCOL_STATUS_INVALID_SLEEP_STATE)\
FIRMWARE_STATUS__X(CONTROL_PROTOCOL_STATUS_INVALID_HW_INFER_STATE_LENGTH)\
FIRMWARE_STATUS__X(CONTROL_PROTOCOL_STATUS_INVALID_CHANNELS_INFO_LENGTH)\
+ FIRMWARE_STATUS__X(CONTROL_PROTOCOL_STATUS_INVALID_BATCH_COUNT_LENGTH)\
\
FIRMWARE_MODULE__X(FIRMWARE_MODULE__POWER_MEASUREMENT)\
FIRMWARE_STATUS__X(HAILO_POWER_MEASUREMENT_STATUS_POWER_INIT_ERROR)\
@@ -554,6 +555,7 @@ Updating rules:
FIRMWARE_STATUS__X(PCIE_SERVICE_STATUS_INVALID_H2D_CHANNEL_INDEX)\
FIRMWARE_STATUS__X(PCIE_SERVICE_STATUS_INVALID_D2H_CHANNEL_INDEX)\
FIRMWARE_STATUS__X(PCIE_SERVICE_INVALID_INITIAL_CREDIT_SIZE)\
+ FIRMWARE_STATUS__X(PCIE_SERVICE_ERROR_ADDING_CREDITS_TO_PCIE_CHANNEL)\
\
FIRMWARE_MODULE__X(FIRMWARE_MODULE__FIRMWARE_UPDATE)\
FIRMWARE_STATUS__X(FIRMWARE_UPDATE_STATUS_INVALID_PARAMETERS)\
@@ -753,6 +755,9 @@ Updating rules:
FIRMWARE_STATUS__X(CONTEXT_SWITCH_STATUS_INVALID_DYNAMIC_CONTEXT_COUNT)\
FIRMWARE_STATUS__X(CONTEXT_SWITCH_STATUS_CONTEXT_INDEX_OUT_OF_RANGE)\
FIRMWARE_STATUS__X(CONTEXT_SWITCH_STATUS_TOTAL_PROVIDED_EDGE_LAYERS_LARGER_THEN_EXPECTED)\
+ FIRMWARE_STATUS__X(CONTEXT_SWITCH_STATUS_REACHED_TIMEOUT_WHILE_WAITING_FOR_NETWORK_IDLE)\
+ FIRMWARE_STATUS__X(CONTEXT_SWITCH_STATUS_WRITE_DATA_BY_TYPE_ACTION_INVALID_TYPE)\
+ FIRMWARE_STATUS__X(CONTEXT_SWITCH_STATUS_WRITE_DATA_BY_TYPE_ACTION_INVALID_MEMORY_SPACE)\
\
FIRMWARE_MODULE__X(FIRMWARE_MODULE__D2H_EVENT_MANAGER)\
FIRMWARE_STATUS__X(HAILO_D2H_EVENT_MANAGER_STATUS_MESSAGE_HIGH_PRIORITY_QUEUE_CREATE_FAILED)\
@@ -1010,6 +1015,7 @@ Updating rules:
FIRMWARE_STATUS__X(VDMA_SERVICE_STATUS_INVALID_CONSTANTS)\
FIRMWARE_STATUS__X(VDMA_SERVICE_STATUS_INVALID_CHANNEL_INDEX)\
FIRMWARE_STATUS__X(VDMA_SERVICE_STATUS_INVALID_EDGE_LAYER_DIRECTION)\
+ FIRMWARE_STATUS__X(VDMA_SERVICE_INSUFFICIENT_DESCRIPTORS_COUNT)\
\
FIRMWARE_MODULE__X(FIRMWARE_MODULE__MEMORY_LOGGER)\
FIRMWARE_STATUS__X(MEMORY_LOGGER_STATUS_DEBUG_INSUFFICIENT_MEMORY)\
@@ -1079,6 +1085,9 @@ Updating rules:
FIRMWARE_STATUS__X(NMS_MANAGER_STATUS_INVALID_NETWORK_INDEX)\
FIRMWARE_STATUS__X(NMS_MANAGER_STATUS_INVALID_NMS_UNIT_INDEX)\
FIRMWARE_STATUS__X(NMS_MANAGER_STATUS_INVALID_BATCH_SIZE)\
+ FIRMWARE_STATUS__X(NMS_MANAGER_STATUS_INVALID_NUM_CLASSES_SIZE)\
+ FIRMWARE_STATUS__X(NMS_MANAGER_STATUS_INVALID_BURST_SIZE)\
+ FIRMWARE_STATUS__X(NMS_MANAGER_STATUS_INVALID_LAST_FRAME_IN_BATCH_SIZE)\
\
FIRMWARE_MODULE__X(FIRMWARE_MODULE__CLUSTER_MANAGER)\
FIRMWARE_STATUS__X(CLUSTER_MANAGER_STATUS_INVALID_CLUSTER_INDEX)\
@@ -1087,6 +1096,7 @@ Updating rules:
FIRMWARE_STATUS__X(CLUSTER_MANAGER_STATUS_INVALID_LCU_INDEX)\
FIRMWARE_STATUS__X(CLUSTER_MANAGER_STATUS_INVALID_KERNEL_DONE_ADDRESS)\
FIRMWARE_STATUS__X(CLUSTER_MANAGER_STATUS_RECEIVED_UNEXPECTED_INTERRUPT)\
+ FIRMWARE_STATUS__X(CLUSTER_MANAGER_STATUS_INVALID_NETWORK_INDEX)\
\
FIRMWARE_MODULE__X(FIRMWARE_MODULE__HW_INFER_MANAGER)\
FIRMWARE_STATUS__X(HW_INFER_MANAGER_STATUS_NETWORK_GROUP_NOT_CONFIGURED_BEFORE_INFER_START)\
diff --git a/common/include/utils.h b/common/include/utils.h
index 7e48489..860d1fa 100644
--- a/common/include/utils.h
+++ b/common/include/utils.h
@@ -10,6 +10,8 @@
#ifndef __UTILS_H__
#define __UTILS_H__
+#include
+
/** A compile time assertion check.
*
* Validate at compile time that the predicate is true without
@@ -125,4 +127,20 @@ _PP_ISEMPTY( \
#define MICROSECONDS_IN_MILLISECOND (1000)
+static inline uint8_t ceil_log2(uint32_t n)
+{
+ uint8_t result = 0;
+
+ if (n <= 1) {
+ return 0;
+ }
+
+ while (n > 1) {
+ result++;
+ n = (n + 1) >> 1;
+ }
+
+ return result;
+}
+
#endif /* __UTILS_H__ */
diff --git a/hailort/CMakeLists.txt b/hailort/CMakeLists.txt
index 7d90f9d..5f790bf 100644
--- a/hailort/CMakeLists.txt
+++ b/hailort/CMakeLists.txt
@@ -9,6 +9,18 @@ option(HAILO_BUILD_EXAMPLES "Build examples" OFF)
option(HAILO_OFFLINE_COMPILATION "Don't download external dependencies" OFF)
option(HAILO_BUILD_SERVICE "Build hailort service" OFF)
option(HAILO_BUILD_PROFILER "Build hailort profiler" ON)
+option(HAILO_COMPILE_WARNING_AS_ERROR "Add compilation flag for treating compilation warnings as errors" OFF)
+option(HAILO_SUPPORT_PACKAGING "Create HailoRT package (internal)" OFF)
+
+if (HAILO_COMPILE_WARNING_AS_ERROR)
+ if(WIN32)
+ set(HAILORT_COMPILE_OPTIONS ${HAILORT_COMPILE_OPTIONS} /WX)
+ elseif(UNIX)
+ set(HAILORT_COMPILE_OPTIONS ${HAILORT_COMPILE_OPTIONS} -Werror)
+ else()
+ message(FATAL_ERROR "Unexpeced host, stopping build")
+ endif()
+endif()
# Flag for emulator (FPGA/Veloce)
if(HAILO_BUILD_EMULATOR)
@@ -18,7 +30,7 @@ endif()
# Set firmware version
add_definitions( -DFIRMWARE_VERSION_MAJOR=4 )
-add_definitions( -DFIRMWARE_VERSION_MINOR=13 )
+add_definitions( -DFIRMWARE_VERSION_MINOR=14 )
add_definitions( -DFIRMWARE_VERSION_REVISION=0 )
if(HAILO_BUILD_SERVICE)
add_definitions( -DHAILO_SUPPORT_MULTI_PROCESS )
@@ -78,20 +90,6 @@ set(COMMON_INC_DIR ${PROJECT_SOURCE_DIR}/common/include)
set(DRIVER_INC_DIR ${PROJECT_SOURCE_DIR}/hailort/drivers/common)
set(RPC_DIR ${PROJECT_SOURCE_DIR}/hailort/rpc)
-if(HAILO_BUILD_PYBIND)
- if(NOT PYTHON_EXECUTABLE AND PYBIND11_PYTHON_VERSION)
- # PYBIND11_PYTHON_VERSION is prioritized (not virtual environment) if PYTHON_EXECUTABLE is not set.
- # See https://pybind11.readthedocs.io/en/stable/changelog.html#v2-6-0-oct-21-2020
- if((${CMAKE_VERSION} VERSION_LESS "3.22.0") AND (NOT WIN32))
- find_package(PythonInterp ${PYBIND11_PYTHON_VERSION} REQUIRED)
- set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
- else()
- find_package(Python3 ${PYBIND11_PYTHON_VERSION} REQUIRED EXACT COMPONENTS Interpreter Development)
- set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
- endif()
- endif()
- add_subdirectory(external/pybind11 EXCLUDE_FROM_ALL)
-endif()
add_subdirectory(external/Catch2 EXCLUDE_FROM_ALL)
add_subdirectory(external/CLI11 EXCLUDE_FROM_ALL)
add_subdirectory(external/json EXCLUDE_FROM_ALL)
@@ -128,6 +126,9 @@ endif()
if(HAILO_WIN_DRIVER)
add_subdirectory(drivers/win)
+endif()
+
+if(HAILO_SUPPORT_PACKAGING)
add_subdirectory(packaging)
endif()
diff --git a/hailort/common/CMakeLists.txt b/hailort/common/CMakeLists.txt
index 1056647..b3bed6b 100644
--- a/hailort/common/CMakeLists.txt
+++ b/hailort/common/CMakeLists.txt
@@ -19,6 +19,7 @@ set(SRC_FILES
${CMAKE_CURRENT_SOURCE_DIR}/barrier.cpp
${CMAKE_CURRENT_SOURCE_DIR}/file_utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/string_utils.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/event_internal.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device_measurements.cpp
)
diff --git a/hailort/common/barrier.hpp b/hailort/common/barrier.hpp
index 3062754..1fae129 100644
--- a/hailort/common/barrier.hpp
+++ b/hailort/common/barrier.hpp
@@ -16,6 +16,9 @@
namespace hailort
{
+class Barrier;
+using BarrierPtr = std::shared_ptr;
+
/**
* A barrier is a synchronization object that allows an expected number of threads to block until all of them
* arrive at the barrier.
diff --git a/hailort/common/device_measurements.cpp b/hailort/common/device_measurements.cpp
index 89fd0d3..b498def 100644
--- a/hailort/common/device_measurements.cpp
+++ b/hailort/common/device_measurements.cpp
@@ -56,16 +56,22 @@ Expected> TemperatureMeasurement::create
return ptr;
}
-
TemperatureMeasurement::TemperatureMeasurement(Device &device, hailo_status &status) : BaseMeasurement(device, status)
-{}
+{
+ /* Executing the check only if BaseMeasurement constructor has succeeded */
+ if (HAILO_SUCCESS == status) {
+ status = sanity_check();
+ }
+}
-hailo_status TemperatureMeasurement::start_measurement()
+hailo_status TemperatureMeasurement::sanity_check()
{
- // Checking sensor before starting thread
- auto temp_info = m_device.get_chip_temperature();
- CHECK_EXPECTED_AS_STATUS(temp_info);
+ auto temp_measurement = m_device.get_chip_temperature();
+ return temp_measurement.status();
+}
+hailo_status TemperatureMeasurement::start_measurement()
+{
m_is_thread_running = true;
m_thread = std::thread([this] () {
while (m_is_thread_running.load()) {
@@ -102,14 +108,21 @@ Expected> PowerMeasurement::create_shared(Devi
PowerMeasurement::PowerMeasurement(Device &device, hailo_power_measurement_types_t measurement_type, hailo_status &status)
: BaseMeasurement(device, status), m_measurement_type(measurement_type)
-{}
+{
+ /* Executing the check only if BaseMeasurement constructor has succeeded */
+ if (HAILO_SUCCESS == status) {
+ status = sanity_check();
+ }
+}
-hailo_status PowerMeasurement::start_measurement()
+hailo_status PowerMeasurement::sanity_check()
{
- // Checking sensor before starting thread
- auto power_info = m_device.power_measurement(HAILO_DVM_OPTIONS_AUTO, m_measurement_type);
- CHECK_EXPECTED_AS_STATUS(power_info);
+ auto power_measurement = m_device.power_measurement(HAILO_DVM_OPTIONS_AUTO, m_measurement_type);
+ return power_measurement.status();
+}
+hailo_status PowerMeasurement::start_measurement()
+{
m_is_thread_running = true;
m_thread = std::thread([this] () {
while (m_is_thread_running.load()) {
diff --git a/hailort/common/device_measurements.hpp b/hailort/common/device_measurements.hpp
index 6089be8..a3c266c 100644
--- a/hailort/common/device_measurements.hpp
+++ b/hailort/common/device_measurements.hpp
@@ -38,6 +38,9 @@ protected:
std::atomic_bool m_is_thread_running;
std::mutex m_mutex;
hailort::AccumulatorPtr m_acc;
+
+private:
+ virtual hailo_status sanity_check() = 0;
};
@@ -56,6 +59,9 @@ public:
}
TemperatureMeasurement(hailort::Device &device, hailo_status &status);
+
+private:
+ virtual hailo_status sanity_check() override;
};
@@ -89,6 +95,7 @@ public:
private:
hailo_power_measurement_types_t m_measurement_type;
+ virtual hailo_status sanity_check() override;
};
#endif /* _HAILO_DEVICE_MEASUREMENTS_HPP_ */
diff --git a/hailort/common/ethernet_utils.hpp b/hailort/common/ethernet_utils.hpp
index 108b8a7..eadfaed 100644
--- a/hailort/common/ethernet_utils.hpp
+++ b/hailort/common/ethernet_utils.hpp
@@ -86,13 +86,12 @@ public:
static const uint32_t MAX_INTERFACE_SIZE = IFNAMSIZ;
#endif
- static hailo_status get_interface_from_board_ip(const char *board_ip, char *interface_name, size_t interface_name_length);
- static hailo_status get_ip_from_interface(const char *interface_name, char *ip, size_t ip_length);
+ static Expected get_interface_from_board_ip(const std::string &board_ip);
+ static Expected get_ip_from_interface(const std::string &interface_name);
private:
#if defined(__GNUG__)
- static hailo_status get_interface_from_arp_entry(char *arp_entry, char *interface_name,
- size_t max_interface_name_length);
+ static Expected get_interface_from_arp_entry(char *arp_entry);
#endif
};
diff --git a/hailort/common/event_internal.cpp b/hailort/common/event_internal.cpp
new file mode 100644
index 0000000..e699379
--- /dev/null
+++ b/hailort/common/event_internal.cpp
@@ -0,0 +1,73 @@
+/**
+ * Copyright (c) 2023 Hailo Technologies Ltd. All rights reserved.
+ * Distributed under the MIT license (https://opensource.org/licenses/MIT)
+**/
+/**
+ * @file event_internal.cpp
+ * @brief Internal implementation for events, shared between all os.
+ **/
+
+#include "common/event_internal.hpp"
+#include "common/logger_macros.hpp"
+#include "common/utils.hpp"
+
+namespace hailort
+{
+
+Waitable::Waitable(underlying_waitable_handle_t handle) :
+ m_handle(handle)
+{}
+
+hailo_status Waitable::wait(std::chrono::milliseconds timeout)
+{
+ auto status = wait_for_single_object(m_handle, timeout);
+ if (HAILO_TIMEOUT == status) {
+ LOGGER__TRACE("wait_for_single_object failed with timeout (timeout={}ms)", timeout.count());
+ return status;
+ }
+ CHECK_SUCCESS(status);
+
+ status = post_wait();
+ CHECK_SUCCESS(status);
+
+ return HAILO_SUCCESS;
+}
+
+underlying_waitable_handle_t Waitable::get_underlying_handle()
+{
+ return m_handle;
+}
+
+WaitOrShutdown::WaitOrShutdown(WaitablePtr waitable, EventPtr shutdown_event) :
+ m_waitable(waitable),
+ m_shutdown_event(shutdown_event),
+ m_waitable_group(create_waitable_group(m_waitable, m_shutdown_event))
+{}
+
+hailo_status WaitOrShutdown::wait(std::chrono::milliseconds timeout)
+{
+ auto index = m_waitable_group.wait_any(timeout);
+ if (index.status() == HAILO_TIMEOUT) {
+ return index.status();
+ }
+ CHECK_EXPECTED_AS_STATUS(index);
+
+ assert(index.value() <= WAITABLE_INDEX);
+ return (index.value() == SHUTDOWN_INDEX) ? HAILO_SHUTDOWN_EVENT_SIGNALED : HAILO_SUCCESS;
+}
+
+hailo_status WaitOrShutdown::signal()
+{
+ return m_waitable->signal();
+}
+
+WaitableGroup WaitOrShutdown::create_waitable_group(WaitablePtr waitable, EventPtr shutdown_event)
+{
+ // Note the order - consistent with SHUTDOWN_INDEX, WAITABLE_INDEX.
+ std::vector> waitables;
+ waitables.emplace_back(std::ref(*shutdown_event));
+ waitables.emplace_back(std::ref(*waitable));
+ return waitables;
+}
+
+} /* namespace hailort */
diff --git a/hailort/common/event_internal.hpp b/hailort/common/event_internal.hpp
new file mode 100644
index 0000000..295d4a8
--- /dev/null
+++ b/hailort/common/event_internal.hpp
@@ -0,0 +1,115 @@
+/**
+ * Copyright (c) 2020-2022 Hailo Technologies Ltd. All rights reserved.
+ * Distributed under the MIT license (https://opensource.org/licenses/MIT)
+ **/
+/**
+ * @file event.hpp
+ * @brief Event and Semaphore wrapper objects used for multithreading
+ **/
+
+#ifndef _EVENT_INTERNAL_HPP_
+#define _EVENT_INTERNAL_HPP_
+
+#include "hailo/event.hpp"
+
+#include
+#include
+#include
+#include
+#if defined(__GNUC__)
+#include
+#endif
+
+namespace hailort
+{
+
+// Group of Waitable objects that can be waited for together
+class WaitableGroup final
+{
+public:
+ WaitableGroup(std::vector> &&waitables) :
+ m_waitables(std::move(waitables)),
+ m_waitable_handles(create_waitable_handle_vector(m_waitables))
+ {}
+
+ /**
+ * Waits until any of the given waitables are signaled. Returns the index in the waitables vector
+ * of the signaled waitable with the smallest index value.
+ */
+ Expected wait_any(std::chrono::milliseconds timeout);
+
+private:
+
+#if defined(__linux__)
+ using WaitableHandle = pollfd;
+#else
+ using WaitableHandle = underlying_waitable_handle_t;
+#endif
+
+ static std::vector create_waitable_handle_vector(
+ const std::vector> &waitables)
+ {
+ std::vector waitable_handles;
+ waitable_handles.reserve(waitables.size());
+ for (auto &waitable : waitables) {
+#if defined(__linux__)
+ waitable_handles.emplace_back(pollfd{waitable.get().get_underlying_handle(), POLLIN, 0});
+#else
+ waitable_handles.emplace_back(waitable.get().get_underlying_handle());
+#endif
+ }
+ return waitable_handles;
+ }
+
+ // Initialization dependency
+ std::vector> m_waitables;
+ // Store this vector here to avoid runtime allocations.
+ std::vector m_waitable_handles;
+};
+
+class WaitOrShutdown final
+{
+public:
+ WaitOrShutdown(WaitablePtr waitable, EventPtr shutdown_event);
+ ~WaitOrShutdown() = default;
+
+ WaitOrShutdown(const WaitOrShutdown &other) = delete;
+ WaitOrShutdown &operator=(const WaitOrShutdown &other) = delete;
+ WaitOrShutdown(WaitOrShutdown &&other) noexcept = default;
+ WaitOrShutdown &operator=(WaitOrShutdown &&other) = delete;
+
+ // Waits on waitable or shutdown_event to be signaled:
+ // * If shutdown_event is signaled:
+ // - shutdown_event is not reset
+ // - HAILO_SHUTDOWN_EVENT_SIGNALED is returned
+ // * If waitable is signaled:
+ // - waitable is reset if waitable->is_auto_reset()
+ // - HAILO_SUCCESS is returned
+ // * If both waitable and shutdown_event are signaled:
+ // - shutdown_event is not reset
+ // - waitable is not reset
+ // - HAILO_SHUTDOWN_EVENT_SIGNALED is returned
+ // * If neither are signaled, then HAILO_TIMEOUT is returned
+ // * On any failure an appropriate status shall be returned
+ hailo_status wait(std::chrono::milliseconds timeout);
+ hailo_status signal();
+
+private:
+ static WaitableGroup create_waitable_group(WaitablePtr waitable, EventPtr shutdown_event);
+
+ // Note: We want to guarantee that if the shutdown event is signaled, HAILO_SHUTDOWN_EVENT_SIGNALED will be
+ // returned.
+ // Waitable::wait_any returns the smallest index value of all the signaled objects.
+ // Hence, SHUTDOWN_INDEX must come before WAITABLE_INDEX!
+ static const size_t SHUTDOWN_INDEX = 0;
+ static const size_t WAITABLE_INDEX = 1;
+
+ const WaitablePtr m_waitable;
+ const EventPtr m_shutdown_event;
+
+ WaitableGroup m_waitable_group;
+};
+
+} /* namespace hailort */
+
+#endif /* _EVENT_INTERNAL_HPP_ */
diff --git a/hailort/common/filesystem.hpp b/hailort/common/filesystem.hpp
index 74d6c77..b650b46 100644
--- a/hailort/common/filesystem.hpp
+++ b/hailort/common/filesystem.hpp
@@ -35,6 +35,7 @@ public:
static Expected get_file_modified_time(const std::string &file_path);
static Expected is_directory(const std::string &path);
static hailo_status create_directory(const std::string &dir_path);
+ static hailo_status remove_directory(const std::string &dir_path);
static Expected get_current_dir();
static std::string get_home_directory();
static bool is_path_accesible(const std::string &path);
diff --git a/hailort/common/latency_meter.hpp b/hailort/common/latency_meter.hpp
index c4a141f..5178e1f 100644
--- a/hailort/common/latency_meter.hpp
+++ b/hailort/common/latency_meter.hpp
@@ -29,7 +29,7 @@ public:
using duration = std::chrono::nanoseconds;
using TimestampsArray = CircularArray;
- explicit LatencyMeter(const std::set &output_names, size_t timestamps_list_length) :
+ LatencyMeter(const std::set &output_names, size_t timestamps_list_length) :
m_start_timestamps(timestamps_list_length),
m_latency_count(0),
m_latency_sum(0)
diff --git a/hailort/common/os/posix/ethernet_utils.cpp b/hailort/common/os/posix/ethernet_utils.cpp
index 0908c4d..f675ec5 100644
--- a/hailort/common/os/posix/ethernet_utils.cpp
+++ b/hailort/common/os/posix/ethernet_utils.cpp
@@ -10,6 +10,9 @@
#include "common/utils.hpp"
#include "common/logger_macros.hpp"
#include "common/ethernet_utils.hpp"
+#include "common/socket.hpp"
+
+#include
namespace hailort
{
@@ -20,8 +23,7 @@ namespace hailort
#define ETHERNET_UTILS__ARP_DEVICE_NAME_INDEX (4)
-hailo_status EthernetUtils::get_interface_from_arp_entry(char *arp_entry, char *interface_name,
- size_t max_interface_name_length)
+Expected EthernetUtils::get_interface_from_arp_entry(char *arp_entry)
{
/* This function parses the interface name out from the arp entry
* Each entry is built as follows:
@@ -30,132 +32,62 @@ hailo_status EthernetUtils::get_interface_from_arp_entry(char *arp_entry, char *
* For example:
* 10.0.0.163 0x1 0x2 80:00:de:ad:be:3f * enp1s0
* */
- hailo_status status = HAILO_UNINITIALIZED;
size_t token_counter = 0;
char* token = NULL;
/* Start splitting the arp entry into tokens according to the delimiter */
token = strtok(arp_entry, ETHERNET_UTILS__ARP_ENTRY_DELIMIETERS);
- if (NULL == token) {
- LOGGER__ERROR("Invalid arp entry, could not split it to tokens");
- status = HAILO_ETH_FAILURE;
- goto l_exit;
- }
+ CHECK_AS_EXPECTED(nullptr != token, HAILO_ETH_FAILURE, "Invalid arp entry, could not split it to tokens");
/* Iterate over the tokens until the device name is found */
while (NULL != token) {
token = strtok(NULL, ETHERNET_UTILS__ARP_ENTRY_DELIMIETERS);
if (ETHERNET_UTILS__ARP_DEVICE_NAME_INDEX == token_counter) {
LOGGER__DEBUG("Interface name: {}", token);
- strncpy(interface_name, token, max_interface_name_length);
- break;
+ return std::string(token);
}
token_counter++;
}
- status = HAILO_SUCCESS;
-l_exit:
- return status;
+ return make_unexpected(HAILO_ETH_FAILURE);
}
-hailo_status EthernetUtils::get_interface_from_board_ip(const char *board_ip, char *interface_name, size_t interface_name_length)
+Expected EthernetUtils::get_interface_from_board_ip(const std::string &board_ip)
{
- hailo_status status = HAILO_UNINITIALIZED;
- FILE* arp_file = NULL;
- int fclose_rc = -1;
- char buffer[ETHERNET_UTILS__ARP_MAX_ENTRY_LENGTH] = {};
-
- CHECK_ARG_NOT_NULL(interface_name);
- CHECK_ARG_NOT_NULL(board_ip);
+ std::ifstream arp_file(ETHERNET_UTILS__ARP_FILE, std::ios::in);
+ CHECK_AS_EXPECTED(arp_file, HAILO_OPEN_FILE_FAILURE, "Cannot open file {}. errno: {:#x}", ETHERNET_UTILS__ARP_FILE, errno);
- /* Open arp file */
- arp_file = fopen(ETHERNET_UTILS__ARP_FILE, "r");
- if (NULL == arp_file) {
- LOGGER__ERROR("Cannot open file {}. Errno: {:#x}", ETHERNET_UTILS__ARP_FILE, errno);
- status = HAILO_OPEN_FILE_FAILURE;
- goto l_exit;
- }
+ char buffer[ETHERNET_UTILS__ARP_MAX_ENTRY_LENGTH] = {};
/* Go over all of the lines at the file */
- while(fgets(buffer, ARRAY_LENGTH(buffer), arp_file)) {
- /* Check if the arp line contains the board_ip */
- if (strstr(buffer, board_ip)) {
- status = get_interface_from_arp_entry(buffer, interface_name, interface_name_length);
- if (HAILO_SUCCESS != status) {
- goto l_exit;
- }
- break;
+ while (arp_file.getline(buffer, sizeof(buffer))) {
+ if (strstr(buffer, board_ip.c_str())) {
+ return get_interface_from_arp_entry(buffer);
}
}
- status = HAILO_SUCCESS;
-l_exit:
- if (NULL != arp_file) {
- fclose_rc = fclose(arp_file);
- if (0 != fclose_rc) {
- LOGGER__ERROR("Cannot close arp file {} ", ETHERNET_UTILS__ARP_FILE);
- if (HAILO_SUCCESS == status) {
- status = HAILO_CLOSE_FAILURE;
- } else {
- LOGGER__ERROR("Did not override status. Left status value at: {} (not assigned {}",
- status,
- HAILO_CLOSE_FAILURE);
- }
- }
- }
-
- return status;
+ LOGGER__ERROR("Failed to find interface name for ip {}", board_ip);
+ return make_unexpected(HAILO_ETH_FAILURE);
}
-hailo_status EthernetUtils::get_ip_from_interface(const char *interface_name, char *ip, size_t ip_length)
+Expected EthernetUtils::get_ip_from_interface(const std::string &interface_name)
{
- hailo_status status = HAILO_UNINITIALIZED;
struct ifreq ifr = {};
- int fd = 0;
- int posix_rc = 0;
-
- CHECK_ARG_NOT_NULL(interface_name);
- CHECK_ARG_NOT_NULL(ip);
/* Create socket */
- fd = socket(AF_INET, SOCK_DGRAM, 0);
- if (fd < 0) {
- LOGGER__ERROR("Failed to create socket. Errno: {:#x}", errno);
- status = HAILO_ETH_FAILURE;
- goto l_exit;
- }
+ auto socket = Socket::create(AF_INET, SOCK_DGRAM, 0);
+ CHECK_EXPECTED(socket);
/* Convert interface name to ip address */
ifr.ifr_addr.sa_family = AF_INET;
- (void)strncpy(ifr.ifr_name, interface_name, IFNAMSIZ-1);
- posix_rc = ioctl(fd, SIOCGIFADDR, &ifr);
- if (0 > posix_rc) {
- LOGGER__ERROR("Interface was not found. ioctl with SIOCGIFADDR has failed. Errno: {:#x}", errno);
- status = HAILO_ETH_INTERFACE_NOT_FOUND;
- goto l_exit;
- }
- (void)strncpy(ip, inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr), ip_length);
- LOGGER__DEBUG("Interface {} | IP: {}", interface_name, ip);
-
- status = HAILO_SUCCESS;
-l_exit:
- /* Close the socket if it was created */
- if (0 < fd) {
- posix_rc = close(fd);
- if (0 != posix_rc) {
- LOGGER__ERROR("Failed closing socket. Errno: {:#x}", errno);
- /* Update status if only in case there was not previous error */
- if (HAILO_SUCCESS == status) {
- status = HAILO_CLOSE_FAILURE;
- } else {
- LOGGER__ERROR("Did not override status. Left status value at: {} (not assigned {}",
- status,
- HAILO_CLOSE_FAILURE);
- }
- }
- }
-
- return status;
+ (void)strncpy(ifr.ifr_name, interface_name.c_str(), IFNAMSIZ-1);
+ auto posix_rc = ioctl(socket->get_fd(), SIOCGIFADDR, &ifr);
+ CHECK_AS_EXPECTED(posix_rc >= 0, HAILO_ETH_INTERFACE_NOT_FOUND,
+ "Interface was not found. ioctl with SIOCGIFADDR has failed. errno: {:#x}", errno);
+
+ std::string res = inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
+ LOGGER__DEBUG("Interface {} | IP: {}", interface_name, res);
+ return res;
}
} /* namespace hailort */
diff --git a/hailort/common/os/posix/filesystem.cpp b/hailort/common/os/posix/filesystem.cpp
index 1a41347..57a12ac 100644
--- a/hailort/common/os/posix/filesystem.cpp
+++ b/hailort/common/os/posix/filesystem.cpp
@@ -165,6 +165,13 @@ hailo_status Filesystem::create_directory(const std::string &dir_path)
return HAILO_SUCCESS;
}
+hailo_status Filesystem::remove_directory(const std::string &dir_path)
+{
+ auto ret_val = rmdir(dir_path.c_str());
+ CHECK(0 == ret_val, HAILO_FILE_OPERATION_FAILURE, "Failed to remove directory {}", dir_path);
+ return HAILO_SUCCESS;
+}
+
Expected Filesystem::get_current_dir()
{
char cwd[PATH_MAX];
diff --git a/hailort/common/os/posix/os_utils.cpp b/hailort/common/os/posix/os_utils.cpp
index 36f1819..c9b0e98 100644
--- a/hailort/common/os/posix/os_utils.cpp
+++ b/hailort/common/os/posix/os_utils.cpp
@@ -8,15 +8,20 @@
**/
#include "hailo/hailort.h"
-
#include "common/os_utils.hpp"
-
+#include "common/utils.hpp"
#include "spdlog/sinks/syslog_sink.h"
+#include
+#include
+#include
+
namespace hailort
{
+#define EXISTENCE_CHECK_SIGNAL (0)
+
HailoRTOSLogger::HailoRTOSLogger()
{
m_hailort_os_logger = spdlog::syslog_logger_mt("syslog", "hailort_service", LOG_PID);
@@ -29,6 +34,46 @@ uint32_t OsUtils::get_curr_pid()
return getpid();
}
+bool OsUtils::is_pid_alive(uint32_t pid)
+{
+ return (0 == kill(pid, EXISTENCE_CHECK_SIGNAL));
+}
+
+void OsUtils::set_current_thread_name(const std::string &name)
+{
+ (void)name;
+#ifndef NDEBUG
+ // pthread_setname_np name size is limited to 16 chars (including null terminator)
+ assert(name.size() < 16);
+ pthread_setname_np(pthread_self(), name.c_str());
+#endif /* NDEBUG */
+}
+
+hailo_status OsUtils::set_current_thread_affinity(uint8_t cpu_index)
+{
+#if defined(__linux__)
+ cpu_set_t cpuset;
+ CPU_ZERO(&cpuset);
+ CPU_SET(cpu_index, &cpuset);
+
+ static const pid_t CURRENT_THREAD = 0;
+ int rc = sched_setaffinity(CURRENT_THREAD, sizeof(cpu_set_t), &cpuset);
+ CHECK(rc == 0, HAILO_INTERNAL_FAILURE, "sched_setaffinity failed with status {}", rc);
+
+ return HAILO_SUCCESS;
+#elif defined(__QNX__)
+ (void)cpu_index;
+ // TODO: impl on qnx (HRT-10889)
+ return HAILO_NOT_IMPLEMENTED;
+#endif
+}
+
+size_t OsUtils::get_page_size()
+{
+ static const auto page_size = sysconf(_SC_PAGESIZE);
+ return page_size;
+}
+
CursorAdjustment::CursorAdjustment(){}
CursorAdjustment::~CursorAdjustment(){}
diff --git a/hailort/common/os/posix/traffic_control.cpp b/hailort/common/os/posix/traffic_control.cpp
index fccbbc9..71aa3f4 100644
--- a/hailort/common/os/posix/traffic_control.cpp
+++ b/hailort/common/os/posix/traffic_control.cpp
@@ -22,7 +22,7 @@ namespace hailort
Expected TrafficControlUtil::create(const std::string &ip, uint16_t port, uint32_t rate_bytes_per_sec)
{
- auto interface_name = get_interface_name(ip);
+ auto interface_name = EthernetUtils::get_interface_from_board_ip(ip);
CHECK_EXPECTED(interface_name, "get_interface_name failed with status {}", interface_name.status());
auto board_id = ip_to_board_id(ip);
@@ -158,17 +158,6 @@ hailo_status TrafficControlUtil::tc_class_del_dev_for_board(const std::string &i
return run_command(cmd.str(), m_is_sudo_needed, {}, true);
}
-Expected TrafficControlUtil::get_interface_name(const std::string &ip)
-{
- auto interface_name = Buffer::create(EthernetUtils::MAX_INTERFACE_SIZE, 0);
- CHECK_EXPECTED(interface_name);
-
- CHECK_SUCCESS_AS_EXPECTED(EthernetUtils::get_interface_from_board_ip(ip.c_str(),
- interface_name->as_pointer(), interface_name->size()));
-
- return interface_name->to_string();
-}
-
Expected TrafficControlUtil::ip_to_board_id(const std::string &ip)
{
// Takes last digit from 3 octet + the whole 4th octet
diff --git a/hailort/common/os/posix/traffic_control.hpp b/hailort/common/os/posix/traffic_control.hpp
index cbca2e8..82cbfff 100644
--- a/hailort/common/os/posix/traffic_control.hpp
+++ b/hailort/common/os/posix/traffic_control.hpp
@@ -23,7 +23,6 @@ class TrafficControlUtil final
{
public:
static Expected create(const std::string &ip, uint16_t port, uint32_t rate_bytes_per_sec);
- static Expected get_interface_name(const std::string &ip);
~TrafficControlUtil() = default;
TrafficControlUtil(TrafficControlUtil&) = delete;
TrafficControlUtil &operator=(const TrafficControlUtil &) = delete;
diff --git a/hailort/common/os/windows/ethernet_utils.cpp b/hailort/common/os/windows/ethernet_utils.cpp
index 8fec8d4..4dcfd3f 100644
--- a/hailort/common/os/windows/ethernet_utils.cpp
+++ b/hailort/common/os/windows/ethernet_utils.cpp
@@ -160,48 +160,40 @@ Expected ArpTable::create(uint32_t interface_index)
return result;
}
-hailo_status EthernetUtils::get_interface_from_board_ip(const char *board_ip, char *interface_name, size_t interface_name_length)
+Expected EthernetUtils::get_interface_from_board_ip(const std::string &board_ip)
{
- CHECK_ARG_NOT_NULL(interface_name);
- CHECK_ARG_NOT_NULL(board_ip);
-
auto network_interfaces = NetworkInterface::get_all_interfaces();
- CHECK_EXPECTED_AS_STATUS(network_interfaces);
+ CHECK_EXPECTED(network_interfaces);
struct in_addr board_ip_struct{};
- auto status = Socket::pton(AF_INET, board_ip, &board_ip_struct);
- CHECK_SUCCESS(status, "Invalid board ip address {}", board_ip);
+ auto status = Socket::pton(AF_INET, board_ip.c_str(), &board_ip_struct);
+ CHECK_SUCCESS_AS_EXPECTED(status, "Invalid board ip address {}", board_ip);
for (const auto& network_interface : network_interfaces.value()) {
auto arp_table = ArpTable::create(network_interface.index());
- CHECK_EXPECTED_AS_STATUS(arp_table);
+ CHECK_EXPECTED(arp_table);
const auto mac_address = arp_table->get_mac_address(static_cast(board_ip_struct.S_un.S_addr));
if (mac_address) {
- (void)strncpy(interface_name, network_interface.friendly_name().c_str(), interface_name_length);
- return HAILO_SUCCESS;
+ return network_interface.friendly_name();
}
}
- return HAILO_ETH_INTERFACE_NOT_FOUND;
+ return make_unexpected(HAILO_ETH_INTERFACE_NOT_FOUND);
}
-hailo_status EthernetUtils::get_ip_from_interface(const char *interface_name, char *ip, size_t ip_length)
+Expected EthernetUtils::get_ip_from_interface(const std::string &interface_name)
{
- CHECK_ARG_NOT_NULL(interface_name);
- CHECK_ARG_NOT_NULL(ip);
-
auto network_interfaces = NetworkInterface::get_all_interfaces();
- CHECK_EXPECTED_AS_STATUS(network_interfaces);
+ CHECK_EXPECTED(network_interfaces);
for (const auto& network_interface : network_interfaces.value()) {
if (network_interface.friendly_name() == interface_name) {
- (void)strncpy(ip, network_interface.ip().c_str(), ip_length);
- return HAILO_SUCCESS;
+ return network_interface.ip();
}
}
- return HAILO_ETH_INTERFACE_NOT_FOUND;
+ return make_unexpected(HAILO_ETH_INTERFACE_NOT_FOUND);
}
} /* namespace hailort */
diff --git a/hailort/common/os/windows/filesystem.cpp b/hailort/common/os/windows/filesystem.cpp
index d9adeae..6dbcc25 100644
--- a/hailort/common/os/windows/filesystem.cpp
+++ b/hailort/common/os/windows/filesystem.cpp
@@ -164,6 +164,13 @@ hailo_status Filesystem::create_directory(const std::string &dir_path)
return HAILO_SUCCESS;
}
+hailo_status Filesystem::remove_directory(const std::string &dir_path)
+{
+ bool was_removed = RemoveDirectoryA(dir_path.c_str());
+ CHECK(was_removed, HAILO_FILE_OPERATION_FAILURE, "Failed to remove directory {}", dir_path);
+ return HAILO_SUCCESS;
+}
+
bool Filesystem::is_path_accesible(const std::string &path)
{
// The code is based on examples from: https://cpp.hotexamples.com/examples/-/-/AccessCheck/cpp-accesscheck-function-examples.html
diff --git a/hailort/common/os/windows/os_utils.cpp b/hailort/common/os/windows/os_utils.cpp
index 3146d31..3d4022f 100644
--- a/hailort/common/os/windows/os_utils.cpp
+++ b/hailort/common/os/windows/os_utils.cpp
@@ -8,6 +8,7 @@
**/
#include "common/os_utils.hpp"
+#include "common/utils.hpp"
#include "hailo/hailort.h"
#include
@@ -29,6 +30,54 @@ uint32_t OsUtils::get_curr_pid()
return static_cast(GetCurrentProcessId());
}
+bool OsUtils::is_pid_alive(uint32_t pid)
+{
+ HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
+ if (hProcess == NULL) {
+ // Process is not running
+ return false;
+ }
+
+ DWORD exitCode;
+ BOOL result = GetExitCodeProcess(hProcess, &exitCode);
+
+ CloseHandle(hProcess);
+
+ if (result && exitCode == STILL_ACTIVE) {
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+void OsUtils::set_current_thread_name(const std::string &name)
+{
+ (void)name;
+}
+
+hailo_status OsUtils::set_current_thread_affinity(uint8_t cpu_index)
+{
+ const DWORD_PTR affinity_mask = static_cast(1ULL << cpu_index);
+ CHECK(0 != SetThreadAffinityMask(GetCurrentThread(), affinity_mask), HAILO_INTERNAL_FAILURE,
+ "SetThreadAffinityMask failed. LE={}", GetLastError());
+
+ return HAILO_SUCCESS;
+}
+
+static size_t get_page_size_impl()
+{
+ SYSTEM_INFO system_info{};
+ GetSystemInfo(&system_info);
+ return system_info.dwPageSize;
+}
+
+size_t OsUtils::get_page_size()
+{
+ static const auto page_size = get_page_size_impl();
+ return page_size;
+}
+
CursorAdjustment::CursorAdjustment()
{
// Enables Vitual Terminal Processing - enables ANSI Escape Sequences on Windows
diff --git a/hailort/common/os_utils.hpp b/hailort/common/os_utils.hpp
index 30d0c2e..025ef1d 100644
--- a/hailort/common/os_utils.hpp
+++ b/hailort/common/os_utils.hpp
@@ -57,22 +57,12 @@ class OsUtils final
{
public:
OsUtils() = delete;
- static uint32_t get_curr_pid();
-
- static void set_current_thread_name(const std::string &name)
- {
- (void)name;
-#ifndef NDEBUG
-#ifndef _WIN32
- // pthread_setname_np name size is limited to 16 chars (including null terminator)
- assert(name.size() < 16);
- pthread_setname_np(pthread_self(), name.c_str());
-#else
-// TODO: implement for windows
-#endif /* _WIN32 */
-#endif /* NDEBUG */
- }
+ static uint32_t get_curr_pid();
+ static bool is_pid_alive(uint32_t pid);
+ static void set_current_thread_name(const std::string &name);
+ static hailo_status set_current_thread_affinity(uint8_t cpu_index);
+ static size_t get_page_size();
};
} /* namespace hailort */
diff --git a/hailort/common/socket.hpp b/hailort/common/socket.hpp
index 8df9daf..afe0afd 100644
--- a/hailort/common/socket.hpp
+++ b/hailort/common/socket.hpp
@@ -42,6 +42,8 @@ public:
m_module_wrapper(std::move(other.m_module_wrapper)), m_socket_fd(std::exchange(other.m_socket_fd, INVALID_SOCKET))
{};
+ socket_t get_fd() { return m_socket_fd; }
+
static hailo_status ntop(int af, const void *src, char *dst, socklen_t size);
static hailo_status pton(int af, const char *src, void *dst);
diff --git a/hailort/common/utils.hpp b/hailort/common/utils.hpp
index 3dd3bc6..a285651 100644
--- a/hailort/common/utils.hpp
+++ b/hailort/common/utils.hpp
@@ -18,6 +18,7 @@
#include
#include