Skip to content

Commit

Permalink
Fix pip install (#36)
Browse files Browse the repository at this point in the history
* Tweaks to pip install

* update bundle-sdist.sh to default to python3

* Increase cmake_minimum_required to 3.16

- that is what kokkos requires

* Replace Kokkos_ENABLE_PTHREAD with Kokkos_ENABLE_THREADS

* VERSION + git submodules

- ensure submodules are cloned when bundling the sdist

* Jenkins + update CMAKE_UNITY_BUILD default

* Update memory and layout defaults for CUDA

* Prefer ENABLE_INTERNAL_KOKKOS when SKBUILD

* Fix VERSION (skipped 0.0.7)

* Fix kokkos_compilation

- added subproject CI test

* decrease view ranks in pip-build

- shortens CI time

* decrease cuda-uvm CI view ranks
  • Loading branch information
jrmadsen authored Apr 28, 2022
1 parent c646c40 commit d6dcffa
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 22 deletions.
75 changes: 73 additions & 2 deletions .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ jobs:
git clone -b ${{ matrix.kokkos-branch }} https://github.com/kokkos/kokkos.git /tmp/kokkos-source &&
cmake -B /tmp/kokkos-build
-DKokkos_ENABLE_SERIAL=ON
-DKokkos_ENABLE_PTHREAD=ON
-DKokkos_ENABLE_THREADS=ON
-DCMAKE_CXX_STANDARD=17
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
/tmp/kokkos-source &&
Expand All @@ -178,7 +178,7 @@ jobs:
run:
python -m pip install -r requirements.txt &&
python -m pip install pytest &&
PYKOKKOS_BASE_SETUP_ARGS="-DENABLE_WERROR=ON -DENABLE_MEMORY_TRAITS=ON -DENABLE_LAYOUTS=ON -DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_PTHREAD=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=OFF"
PYKOKKOS_BASE_SETUP_ARGS="-DENABLE_WERROR=ON -DENABLE_MEMORY_TRAITS=ON -DENABLE_LAYOUTS=ON -DENABLE_VIEW_RANKS=2 -DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_THREADS=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=OFF"
python -m pip install -v --user --no-deps -e .

- name: Import Test
Expand All @@ -191,3 +191,74 @@ jobs:
working-directory: ${{github.workspace}}/scratch
run:
pytest $(dirname $(python -c "import kokkos; print(kokkos.__file__)" 2> /dev/null))

subproject:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]

steps:
- uses: actions/checkout@v3
with:
path: ${{github.workspace}}/pykokkos-base
submodules: true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Update container
run:
sudo apt-get update &&
sudo apt-get install -y build-essential gcc g++ ninja-build &&
python -m pip install --upgrade pip &&
python -m pip install 'cmake==3.18.4'

- name: Generate Hierarchy
run: |
cp -r ${{github.workspace}}/pykokkos-base/external/kokkos ${{github.workspace}}/kokkos
cp -r ${{github.workspace}}/pykokkos-base/external/pybind11 ${{github.workspace}}/pybind11
ls
ls *
- name: Generate CMakeLists.txt
run: |
echo -e "cmake_minimum_required(VERSION 3.16.0 FATAL_ERROR)\nproject(pykokkos-base-as-subproject LANGUAGES CXX)\nadd_subdirectory(kokkos)\nadd_subdirectory(pybind11)\nadd_subdirectory(pykokkos-base)" > ${{github.workspace}}/CMakeLists.txt
cat ${{github.workspace}}/CMakeLists.txt
- name: Configure CMake
run:
python -m pip install -r ${{github.workspace}}/pykokkos-base/requirements.txt &&
python -m pip install pytest &&
cmake -B ${{github.workspace}}/build
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-DENABLE_LAYOUTS=OFF
-DENABLE_MEMORY_TRAITS=OFF
-DENABLE_VIEW_RANKS=1
-DENABLE_EXAMPLES=ON
-DENABLE_WERROR=ON
-DKokkos_ENABLE_SERIAL=ON
-DKokkos_ENABLE_OPENMP=ON
-DBUILD_SHARED_LIBS=ON
-DPYTHON_EXECUTABLE=$(which python)
-DPython3_EXECUTABLE=$(which python)
${{github.workspace}}

- name: Build
run:
cmake --build ${{github.workspace}}/build --target all --parallel 2 &&
sudo cmake --build ${{github.workspace}}/build --target install --parallel 2

- name: Setup PYTHONPATH
run:
echo "PYTHONPATH=/usr/local/lib/python${{ matrix.python-version }}/site-packages:${PYTHONPATH}" >> $GITHUB_ENV

- name: Import Test
run:
DEBUG_OUTPUT=ON python -c "import kokkos; print(kokkos.__file__)"

- name: Test
run:
python -m kokkos.test
5 changes: 3 additions & 2 deletions .jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pipeline {
-DKokkos_ENABLE_HIP=ON \
-DBUILD_SHARED_LIBS=ON \
/tmp/kokkos-source'''
sh 'cmake --build /tmp/kokkos-build --target all --parallel ${BUILD_JOBS}'
sh 'cmake --build /tmp/kokkos-build --target all --parallel ${BUILD_JOBS} -- VERBOSE=1'
sh 'cmake --build /tmp/kokkos-build --target install --parallel ${BUILD_JOBS}'
sh 'python3 -m pip install -r requirements.txt'
sh 'python3 -m pip install pytest'
Expand Down Expand Up @@ -109,6 +109,7 @@ pipeline {
-DCMAKE_UNITY_BUILD=OFF \
-DENABLE_LAYOUTS=ON \
-DENABLE_MEMORY_TRAITS=OFF \
-DENABLE_VIEW_RANKS=2 \
-DENABLE_EXAMPLES=ON \
-DENABLE_WERROR=OFF \
-DENABLE_CTP=ON \
Expand Down Expand Up @@ -167,7 +168,7 @@ pipeline {
sh '''cmake -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_UNITY_BUILD=OFF \
-DENABLE_VIEW_RANKS=3 \
-DENABLE_VIEW_RANKS=2 \
-DENABLE_LAYOUTS=ON \
-DENABLE_MEMORY_TRAITS=OFF \
-DENABLE_EXAMPLES=ON \
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.11 FATAL_ERROR)
CMAKE_MINIMUM_REQUIRED(VERSION 3.16 FATAL_ERROR)

SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules ${CMAKE_MODULE_PATH})

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Here are the steps when Kokkos is added as a submodule:
- **YES**: set `Kokkos_ENABLE_OPENMP=ON`
- **NO**: `find_package(Threads)`
- Was Threads found?
- **YES**: set `Kokkos_ENABLE_PTHREADS=ON` (if not Windows)
- **YES**: set `Kokkos_ENABLE_THREADS=ON` (if not Windows)
- `find_package(CUDA)`
- Was CUDA found?
- **YES**: set:
Expand Down
30 changes: 20 additions & 10 deletions cmake/Modules/KokkosPythonKokkos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ INCLUDE_GUARD(GLOBAL)
INCLUDE(KokkosPythonUtilities) # miscellaneous macros and functions

# if first time cmake is run and no external/internal preference is specified,
# try to find already installed kokkos
IF(NOT DEFINED ENABLE_INTERNAL_KOKKOS AND NOT TARGET Kokkos::kokkoscore)
# try to find already installed kokkos unless (A) the Kokkos targets already
# exist or (B) pykokkos-base is being build via scikit-build. In the case
# of scikit-build, we want to prefer the internal kokkos because it is
# unlikely the user will see or kokkos which kokkos is found
IF(NOT DEFINED ENABLE_INTERNAL_KOKKOS AND NOT TARGET Kokkos::kokkoscore AND NOT SKBUILD)
FIND_PACKAGE(Kokkos)
# set the default cache value
IF(Kokkos_FOUND)
SET(_INTERNAL_KOKKOS OFF)
# force using same compiler as kokkos
kokkos_compilation(GLOBAL)
ELSE()
SET(_INTERNAL_KOKKOS ON)
ENDIF()
ELSEIF(TARGET Kokkos::kokkoscore)
SET(_INTERNAL_KOKKOS OFF)
ELSEIF(NOT DEFINED ENABLE_INTERNAL_KOKKOS AND SKBUILD)
set(_INTERNAL_KOKKOS ON)
ELSE()
# make sure ADD_OPTION in KokkosPythonOptions has a value
SET(_INTERNAL_KOKKOS ${ENABLE_INTERNAL_KOKKOS})
Expand All @@ -27,7 +34,9 @@ ENDIF()
# force an error
IF(NOT _INTERNAL_KOKKOS AND NOT TARGET Kokkos::kokkoscore)
FIND_PACKAGE(Kokkos REQUIRED COMPONENTS launch_compiler)

kokkos_compilation(GLOBAL)

IF(NOT Kokkos_INCLUDE_DIR)
GET_TARGET_PROPERTY(Kokkos_INCLUDE_DIR Kokkos::kokkoscore INTERFACE_INCLUDE_DIRECTORIES)
ENDIF()
Expand All @@ -43,6 +52,7 @@ IF(NOT _INTERNAL_KOKKOS AND NOT TARGET Kokkos::kokkoscore)
ADD_FEATURE(Kokkos_CXX_COMPILER "Compiler used to build Kokkos")
ADD_FEATURE(Kokkos_CXX_COMPILER_ID "Compiler ID used to build Kokkos")
ELSEIF(TARGET Kokkos::kokkoscore)

IF(NOT Kokkos_INCLUDE_DIR)
GET_TARGET_PROPERTY(Kokkos_INCLUDE_DIR Kokkos::kokkoscore INTERFACE_INCLUDE_DIRECTORIES)
ENDIF()
Expand Down Expand Up @@ -74,11 +84,11 @@ IF(_INTERNAL_KOKKOS)
SET(Threads_FOUND OFF)
SET(CUDA_FOUND OFF)

IF(NOT Kokkos_ENABLE_PTHREAD)
IF(NOT Kokkos_ENABLE_THREADS)
FIND_PACKAGE(OpenMP QUIET)
ENDIF()

IF(NOT DEFINED Kokkos_ENABLE_PTHREAD AND NOT OpenMP_FOUND)
IF(NOT DEFINED Kokkos_ENABLE_THREADS AND NOT OpenMP_FOUND)
FIND_PACKAGE(Threads QUIET)
ENDIF()

Expand All @@ -91,17 +101,17 @@ IF(_INTERNAL_KOKKOS)
ADD_OPTION(ENABLE_THREADS "Enable Pthreads when building Kokkos submodule" ${Threads_FOUND})
ADD_OPTION(ENABLE_CUDA "Enable CUDA when building Kokkos submodule" ${CUDA_FOUND})

# if OpenMP defaulted to ON but Kokkos_ENABLE_PTHREAD was explicitly set,
# if OpenMP defaulted to ON but Kokkos_ENABLE_THREADS was explicitly set,
# disable OpenMP defaulting to ON
IF(ENABLE_OPENMP AND Kokkos_ENABLE_PTHREAD)
IF(ENABLE_OPENMP AND Kokkos_ENABLE_THREADS)
SET(ENABLE_OPENMP OFF)
SET(Kokkos_ENABLE_OPENMP OFF)
ENDIF()

# always disable pthread backend since pthreads are not supported on Windows
IF(WIN32)
SET(ENABLE_THREADS OFF)
SET(Kokkos_ENABLE_PTHREAD OFF)
SET(Kokkos_ENABLE_THREADS OFF)
ENDIF()

# make sure this pykokkos-base option is synced to Kokkos option
Expand All @@ -115,8 +125,8 @@ IF(_INTERNAL_KOKKOS)
ENDIF()

# make sure this pykokkos-base option is synced to Kokkos option
IF(DEFINED Kokkos_ENABLE_PTHREAD)
SET(ENABLE_THREADS ${Kokkos_ENABLE_PTHREAD})
IF(DEFINED Kokkos_ENABLE_THREADS)
SET(ENABLE_THREADS ${Kokkos_ENABLE_THREADS})
ENDIF()

# make sure this pykokkos-base option is synced to Kokkos option
Expand All @@ -136,7 +146,7 @@ IF(_INTERNAL_KOKKOS)

# define the kokkos option as default and/or get it to display
IF(ENABLE_THREADS)
ADD_OPTION(Kokkos_ENABLE_PTHREAD "Build Kokkos submodule with Pthread support" ON)
ADD_OPTION(Kokkos_ENABLE_THREADS "Build Kokkos submodule with Pthread support" ON)
ENDIF()

# define the kokkos option as default and/or get it to display
Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/KokkosPythonOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ ENDIF()

# default UNITY_BUILD to ON except when compiling CUDA
SET(_UNITY_BUILD ON)
IF("CUDA" IN_LIST Kokkos_DEVICES)
IF("CUDA" IN_LIST Kokkos_DEVICES OR ENABLE_CUDA OR Kokkos_ENABLE_CUDA)
SET(_UNITY_BUILD OFF)
ENDIF()

SET(_ENABLE_MEM_DEFAULT ON)
SET(_ENABLE_LAY_DEFAULT ON)
# unless ENABLE_LAYOUTS or ENABLE_MEMORY_TRAITS were set
# or, NVCC is really, really slow so never default memory traits to ON
IF("CUDA" IN_LIST Kokkos_DEVICES)
IF("CUDA" IN_LIST Kokkos_DEVICES OR ENABLE_CUDA OR Kokkos_ENABLE_CUDA)
# one or both of these will be ignored bc of existing cache values
SET(_ENABLE_MEM_DEFAULT OFF)
SET(_ENABLE_LAY_DEFAULT ON)
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.11 FATAL_ERROR)
CMAKE_MINIMUM_REQUIRED(VERSION 3.16 FATAL_ERROR)

PROJECT(Kokkos-Python-Example LANGUAGES C CXX)

Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[build-system]
requires = [
"scikit-build",
"cmake>=3.16",
"setuptools >= 40.0.4",
"setuptools_scm >= 2.0.0",
"wheel >= 0.29.0",
"scikit-build >= 0.8.0",
"cmake >= 3.16.0",
]
build-backend = 'setuptools.build_meta'

[tool.black]
line-length = 88
Expand Down
12 changes: 11 additions & 1 deletion scripts/bundle-sdist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ if [ ${PWD} = ${BASH_SOURCE[0]} ]; then
cd ..
fi

: ${PYTHON_EXECUTABLE:=python3}

if [ ! -f external/kokkos/CMakeLists.txt ]; then
git submodule update --init external/kokkos
fi

if [ ! -f external/pybind11/CMakeLists.txt ]; then
git submodule update --init external/pybind11
fi

rm -rf .eggs *.egg-info _skbuild dist
python setup.py sdist
${PYTHON_EXECUTABLE} setup.py sdist -v -v -v
cd dist
sha256sum *
gpg --detach-sign -a *
Expand Down

0 comments on commit d6dcffa

Please sign in to comment.