Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove fortran binary files and add logic to build them from source #152

Merged
merged 7 commits into from
Jun 27, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,25 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
optional_args: -pt
- os: windows-latest
optional_args: -pt --cmake_gen ninja
- os: macos-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Fortran compiler
uses: fortran-lang/setup-fortran@8821f57b53846d35d62632eb51c60ac6c4bff4ce # v1.6.1
with:
submodules: recursive
compiler: intel
- name: Build C library
# TODO: Ubuntu is phasing out support for 32-bit packages (e.g., `apt install gcc-multilib`
# fails on GitHub's runner); only build the 64-bit version for now.
run: python buildall.py --force_bits 64
# 1. Force to only build the 64-bit version since ITT API 32-bit support will be discontinued soon
# 2. Disable PT support for MacOS since we have x86 specific assembly instructions
# 3. Switch to use Ninja CMake Generator for Windows since setup-fortran action
# doesn't work in case of CMake + VS (https://github.com/fortran-lang/setup-fortran/issues/45)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good documentation! I can foresee people stumbling on this at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this isn't trolling 😀

Copy link
Contributor

@abrown abrown Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, no! I was just reading through this PR thinking, "oof, I hope I don't have to mess with this Fortran stuff in CI because I won't remember what works and what doesn't"! These doc comments came along at the right time.

run: python buildall.py --force_bits 64 -ft ${{ matrix.optional_args }}

rust_format:
name: Check Rust formatting
Expand Down
41 changes: 26 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,33 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
optional_args: -pt
- os: windows-latest
optional_args: -pt --cmake_gen ninja
- os: macos-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Config environment
if: runner.os == 'Linux'
run: sudo apt-get install gcc-multilib
run: sudo apt-get update && sudo apt-get install gcc-multilib
- name: Setup Fortran compiler
uses: fortran-lang/setup-fortran@8821f57b53846d35d62632eb51c60ac6c4bff4ce # v1.6.1
with:
compiler: intel
- name: Build C library
run: python buildall.py ${{ runner.os != 'macOS' && '-pt -v' || '-v' }}
run: python buildall.py -ft ${{ matrix.optional_args }}
- name: Display structure of files
run: ls -R
- uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
- name: Upload artifact
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
with:
name: build-artifacts-${{ matrix.os }}
path: build*/**/bin
path: |
build*/**/bin
build*/**/fortran

create_release:
permissions:
Expand All @@ -39,9 +50,9 @@ jobs:
runs-on: ubuntu-latest
needs: build
steps:
- name: Chechout sources
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Create Release
- name: Create release
id: create_release
uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e # v1.1.4
env:
Expand All @@ -51,7 +62,7 @@ jobs:
release_name: release ${{ github.ref_name }}
draft: false
prerelease: false
- name: Download Artifacts
- name: Download artifacts
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 # v4.1.1
with:
path: build-artifacts
Expand All @@ -61,11 +72,11 @@ jobs:
run: ls -R
- name: Zip files
run: |
zip -r ittapi_build_${{ github.ref_name }}.zip include &&
cd build-artifacts &&
zip -rg ../ittapi_build_${{ github.ref_name }}.zip build*/**/bin &&
zip -r ittapi_build_${{ github.ref_name }}.zip include &&
cd build-artifacts &&
zip -rg ../ittapi_build_${{ github.ref_name }}.zip build*/**/bin build*/**/fortran &&
cd -
- name: Upload Release Asset
- name: Upload release asset
id: upload-release-asset
uses: actions/upload-release-asset@e8f9f06c4b078e705bd2ea027f0926603fc9b4d5 # v1.0.2
env:
Expand Down
95 changes: 61 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause
#

cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.5)

if (POLICY CMP0048)
if(POLICY CMP0048)
# The `project()` command manages `VERSION` variables
cmake_policy(SET CMP0048 NEW)
endif()
Expand All @@ -23,19 +23,25 @@ endif()

project(ittapi)

OPTION(FORCE_32 "Force a 32bit compile on 64bit" OFF)
OPTION(ITT_API_IPT_SUPPORT "ptmarks support" OFF)
OPTION(ITT_API_FORTRAN_SUPPORT "fortran support" OFF)
option(FORCE_32 "Force a 32-bit compile on 64-bit" OFF)
option(ITT_API_IPT_SUPPORT "ptmarks support" OFF)
option(ITT_API_FORTRAN_SUPPORT "fortran support" OFF)

IF(FORCE_32 AND UNIX)
if(FORCE_32 AND UNIX)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
ENDIF()
endif()

if(CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT(FORCE_32))
set(ARCH_64 ON)
endif()

if(FORCE_32 AND ITT_API_FORTRAN_SUPPORT)
# ifx dropped 32-bit support
message(WARNING "Fortran support for 32-bit has been discontinued")
set(ITT_API_FORTRAN_SUPPORT OFF)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
# override default -O3
string(REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
Expand All @@ -48,10 +54,10 @@ endif()

set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)

foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${LIBRARY_OUTPUT_PATH} )
endforeach( )
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${LIBRARY_OUTPUT_PATH})
endforeach()

set(ITT_PUBLIC_HDRS
include/ittnotify.h
Expand All @@ -61,45 +67,66 @@ set(ITT_PUBLIC_HDRS

file(GLOB ITT_SRCS "src/ittnotify/*.c" "src/ittnotify/*.h")

if (ITT_API_IPT_SUPPORT)
if(ITT_API_IPT_SUPPORT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DITT_API_IPT_SUPPORT")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DITT_API_IPT_SUPPORT")
if (NOT WIN32)
if(NOT WIN32)
enable_language(ASM)
if (ARCH_64)
if(ARCH_64)
set(ITT_PT src/ittnotify/ittptmark64.S)
else()
set(ASM_OPTIONS "-m32")
set(ITT_PT src/ittnotify/ittptmark32.S)
endif()
set(CMAKE_ASM_FLAGS "${CFLAGS} ${ASM_OPTIONS}" )
set(CMAKE_ASM_FLAGS "${CFLAGS} ${ASM_OPTIONS}")
else()
enable_language(ASM_MASM)
if (ARCH_64)
if(ARCH_64)
set(ITT_PT src/ittnotify/ittptmark64.asm)
else()
set(ITT_PT src/ittnotify/ittptmark32.asm)
endif()
endif()
endif()

if (NOT WIN32)
if(NOT WIN32)
set(PLATFORM_PATH "posix")
set(PLATFORM_EXT "o")
else()
set(PLATFORM_PATH "win32")
set(PLATFORM_EXT "obj")
endif()

if (ARCH_64)
set(ARCH_PATH "x86_64")
else()
set(ARCH_PATH "x86")
endif()

if(ITT_API_FORTRAN_SUPPORT)
set(ITT_FORTRAN include/fortran/${PLATFORM_PATH}/${ARCH_PATH}/ittfortran.${PLATFORM_EXT})
set(ADVISOR_ANNOTATION include/fortran/${PLATFORM_PATH}/${ARCH_PATH}/advisor_annotate.${PLATFORM_EXT})
enable_language(Fortran)

set(FORTRAN_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/fortran)
file(MAKE_DIRECTORY ${FORTRAN_BINARY_DIR})

set(ITT_FORTRAN_SRC ${CMAKE_CURRENT_SOURCE_DIR}/include/fortran/${PLATFORM_PATH}/ittnotify.f90)
set(ADVISOR_ANNOTATION_SRC ${CMAKE_CURRENT_SOURCE_DIR}/include/fortran/advisor_annotate.f90)
set(ITT_FORTRAN ${FORTRAN_BINARY_DIR}/ittfortran.${PLATFORM_EXT})
set(ADVISOR_ANNOTATION ${FORTRAN_BINARY_DIR}/advisor_annotate.${PLATFORM_EXT})

if(WIN32)
set(FORTRAN_BUILD_CMD ${CMAKE_Fortran_COMPILER} /Z7 /nologo /libdir:noauto /c /O2 /module:${FORTRAN_BINARY_DIR})
set(ITT_FORTRAN_BUILD_CMD ${FORTRAN_BUILD_CMD} /object:${ITT_FORTRAN} ${ITT_FORTRAN_SRC})
set(ADVISOR_ANNOTATION_BUILD_CMD ${FORTRAN_BUILD_CMD} /object:${ADVISOR_ANNOTATION} ${ADVISOR_ANNOTATION_SRC})
else()
set(FORTRAN_BUILD_CMD ${CMAKE_Fortran_COMPILER} -g -c -fPIC -O2 -module ${FORTRAN_BINARY_DIR})
set(ITT_FORTRAN_BUILD_CMD ${FORTRAN_BUILD_CMD} -o ${ITT_FORTRAN} ${ITT_FORTRAN_SRC})
set(ADVISOR_ANNOTATION_BUILD_CMD ${FORTRAN_BUILD_CMD} -o ${ADVISOR_ANNOTATION} ${ADVISOR_ANNOTATION_SRC})
endif()

add_custom_command(OUTPUT ${ITT_FORTRAN}
COMMAND ${ITT_FORTRAN_BUILD_CMD}
DEPENDS ${ITT_FORTRAN_SRC}
COMMENT "Building ITT Fortran")

add_custom_command(OUTPUT ${ADVISOR_ANNOTATION}
COMMAND ${ADVISOR_ANNOTATION_BUILD_CMD}
DEPENDS ${ADVISOR_ANNOTATION_SRC}
COMMENT "Building Advisor Annotation")

add_library(ittnotify STATIC ${ITT_SRCS} ${ITT_PUBLIC_HDRS} ${ITT_PT} ${ITT_FORTRAN})
add_library(advisor STATIC ${ADVISOR_ANNOTATION})
Expand All @@ -111,24 +138,24 @@ set(JITPROFILING_SRC "src/ittnotify/jitprofiling.c")
add_library(jitprofiling STATIC ${JITPROFILING_SRC})

if(WIN32)
SET_TARGET_PROPERTIES(ittnotify PROPERTIES OUTPUT_NAME libittnotify)
SET_TARGET_PROPERTIES(jitprofiling PROPERTIES OUTPUT_NAME libjitprofiling)
set_target_properties(ittnotify PROPERTIES OUTPUT_NAME libittnotify)
set_target_properties(jitprofiling PROPERTIES OUTPUT_NAME libjitprofiling)
if(ITT_API_FORTRAN_SUPPORT)
SET_TARGET_PROPERTIES(advisor PROPERTIES OUTPUT_NAME libadvisor)
set_target_properties(advisor PROPERTIES OUTPUT_NAME libadvisor)
endif()
else()
SET_TARGET_PROPERTIES(ittnotify PROPERTIES OUTPUT_NAME ittnotify)
SET_TARGET_PROPERTIES(jitprofiling PROPERTIES OUTPUT_NAME jitprofiling)
set_target_properties(ittnotify PROPERTIES OUTPUT_NAME ittnotify)
set_target_properties(jitprofiling PROPERTIES OUTPUT_NAME jitprofiling)
if(ITT_API_FORTRAN_SUPPORT)
SET_TARGET_PROPERTIES(advisor PROPERTIES OUTPUT_NAME advisor)
set_target_properties(advisor PROPERTIES OUTPUT_NAME advisor)
endif()
endif()

TARGET_LINK_LIBRARIES(ittnotify PRIVATE ${CMAKE_DL_LIBS})
target_link_libraries(ittnotify PRIVATE ${CMAKE_DL_LIBS})

SET_TARGET_PROPERTIES(ittnotify PROPERTIES LINKER_LANGUAGE C)
set_target_properties(ittnotify PROPERTIES LINKER_LANGUAGE C)
if(ITT_API_FORTRAN_SUPPORT)
SET_TARGET_PROPERTIES(advisor PROPERTIES LINKER_LANGUAGE C)
set_target_properties(advisor PROPERTIES LINKER_LANGUAGE C)
endif()

target_include_directories(ittnotify
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ a BSD/GPLv2 dual license with every tool supporting ITT API.
To build the library:
- On Windows, Linux, FreeBSD and OSX: requires [cmake](https://cmake.org) to be set in `PATH`
- Windows: requires Visual Studio installed or requires [Ninja](https://github.com/ninja-build/ninja/releases) to be set in `PATH`
- To enable fortran support requires [Intel Fortran Compiler](https://www.intel.com/content/www/us/en/docs/fortran-compiler/get-started-guide/current/overview.html) installed
- To list available build options execute: `python buildall.py -h`
```
usage: buildall.py [-h] [-d] [-c] [-v] [-pt] [--force_bits] [-ft]
usage: buildall.py [-h] [-d] [-c] [-v] [-pt] [-ft] [--force_bits]

optional arguments:
-h, --help show this help message and exit
-d, --debug specify debug build configuration (release by default)
-c, --clean delete any intermediate and output files
-v, --verbose enable verbose output from build process
-pt, --ptmark enable anomaly detection support
--force_bits specify bit version for the target
-ft, --fortran enable fortran support
--force_bits specify bit version for the target
--vs specify visual studio version (Windows only)
--cmake_gen specify cmake build generator (Windows only)
```
### License

Expand Down
12 changes: 8 additions & 4 deletions buildall.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ def main():
"-v", "--verbose", help="enable verbose output from build process", action="store_true")
parser.add_argument(
"-pt", "--ptmark", help="enable anomaly detection support", action="store_true")
parser.add_argument(
"-ft", "--fortran", help="enable fortran support", action="store_true")
parser.add_argument(
"--force_bits", choices=["32", "64"], help="specify bit version for the target")
parser.add_argument("-ft", "--fortran",
help="enable fortran support", action="store_true")
if sys.platform == 'win32' and vs_versions:
parser.add_argument(
"--vs", help="specify visual studio version {default}", choices=vs_versions, default=vs_versions[0])
parser.add_argument(
"--cmake_gen", choices=["vs", "ninja"], help="specify cmake build generator")
args = parser.parse_args()

if args.force_bits:
Expand Down Expand Up @@ -157,7 +159,9 @@ def main():
return

if sys.platform == 'win32':
if vs_versions:
# ninja does not support platform bit specification
use_ninja = args.cmake_gen == 'ninja' and bits =='64'
if vs_versions and not use_ninja:
generator = 'Visual Studio {}'.format(args.vs)
generator_args = '-A {}'.format('x64' if bits ==
'64' else 'Win32')
Expand All @@ -177,7 +181,7 @@ def main():
])))

if sys.platform == 'win32':
target_project = 'ALL_BUILD'
target_project = 'ALL_BUILD' if not use_ninja else 'all'
run_shell('%s --build . --config %s --target %s' %
(cmake, ('Debug' if args.debug else 'Release'), target_project))
else:
Expand Down
Binary file removed include/fortran/posix/x86/advisor_annotate.mod
Binary file not shown.
Binary file removed include/fortran/posix/x86/advisor_annotate.o
Binary file not shown.
Binary file removed include/fortran/posix/x86/ittfortran.o
Binary file not shown.
Binary file removed include/fortran/posix/x86/ittnotify.mod
Binary file not shown.
Binary file removed include/fortran/posix/x86_64/advisor_annotate.mod
Binary file not shown.
Binary file removed include/fortran/posix/x86_64/advisor_annotate.o
Binary file not shown.
Binary file removed include/fortran/posix/x86_64/ittfortran.o
Binary file not shown.
Binary file removed include/fortran/posix/x86_64/ittnotify.mod
Binary file not shown.
Binary file removed include/fortran/win32/x86/advisor_annotate.mod
Binary file not shown.
Binary file removed include/fortran/win32/x86/advisor_annotate.obj
Binary file not shown.
Binary file removed include/fortran/win32/x86/ittfortran.obj
Binary file not shown.
Binary file removed include/fortran/win32/x86/ittnotify.mod
Binary file not shown.
Binary file removed include/fortran/win32/x86_64/advisor_annotate.mod
Binary file not shown.
Binary file removed include/fortran/win32/x86_64/advisor_annotate.obj
Binary file not shown.
Binary file removed include/fortran/win32/x86_64/ittfortran.obj
Binary file not shown.
Binary file removed include/fortran/win32/x86_64/ittnotify.mod
Binary file not shown.
Loading