Skip to content

Commit

Permalink
Compilation for WASM and RISCV64 (openvinotoolkit#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov authored and dmitry-gorokhov committed Jan 10, 2023
1 parent 10383ad commit 7198441
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/plugins/intel_cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ if(X86_64)
elseif(AARCH64)
add_definitions(-DOV_CPU_AARCH64)
set(OV_CPU_AARCH64 ON)
elseif(X86 OR RISCV64)
# nothing for now
else()
message(FATAL_ERROR "Unsupported system processor ${CMAKE_SYSTEM_PROCESSOR}")
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_cpu/src/cpu_shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class Shape {
}

enum : Dim {
UNDEFINED_DIM = 0xffffffffffffffff
UNDEFINED_DIM = std::numeric_limits<Dim>::max()
};

private:
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/intel_cpu/src/cpu_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
namespace ov {
namespace intel_cpu {

using Dim = std::size_t;
using VectorDims = std::vector<Dim>;

const InferenceEngine::details::caseless_unordered_map<std::string, Type> type_to_name_tbl = {
{ "Constant", Type::Input },
{ "Parameter", Type::Input },
Expand Down
35 changes: 30 additions & 5 deletions src/plugins/intel_cpu/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,30 @@
#include "weights_cache.hpp"
#include "utils/denormals.hpp"

#if !defined(__arm__) && !defined(_M_ARM) && !defined(__aarch64__) && !defined(_M_ARM64)
#ifndef __GNUC_PREREQ
#define __GNUC_PREREQ(major, minor) ((((__GNUC__) << 16) + (__GNUC_MINOR__)) >= (((major) << 16) + (minor)))
#if defined(__arm__) || defined(_M_ARM)
# define OV_CPU_ARM
#elif defined(__aarch64__) || defined(_M_ARM64)
# define OV_CPU_ARM64
#elif defined(i386) || defined(__i386) || defined(__i386__) || defined(__IA32__) || \
defined(_M_I86) || defined(_M_IX86) || defined(__X86__) || defined(_X86_)
# define OV_CPU_X86
#elif defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || \
defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
# define OV_CPU_X86_64
#elif defined(__riscv)
# define OV_CPU_RISCV64
#endif

#if !(defined(OV_CPU_ARM) || defined(OV_CPU_ARM64))
# ifndef __GNUC_PREREQ
# define __GNUC_PREREQ(major, minor) ((((__GNUC__) << 16) + (__GNUC_MINOR__)) >= (((major) << 16) + (minor)))
#endif

# ifdef _WIN32
# include <intrin.h>
# include <windows.h>
#elif defined(__EMSCRIPTEN__)
// nothing
# elif !(__GNUC_PREREQ(4, 3) && !defined(__APPLE__))
# include <cpuid.h>
# endif
Expand All @@ -55,7 +72,15 @@ namespace intel_cpu {

static std::string getDeviceFullName() {
std::string brand_string;
#if !defined(__arm__) && !defined(_M_ARM) && !defined(__aarch64__) && !defined(_M_ARM64)
#ifdef __EMSCRIPTEN__
brand_string = "WebAssembly CPU";
#elif defined(OV_CPU_RISCV64)
// TODO: extract actual device name
brand_string = "RISCV-64 CPU";
#elif defined(OV_CPU_ARM64) || defined(OV_CPU_ARM)
// TODO: extract actual device name
brand_string = "ARM CPU";
#elif defined(OV_CPU_X86_64) || defined(OV_CPU_X86)
const unsigned int addr_list[3] = { 0x80000002, 0x80000003, 0x80000004 };
unsigned int regs[4];
for (auto addr : addr_list) {
Expand All @@ -70,7 +95,7 @@ static std::string getDeviceFullName() {
brand_string += ch[j];
}
#else
brand_string = "Non Intel Architecture";
# error "Unknown device architecture"
#endif
return brand_string;
}
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/intel_cpu/thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ function(ie_add_onednn)
endif()
if(X86_64)
set(DNNL_TARGET_ARCH "X64" CACHE STRING "" FORCE)
elseif(X86)
set(DNNL_TARGET_ARCH "X86" CACHE STRING "" FORCE)
elseif(RISCV64)
set(DNNL_TARGET_ARCH "RV64" CACHE STRING "" FORCE)
elseif(AARCH64)
set(DNNL_TARGET_ARCH "AARCH64" CACHE STRING "" FORCE)
set(DNNL_AARCH64_USE_ACL ON CACHE BOOL "" FORCE)
Expand All @@ -68,8 +72,8 @@ function(ie_add_onednn)
set(ARM_COMPUTE_TARGET_ARCH_DEFAULT arm64-v8a)
endif()
set(ARM_COMPUTE_TARGET_ARCHS arm64-v8a arm64-v8.2-a arm64-v8.2-a-sve arm64-v8.2-a-sve2
armv8a armv8.2-a armv8.2-a-sve armv8.6-a armv8.6-a-sve armv8.6-a-sve2
armv8r64)
armv8a armv8.2-a armv8.2-a-sve armv8.6-a armv8.6-a-sve armv8.6-a-sve2
armv8r64)

set(ARM_COMPUTE_TARGET_ARCH "${ARM_COMPUTE_TARGET_ARCH_DEFAULT}" CACHE STRING "Architecture for ARM ComputeLibrary")
set_property(CACHE ARM_COMPUTE_TARGET_ARCH PROPERTY STRINGS ${ARM_COMPUTE_TARGET_ARCHS})
Expand Down
14 changes: 10 additions & 4 deletions src/plugins/intel_cpu/thirdparty/FindACL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ else()
logging=1)
endif()

if(EMSCRIPTEN)
if(EMSCRIPTEN OR LINUX)
list(APPEND ARM_COMPUTE_OPTIONS os=linux)
elseif(ANDROID)
list(APPEND ARM_COMPUTE_OPTIONS os=android)
Expand Down Expand Up @@ -135,6 +135,14 @@ else()

set(extra_link_flags "${extra_link_flags} ${extra_flags}")
set(extra_cxx_flags "${extra_cxx_flags} ${extra_flags}")
elseif(CMAKE_CROSSCOMPILING AND LINUX)
get_filename_component(cxx_compiler "${CMAKE_CXX_COMPILER}" NAME)
get_filename_component(c_compiler "${CMAKE_C_COMPILER}" NAME)
get_filename_component(compiler_prefix "${CMAKE_CXX_COMPILER}" DIRECTORY)
set(cmake_build_env
CC=${c_compiler}
CXX=${cxx_compiler})
list(APPEND ARM_COMPUTE_OPTIONS compiler_prefix="${compiler_prefix}/")
elseif(EMSCRIPTEN)
set(cmake_build_env
CC=emcc
Expand Down Expand Up @@ -179,9 +187,7 @@ else()
endif()

if(ENABLE_LTO)
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
AND (NOT CMAKE_CROSSCOMPILING))
if((CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG) AND (NOT CMAKE_CROSSCOMPILING))
set(extra_cxx_flags "${extra_cxx_flags} -flto=thin")
set(extra_link_flags "${extra_link_flags} -flto=thin")
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_cpu/thirdparty/onednn

0 comments on commit 7198441

Please sign in to comment.