Skip to content

Commit

Permalink
[CPU] CACHE_DIR hash optimization (#25624)
Browse files Browse the repository at this point in the history
### Details:
 - *JIT implementation of the hash function in the ConstantWriter*

### Tickets:
 - *127331*
  • Loading branch information
nshchego authored Oct 21, 2024
1 parent d34cdda commit 5f4a445
Show file tree
Hide file tree
Showing 10 changed files with 1,410 additions and 89 deletions.
5 changes: 4 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ target_include_directories(openvino_core_dev INTERFACE
$<BUILD_INTERFACE:${OpenVINO_SOURCE_DIR}/src/common/transformations/include>
$<BUILD_INTERFACE:${OpenVINO_SOURCE_DIR}/src/common/low_precision_transformations/include>)

target_include_directories(openvino_core_dev SYSTEM INTERFACE
$<BUILD_INTERFACE:$<$<TARGET_EXISTS:xbyak::xbyak>:$<TARGET_PROPERTY:xbyak::xbyak,INTERFACE_INCLUDE_DIRECTORIES>>>)

target_link_libraries(openvino_core_dev INTERFACE openvino::itt openvino::util)

set_target_properties(openvino_core_dev PROPERTIES EXPORT_NAME core::dev)
Expand Down Expand Up @@ -81,7 +84,7 @@ if(ENABLE_SYSTEM_PUGIXML)
set_target_properties(openvino_core_obj PROPERTIES NO_SYSTEM_FROM_IMPORTED ON)
endif()

target_compile_definitions(openvino_core_obj PRIVATE IMPLEMENT_OPENVINO_API)
target_compile_definitions(openvino_core_obj PRIVATE IMPLEMENT_OPENVINO_API XBYAK_NO_OP_NAMES XBYAK64)

ov_build_target_faster(openvino_core_obj
UNITY
Expand Down
20 changes: 20 additions & 0 deletions src/core/dev_api/openvino/runtime/compute_hash.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <cstddef>

namespace ov {
namespace runtime {

/**
* @brief Computes the hash value for the input data
* @param src A pointer to the input data
* @param size The length of the input data in bytes
*/
size_t compute_hash(const void* src, size_t size);

} // namespace runtime
} // namespace ov
3 changes: 0 additions & 3 deletions src/core/reference/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ target_include_directories(${TARGET_NAME} PUBLIC
$<BUILD_INTERFACE:${OV_CORE_DEV_API_PATH}>
$<BUILD_INTERFACE:${OV_CORE_INCLUDE_PATH}>)

target_include_directories(${TARGET_NAME} SYSTEM PRIVATE
$<BUILD_INTERFACE:$<$<TARGET_EXISTS:xbyak::xbyak>:$<TARGET_PROPERTY:xbyak::xbyak,INTERFACE_INCLUDE_DIRECTORIES>>>)

find_package(Threads REQUIRED)
target_link_libraries(${TARGET_NAME} PRIVATE Threads::Threads openvino::core::dev)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,66 +15,69 @@
namespace ov {
namespace reference {
namespace jit {
#ifdef XBYAK64
static const Xbyak::Operand::Code abi_save_gpr_regs[] = {
Xbyak::Operand::RBX,
Xbyak::Operand::RBP,
Xbyak::Operand::R12,
Xbyak::Operand::R13,
Xbyak::Operand::R14,
Xbyak::Operand::R15,
# ifdef _WIN32
#ifdef _WIN32
Xbyak::Operand::RDI,
Xbyak::Operand::RSI,
# endif
#endif
};

# ifdef _WIN32
# define abi_param1 Xbyak::Reg64(Xbyak::Operand::RCX) // RCX
# else
# define abi_param1 Xbyak::Reg64(Xbyak::Operand::RDI) // RDI
# endif
#endif // XBYAK64
#ifdef _WIN32
# define abi_param1 Xbyak::Reg64(Xbyak::Operand::RCX) // RCX
#else
# define abi_param1 Xbyak::Reg64(Xbyak::Operand::RDI) // RDI
#endif

class Generator : public Xbyak::CodeGenerator {
static constexpr size_t xmm_len = 16;
typedef enum {
isa_any,
sse42,
avx,
avx2,
avx512_common,
avx512_core,
avx512_core_vnni,
avx512_mic,
avx512_mic_4ops,
avx512_core_bf16,
avx512_vpopcnt,
fp16,
pclmulqdq,
vpclmulqdq
} cpu_isa_t;

class Generator : public Xbyak::CodeGenerator {
#ifdef _WIN32
static constexpr size_t xmm_to_preserve_start = 6;
static constexpr size_t xmm_to_preserve = 10;
static constexpr size_t xmm_to_preserve_start = 6llu;
static constexpr size_t xmm_to_preserve = 10llu;
#else
static constexpr size_t xmm_to_preserve_start = 0;
static constexpr size_t xmm_to_preserve = 0;
static constexpr size_t xmm_to_preserve_start = 0lu;
static constexpr size_t xmm_to_preserve = 0lu;
#endif

static const size_t num_abi_save_gpr_regs = sizeof(abi_save_gpr_regs) / sizeof(abi_save_gpr_regs[0]);
const size_t size_of_abi_save_regs;

const Xbyak::Reg64 reg_EVEX_max_8b_offt;
static constexpr int EVEX_max_8b_offt = 0x200;
size_t m_vlen = ymm_len;

public:
const Xbyak::Reg64 param = abi_param1;
static constexpr size_t xmm_len = 16lu;
static constexpr size_t ymm_len = 32lu;
static constexpr size_t zmm_len = 64lu;

typedef enum {
isa_any,
sse42,
avx,
avx2,
avx512_common,
avx512_core,
avx512_core_vnni,
avx512_mic,
avx512_mic_4ops,
avx512_core_bf16,
avx512_vpopcnt,
fp16
} cpu_isa_t;
const Xbyak::Reg64 param = abi_param1;

static bool mayiuse(const cpu_isa_t cpu_isa);
static bool is_x64();

Generator(void* code_ptr = nullptr, size_t code_size = 16 * 1024);
Generator(cpu_isa_t isa = avx2, void* code_ptr = nullptr, size_t code_size = 16lu * 1024lu);
void preamble();
void postamble();

Expand All @@ -85,7 +88,12 @@ class Generator : public Xbyak::CodeGenerator {

template <typename T>
void copy(const Xbyak::Reg64& dst, const Xbyak::Reg64& src, const Xbyak::Reg64& size);

size_t get_vlen() {
return m_vlen;
}
};

} // namespace jit
} // namespace reference
} // namespace ov
Loading

0 comments on commit 5f4a445

Please sign in to comment.