forked from microsoft/MLAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
439 changed files
with
144,494 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <[email protected]> | ||
# Licensed under the MIT License. | ||
|
||
# Minimum CMake required | ||
cmake_minimum_required(VERSION 3.26) | ||
|
||
cmake_policy(SET CMP0069 NEW) | ||
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) | ||
|
||
cmake_policy(SET CMP0092 NEW) | ||
cmake_policy(SET CMP0091 NEW) | ||
cmake_policy(SET CMP0117 NEW) | ||
|
||
# Project | ||
project(MLAS C CXX ASM) | ||
|
||
set(CMAKE_C_STANDARD 99) | ||
include(CheckCXXCompilerFlag) | ||
include(CheckLanguage) | ||
include(CMakeDependentOption) | ||
include(FetchContent) | ||
include(CheckFunctionExists) | ||
include(GNUInstallDirs) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
|
||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) | ||
include(CTest) | ||
endif() | ||
|
||
if (NOT CMAKE_BUILD_TYPE) | ||
message(STATUS "Build type not set - using RelWithDebInfo") | ||
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose build type: Debug Release RelWithDebInfo MinSizeRel." FORCE) | ||
endif() | ||
|
||
find_package(Threads) | ||
|
||
set(ONNXRUNTIME_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src) | ||
set(ONNXRUNTIME_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
|
||
include(cmake/external_deps.cmake) | ||
include_directories(${eigen_SOURCE_DIR}) | ||
|
||
add_compile_options(-DNSYNC_ATOMIC_CPP11 -DDISABLE_ABSEIL) | ||
set(ONNXRUNTIME_MLAS_LIBS onnxruntime_mlas) | ||
add_subdirectory(src) | ||
if(TARGET onnxruntime_mlas_arm64) | ||
list(APPEND ONNXRUNTIME_MLAS_LIBS onnxruntime_mlas_arm64) | ||
endif() | ||
|
||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) | ||
add_subdirectory(tests) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
eigen;https://gitlab.com/libeigen/eigen/-/archive/e7248b26a1ed53fa030c5c459f7ea095dfd276ac/eigen-e7248b26a1ed53fa030c5c459f7ea095dfd276ac.zip;be8be39fdbc6e60e94fa7870b280707069b5b81a | ||
microsoft_gsl;https://github.com/microsoft/GSL/archive/refs/tags/v4.0.0.zip;cf368104cd22a87b4dd0c80228919bb2df3e2a14 | ||
googletest;https://github.com/google/googletest/archive/refs/tags/v1.15.0.zip;9d2d0af8d77ac726ea55d44a8fa727ec98311349 | ||
google_benchmark;https://github.com/google/benchmark/archive/refs/tags/v1.8.5.zip;cd47d3d272faf353600c8cc2fdec2b52d6f69177 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
file(STRINGS cmake/deps.txt ONNXRUNTIME_DEPS_LIST) | ||
foreach(ONNXRUNTIME_DEP IN LISTS ONNXRUNTIME_DEPS_LIST) | ||
# Lines start with "#" are comments | ||
if(NOT ONNXRUNTIME_DEP MATCHES "^#") | ||
# The first column is name | ||
list(POP_FRONT ONNXRUNTIME_DEP ONNXRUNTIME_DEP_NAME) | ||
# The second column is URL | ||
# The URL below may be a local file path or an HTTPS URL | ||
list(POP_FRONT ONNXRUNTIME_DEP ONNXRUNTIME_DEP_URL) | ||
set(DEP_URL_${ONNXRUNTIME_DEP_NAME} ${ONNXRUNTIME_DEP_URL}) | ||
# The third column is SHA1 hash value | ||
set(DEP_SHA1_${ONNXRUNTIME_DEP_NAME} ${ONNXRUNTIME_DEP}) | ||
|
||
if(ONNXRUNTIME_DEP_URL MATCHES "^https://") | ||
# Search a local mirror folder | ||
string(REGEX REPLACE "^https://" "${REPO_ROOT}/mirror/" LOCAL_URL "${ONNXRUNTIME_DEP_URL}") | ||
|
||
if(EXISTS "${LOCAL_URL}") | ||
cmake_path(ABSOLUTE_PATH LOCAL_URL) | ||
set(DEP_URL_${ONNXRUNTIME_DEP_NAME} "${LOCAL_URL}") | ||
endif() | ||
endif() | ||
endif() | ||
endforeach() | ||
|
||
message(STATUS "Loading Dependencies ...") | ||
include(FetchContent) | ||
include(cmake/helper_functions.cmake) | ||
|
||
onnxruntime_fetchcontent_declare( | ||
GSL | ||
URL ${DEP_URL_microsoft_gsl} | ||
URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} | ||
EXCLUDE_FROM_ALL | ||
FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL | ||
) | ||
|
||
onnxruntime_fetchcontent_declare( | ||
eigen | ||
URL ${DEP_URL_eigen} | ||
URL_HASH SHA1=${DEP_SHA1_eigen} | ||
EXCLUDE_FROM_ALL | ||
) | ||
|
||
onnxruntime_fetchcontent_makeavailable(GSL eigen) | ||
|
||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) | ||
# WebAssembly threading support in Node.js is still an experimental feature and | ||
# not working properly with googletest suite. | ||
if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") | ||
set(gtest_disable_pthreads ON) | ||
endif() | ||
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) | ||
|
||
set(GTEST_HAS_ABSL OFF CACHE BOOL "" FORCE) | ||
|
||
# gtest and gmock | ||
FetchContent_Declare( | ||
googletest | ||
URL ${DEP_URL_googletest} | ||
URL_HASH SHA1=${DEP_SHA1_googletest} | ||
FIND_PACKAGE_ARGS 1.14.0...<2.0.0 NAMES GTest | ||
) | ||
FetchContent_MakeAvailable(googletest) | ||
|
||
# We will not need to test benchmark lib itself. | ||
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark testing as we don't need it.") | ||
# We will not need to install benchmark since we link it statically. | ||
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Disable benchmark install to avoid overwriting vendor install.") | ||
|
||
FetchContent_Declare( | ||
google_benchmark | ||
URL ${DEP_URL_google_benchmark} | ||
URL_HASH SHA1=${DEP_SHA1_google_benchmark} | ||
FIND_PACKAGE_ARGS NAMES benchmark | ||
) | ||
onnxruntime_fetchcontent_makeavailable(google_benchmark) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# This file contains some wrappers for cmake's FetchContent functions. The wrappers added the following functionalities: | ||
# 1. Group the VC projects into the "external" folder. We can do it at there in a centralized way instead | ||
# of doing it one by one. | ||
# 2. Set the cmake property COMPILE_WARNING_AS_ERROR to OFF for these external projects. | ||
|
||
function(onnxruntime_fetchcontent_declare contentName) | ||
FetchContent_Declare(${ARGV}) | ||
string(TOLOWER ${contentName} contentNameLower) | ||
list(FIND ARGN SOURCE_SUBDIR index_SOURCE_SUBDIR) | ||
if(index_SOURCE_SUBDIR GREATER_EQUAL 0) | ||
cmake_parse_arguments(PARSE_ARGV 1 ARG "" "SOURCE_SUBDIR" "") | ||
set(onnxruntime_${contentNameLower}_cmake_src_dir "${ARG_SOURCE_SUBDIR}" PARENT_SCOPE) | ||
endif() | ||
endfunction() | ||
|
||
macro(onnxruntime_fetchcontent_makeavailable) | ||
set(ONNXRUNTIME_CMAKE_SKIP_INSTALL_RULES_OLD_VALUE | ||
"${CMAKE_SKIP_INSTALL_RULES}") | ||
# If we don't skip the install rules we will hit errors from re2 like: | ||
# CMake Error: install(EXPORT "re2Targets" ...) includes target "re2" which requires target "absl_base" that is not in any export set. | ||
set(CMAKE_SKIP_INSTALL_RULES TRUE) | ||
FetchContent_MakeAvailable(${ARGV}) | ||
foreach(contentName IN ITEMS ${ARGV}) | ||
string(TOLOWER ${contentName} contentNameLower) | ||
set(content_src_dir "${${contentNameLower}_SOURCE_DIR}") | ||
if(NOT "${onnxruntime_${contentNameLower}_cmake_src_dir}" STREQUAL "") | ||
string(APPEND content_src_dir "/${onnxruntime_${contentNameLower}_cmake_src_dir}") | ||
endif() | ||
get_property(subdir_import_targets DIRECTORY "${content_src_dir}" PROPERTY BUILDSYSTEM_TARGETS) | ||
foreach(subdir_target ${subdir_import_targets}) | ||
if(TARGET ${subdir_target}) | ||
get_target_property(subdir_target_type ${subdir_target} TYPE) | ||
if(subdir_target_type STREQUAL "EXECUTABLE") | ||
get_target_property(subdir_target_osx_arch ${subdir_target} OSX_ARCHITECTURES) | ||
if (subdir_target_osx_arch) | ||
if (NOT ${CMAKE_HOST_SYSTEM_PROCESSOR} IN_LIST subdir_target_osx_arch) | ||
message("Added an executable target ${subdir_target} but it can not run natively on ${CMAKE_HOST_SYSTEM_PROCESSOR}, we will try to modify it") | ||
endif() | ||
endif() | ||
endif() | ||
set_target_properties(${subdir_target} PROPERTIES FOLDER "External") | ||
set_target_properties(${subdir_target} PROPERTIES COMPILE_WARNING_AS_ERROR OFF) | ||
endif() | ||
endforeach() | ||
endforeach() | ||
set(CMAKE_SKIP_INSTALL_RULES ${ONNXRUNTIME_CMAKE_SKIP_INSTALL_RULES_OLD_VALUE}) | ||
endmacro() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace onnxruntime { | ||
|
||
/** A computed hash value. */ | ||
using HashValue = uint64_t; | ||
|
||
/** The type of an argument (input or output).*/ | ||
enum class ArgType : uint8_t { | ||
kInput, | ||
kOutput, | ||
}; | ||
|
||
} // namespace onnxruntime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#include <sstream> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace onnxruntime { | ||
/** | ||
CodeLocation captures information on where in the source code a message came from. | ||
*/ | ||
struct CodeLocation { | ||
/** | ||
@param file_path Usually the value of __FILE__ | ||
@param line Usually the value of __LINE__ | ||
@param func Usually the value of __PRETTY_FUNCTION__ or __FUNCTION__ | ||
*/ | ||
CodeLocation(const char* file_path, const int line, const char* func) | ||
: file_and_path{file_path}, line_num{line}, function{func} { | ||
} | ||
|
||
/** | ||
@param file_path Usually the value of __FILE__ | ||
@param line Usually the value of __LINE__ | ||
@param func Usually the value of __PRETTY_FUNCTION__ or __FUNCTION__ | ||
@param stacktrace Stacktrace from source of message. | ||
*/ | ||
CodeLocation(const char* file_path, const int line, const char* func, const std::vector<std::string>& stacktrace) | ||
: file_and_path{file_path}, line_num{line}, function{func}, stacktrace(stacktrace) { | ||
} | ||
|
||
std::string FileNoPath() const { | ||
// assuming we always have work to do, so not trying to avoid creating a new string if | ||
// no path was removed. | ||
return file_and_path.substr(file_and_path.find_last_of("/\\") + 1); | ||
} | ||
|
||
enum Format { | ||
kFilename, | ||
kFilenameAndPath | ||
}; | ||
|
||
std::string ToString(Format format = Format::kFilename) const { | ||
std::ostringstream out; | ||
out << (format == Format::kFilename ? FileNoPath() : file_and_path) << ":" << line_num << " " << function; | ||
return out.str(); | ||
} | ||
// utf-8. Because on Windows we compile our code with "/utf-8". And we assume the other platforms only use utf-8. | ||
const std::string file_and_path; | ||
const int line_num; | ||
// utf-8 | ||
const std::string function; | ||
const std::vector<std::string> stacktrace; | ||
}; | ||
|
||
} // namespace onnxruntime |
Oops, something went wrong.