Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Introducing OMP #3001

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
35 changes: 20 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")

# Go through and add in all the relevant build flags as appropriate
# Go through and add in all the relevant build flags as appropriate
check_and_set_compiler_flag(-ftemplate-depth=900 CXX)
check_and_set_compiler_flag(-Wno-c++11-narrowing CXX)
check_and_set_compiler_flag(-Wno-stdlibcxx-not-found CXX RESTRICT_CLANG)
Expand Down Expand Up @@ -154,17 +154,17 @@ check_and_set_compiler_flag(-mfpmath=sse RELEASE)

if(APPLE)
# This triggers a bug in clang; the 10.13 symbol ___chkstk_darwin is missing in
# 10.13, and the code generated doesn't run on that, even with the 10.12 target.
# 10.13, and the code generated doesn't run on that, even with the 10.12 target.
# The solution to this is to disable the stack checking globally, which seems
# to be enabled by default in clang 11 and later for objective C++ code.
# to be enabled by default in clang 11 and later for objective C++ code.
check_and_set_compiler_flag(-fno-stack-check)
check_and_set_compiler_flag(-fno-stack-protector)
endif()

# Turn on ARC globally.
check_and_set_compiler_flag(-fobjc-arc)

# This flag needs to be set after all other warning flags, or it may give false
# This flag needs to be set after all other warning flags, or it may give false
# positives.
check_and_set_compiler_flag(-Wno-unknown-warning-option)

Expand Down Expand Up @@ -193,7 +193,7 @@ Find_Int128_Types()
include(CompilerOddities)
Set_Compiler_Specific_Flags()

# Set up threads.
# Set up threads.
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
Expand All @@ -212,13 +212,13 @@ if (APPLE)
find_library(CORE_VIDEO CoreVideo)
find_library(METAL NAMES Metal)
find_library(METAL_PERFORMANCE_SHADERS NAMES MetalPerformanceShaders)
set(_TC_APPLE_DEPENDENCIES
${ACCELERATE} ${CORE_GRAPHICS} ${JAVASCRIPT_CORE} ${FOUNDATION}
set(_TC_APPLE_DEPENDENCIES
${ACCELERATE} ${CORE_GRAPHICS} ${JAVASCRIPT_CORE} ${FOUNDATION}
${CORE_IMAGE} ${CORE_ML} ${CORE_VIDEO} ${METAL} ${METAL_PERFORMANCE_SHADERS})

if(NOT ${TC_BUILD_IOS})
find_library(APPKIT AppKit)
set(_TC_APPLE_DEPENDENCIES ${_TC_APPLE_DEPENDENCIES} ${APPKIT})
set(_TC_APPLE_DEPENDENCIES ${_TC_APPLE_DEPENDENCIES} ${APPKIT})
endif()
endif()

Expand Down Expand Up @@ -358,7 +358,7 @@ foreach(package ${packages})
add_dependencies(external_dependencies ex_${depname})
endforeach()

set(_TC_EXTERNAL_DEPENDENCIES
set(_TC_EXTERNAL_DEPENDENCIES
openssl libxml2 curl
Threads::Threads
${CMAKE_DL_LIBS})
Expand All @@ -368,7 +368,7 @@ set(_TC_EXTERNAL_DEPENDENCIES
# These are used by C API, unity_shared, etc.

if(NOT _TC_DEFAULT_SERVER_INITIALIZER)
set(_TC_DEFAULT_SERVER_INITIALIZER
set(_TC_DEFAULT_SERVER_INITIALIZER
"${CMAKE_SOURCE_DIR}/src/capi/default_server_initializer.cpp"
)
endif()
Expand All @@ -385,7 +385,6 @@ set(_TC_COMMON_OBJECTS
"$<TARGET_OBJECTS:lz4>"
"$<TARGET_OBJECTS:protobuf>"
"$<TARGET_OBJECTS:uuid>"
"$<TARGET_OBJECTS:xgboost>"
"$<TARGET_OBJECTS:coremltools_mlmodel>"

# Then our own source code
Expand All @@ -404,8 +403,8 @@ set(_TC_COMMON_OBJECTS
"$<TARGET_OBJECTS:nanosockets>"
"$<TARGET_OBJECTS:network>"
"$<TARGET_OBJECTS:optimization>"
"$<TARGET_OBJECTS:parallel>"
"$<TARGET_OBJECTS:process>"
"$<TARGET_OBJECTS:parallel>"
"$<TARGET_OBJECTS:pylambda>"
"$<TARGET_OBJECTS:random>"
"$<TARGET_OBJECTS:serialization>"
Expand Down Expand Up @@ -459,15 +458,22 @@ set(_TC_COMMON_REQUIREMENTS
boost
libbz2
z
xgboost
)

if (NOT TC_BUILD_IOS)
set(TC_ENABLE_OPENMP ON CACHE STRING "enable openmp")
add_definitions(-D_OPNMP)
remove_definitions(-DDISABLE_OPENMP)
endif()

if(APPLE)
set(_TC_COMMON_REQUIREMENTS
# External dependencies (from deps)
${_TC_COMMON_REQUIREMENTS}
${_TC_APPLE_DEPENDENCIES})
endif()

set(_TC_COMMON_OBJECTS
${_TC_COMMON_OBJECTS}
"$<TARGET_OBJECTS:annotation>"
Expand All @@ -491,7 +497,7 @@ if(APPLE)
${_TC_COMMON_OBJECTS}
"$<TARGET_OBJECTS:vega_renderer>"
)
set(_TC_COMMON_REQUIREMENTS
set(_TC_COMMON_REQUIREMENTS
${_TC_COMMON_REQUIREMENTS}
${APPKIT}
${CORE_GRAPHICS}
Expand Down Expand Up @@ -541,4 +547,3 @@ endif()

add_subdirectory(src)
add_subdirectory(test)

5 changes: 5 additions & 0 deletions src/external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ add_subdirectory(google)
add_subdirectory(bzip2)
add_subdirectory(lz4)
add_subdirectory(uuid_p)

if (NOT TC_BUILD_IOS)
add_subdirectory(openmp)
endif()

add_subdirectory(xgboost)
add_subdirectory(coremltools_wrap)
add_subdirectory(boost)
Expand Down
49 changes: 49 additions & 0 deletions src/external/openmp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
project(Turi)

if(TC_BUILD_IOS)
return()
endif()

message("Building openmp using native build system.")

set(_openmp_dir openmp-src)

set(ON_X86
ON
CACHE BOOL "build on x86 architecture")

# custom settings
set(OPENMP_STANDALONE_BUILD
TRUE
CACHE BOOL "not build within llvm source tree")

set(LIBOMP_ENABLE_SHARED
OFF
CACHE BOOL "open static/dynamic link")

set(LIBOMP_USE_ADAPTIVE_LOCKS
${ON_X86}
CACHE BOOL "enable only for x86")

set(OPENMP_ENABLE_LIBOMPTARGET
OFF
CACHE BOOL "no libomptarget")

set(LIBOMP_COPY_EXPORTS
FALSE
CACHE STRING "build in place")

# build openmp
add_subdirectory(${_openmp_dir})

set(TURI_OMP_H_PATH
${CMAKE_CURRENT_BINARY_DIR}/${_openmp_dir}/runtime/src
CACHE STRING "build time generated omp.h path")

target_include_directories(omp INTERFACE ${TURI_OMP_H_PATH})

# for <crt_extern.h>
target_include_directories(omp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

# used to extract the header path
set_target_properties(omp PROPERTIES TURI_OMP_H_PATH ${TURI_OMP_H_PATH})
8 changes: 8 additions & 0 deletions src/external/openmp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
README
------

* Tue Feb 11 10:40:12 PST 2020

`openmp-src` is a clone from [llvm-mirror/openmp](https://github.com/llvm-mirror/openmp/tree/master).

The branch is set to the current most recent release, [release\_90](https://github.com/llvm-mirror/openmp/tree/release_90).
44 changes: 44 additions & 0 deletions src/external/openmp/crt_externs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
*/

/*
** Prototypes for the functions to get environment information in
** the world of dynamic libraries. Lifted from .c file of same name.
** Fri Jun 23 12:56:47 PDT 1995
** AOF ([email protected])
*/

#include <sys/cdefs.h>

__BEGIN_DECLS
extern char ***_NSGetArgv(void);
extern int *_NSGetArgc(void);
extern char ***_NSGetEnviron(void);
extern char **_NSGetProgname(void);
extern struct mach_header *_NSGetMachExecuteHeader(void);
__END_DECLS
42 changes: 42 additions & 0 deletions src/external/openmp/openmp-src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#==============================================================================#
# This file specifies intentionally untracked files that git should ignore.
# See: http://www.kernel.org/pub/software/scm/git/docs/gitignore.html
#
# This file is intentionally different from the output of `git svn show-ignore`,
# as most of those are useless.
#==============================================================================#

#==============================================================================#
# File extensions to be ignored anywhere in the tree.
#==============================================================================#
# Temp files created by most text editors.
*~
# Merge files created by git.
*.orig
# Byte compiled python modules.
*.pyc
# vim swap files
.*.sw?
.sw?
#OS X specific files.
.DS_store

#==============================================================================#
# Explicit files to ignore (only matches one).
#==============================================================================#
# Various tag programs
tags
/TAGS
/GPATH
/GRTAGS
/GSYMS
/GTAGS
.gitusers

#==============================================================================#
# Directories to ignore (do not add trailing '/'s, they skip symlinks).
#==============================================================================#
runtime/exports

# Nested build directory
/build
83 changes: 83 additions & 0 deletions src/external/openmp/openmp-src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

# Add cmake directory to search for custom cmake functions.
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

# llvm/runtimes/ will set OPENMP_STANDALONE_BUILD.
if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
set(OPENMP_STANDALONE_BUILD TRUE)
project(openmp C CXX)

# CMAKE_BUILD_TYPE was not set, default to Release.
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

# Group common settings.
set(OPENMP_ENABLE_WERROR FALSE CACHE BOOL
"Enable -Werror flags to turn warnings into errors for supporting compilers.")
set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING
"Suffix of lib installation directory, e.g. 64 => lib64")
# Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}")

# Group test settings.
set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
"C compiler to use for testing OpenMP runtime libraries.")
set(OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
"C++ compiler to use for testing OpenMP runtime libraries.")
set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.")
else()
set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
# If building in tree, we honor the same install suffix LLVM uses.
set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}")

if (NOT MSVC)
set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
else()
set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
endif()
endif()

# Check and set up common compiler flags.
include(config-ix)
include(HandleOpenMPOptions)

# Set up testing infrastructure.
include(OpenMPTesting)

set(OPENMP_TEST_FLAGS "" CACHE STRING
"Extra compiler flags to send to the test compiler.")
set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING
"OpenMP compiler flag to use for testing OpenMP runtime libraries.")


# Build host runtime library.
add_subdirectory(runtime)


set(ENABLE_LIBOMPTARGET ON)
# Currently libomptarget cannot be compiled on Windows or MacOS X.
# Since the device plugins are only supported on Linux anyway,
# there is no point in trying to compile libomptarget on other OSes.
if (APPLE OR WIN32 OR NOT OPENMP_HAVE_STD_CPP11_FLAG)
set(ENABLE_LIBOMPTARGET OFF)
endif()

option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
${ENABLE_LIBOMPTARGET})
if (OPENMP_ENABLE_LIBOMPTARGET)
# Check that the library can acutally be built.
if (APPLE OR WIN32)
message(FATAL_ERROR "libomptarget cannot be built on Windows and MacOS X!")
elseif (NOT OPENMP_HAVE_STD_CPP11_FLAG)
message(FATAL_ERROR "Host compiler must support C++11 to build libomptarget!")
endif()

add_subdirectory(libomptarget)
endif()

# Now that we have seen all testuites, create the check-openmp target.
construct_check_openmp_target()
Loading