Skip to content

Commit

Permalink
Cherry pick x86 fix in release 0.3.0 (#606)
Browse files Browse the repository at this point in the history
* merge x86 linux build

* remove wrong argu
  • Loading branch information
Raymond Yang authored and RandySheriffH committed Mar 12, 2019
1 parent 17ceca2 commit b8c5bf2
Show file tree
Hide file tree
Showing 15 changed files with 1,067 additions and 12 deletions.
5 changes: 5 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ else()
string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -march=native -mtune=native")
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO " -march=native -mtune=native")
endif()
if(onnxruntime_BUILD_x86)
set (CMAKE_SYSTEM_PROCESSOR "x86")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -mfpmath=sse -Wno-narrowing")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -mfpmath=sse -Wno-narrowing")
endif()
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand Down
21 changes: 20 additions & 1 deletion cmake/onnxruntime_mlas.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@ else()
${ONNXRUNTIME_ROOT}/core/mlas/lib/aarch64/sgemma.s
)

elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86?)$")

enable_language(ASM)

set(mlas_platform_srcs_sse2
${ONNXRUNTIME_ROOT}/core/mlas/lib/x86/SgemmKernelSse2.S
)
set_source_files_properties(${mlas_platform_srcs_sse2} PROPERTIES COMPILE_FLAGS "-msse2")

set(mlas_platform_srcs_avx
${ONNXRUNTIME_ROOT}/core/mlas/lib/x86/SgemmKernelAvx.S
)
set_source_files_properties(${mlas_platform_srcs_avx} PROPERTIES COMPILE_FLAGS "-mavx")

set(mlas_platform_srcs
${mlas_platform_srcs_sse2}
${mlas_platform_srcs_avx}
)

elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")

enable_language(ASM)
Expand All @@ -106,7 +125,7 @@ else()
${ONNXRUNTIME_ROOT}/core/mlas/lib/x86_64/SgemmKernelSse2.S
${ONNXRUNTIME_ROOT}/core/mlas/lib/x86_64/SgemmTransposePackB16x4Sse2.S
)
set_source_files_properties(${mlas_platform_srcs_sse} PROPERTIES COMPILE_FLAGS "-msse2")
set_source_files_properties(${mlas_platform_srcs_sse2} PROPERTIES COMPILE_FLAGS "-msse2")

set(mlas_platform_srcs_avx
${ONNXRUNTIME_ROOT}/core/mlas/lib/x86_64/SgemmKernelAvx.S
Expand Down
3 changes: 0 additions & 3 deletions onnxruntime/core/mlas/lib/mlasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ Module Name:
#include <cpuid.h>
#include <immintrin.h>
#endif
#if defined(__x86_64__)
#include "x86_64/xgetbv.h"
#endif
#endif

//
Expand Down
41 changes: 36 additions & 5 deletions onnxruntime/core/mlas/lib/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,41 @@ Module Name:

MLAS_PLATFORM MlasPlatform;

#ifdef MLAS_TARGET_AMD64_IX86

//
// Reads the processor extended control register to determine platform
// capabilities.
//

#if !defined(_XCR_XFEATURE_ENABLED_MASK)
#define _XCR_XFEATURE_ENABLED_MASK 0
#endif

inline
uint64_t
MlasReadExtendedControlRegister(
unsigned int ext_ctrl_reg
)
{
#if defined(_WIN32)
return _xgetbv(ext_ctrl_reg);
#else
uint32_t eax, edx;

__asm__
(
"xgetbv"
: "=a" (eax), "=d" (edx)
: "c" (ext_ctrl_reg)
);

return ((uint64_t)edx << 32) | eax;
#endif
}

#endif

MLAS_PLATFORM::MLAS_PLATFORM(
void
)
Expand Down Expand Up @@ -74,11 +109,7 @@ Return Value:
// Check if the operating system supports saving SSE and AVX states.
//

#if defined(_WIN32)
uint64_t xcr0 = _xgetbv(_XCR_XFEATURE_ENABLED_MASK);
#else
uint64_t xcr0 = xgetbv(_XCR_XFEATURE_ENABLED_MASK);
#endif
uint64_t xcr0 = MlasReadExtendedControlRegister(_XCR_XFEATURE_ENABLED_MASK);

if ((xcr0 & 0x6) == 0x6) {

Expand Down
Loading

0 comments on commit b8c5bf2

Please sign in to comment.