Skip to content

Commit

Permalink
github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
elgiano committed Jun 18, 2023
1 parent 2fe6cfd commit 8825f41
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 20 deletions.
57 changes: 43 additions & 14 deletions .github/workflows/pluginbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,32 @@ jobs:
matrix:
include:

- name: macOS
os: macos-10.15
- name: 'Linux-x64'
os: ubuntu-latest
torch: https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.0.1%2Bcpu.zip

- name: Linux-x64
os: ubuntu-18.04
- name: 'Windows-x64'
os: windows-latest
torch: https://download.pytorch.org/libtorch/cpu/libtorch-win-shared-with-deps-2.0.1%2Bcpu.zip

- name: Windows-x64
os: windows-2019
- name: 'macOS-x64'
os: macos-latest
torch: https://download.pytorch.org/libtorch/cpu/libtorch-macos-2.0.1.zip

- name: 'macOS-arm64'
arch: arm64
os: macos-latest

env:
SC_PATH: ${{ github.workspace }}/supercollider
TORCH_PATH: ${{ github.workspace }}/libtorch
BUILD_PATH: ${{ github.workspace }}/build
INSTALL_PATH: ${{ github.workspace }}/build/Install
ARCHIVE_NAME: NNModel-${{ matrix.name }}.zip
ARCHIVE_NAME: nn.ar-${{ matrix.name }}.zip
CMAKE_OSX_ARCHITECTURES: '${{ matrix.arch }}'

steps:
- name: Checkout NNModel
- name: Checkout nn.ar
uses: actions/checkout@v2

- name: Checkout SuperCollider
Expand All @@ -37,16 +47,35 @@ jobs:
path: ${{ env.SC_PATH }}
ref: main

# Create a separate build directory
# We'll use this as our working directory for subsequent commands
# Get libtorch
- name: Download libtorch (Unix)
if: runner.os != 'Windows' && matrix.arch != 'arm64'
run: |
wget ${{ matrix.torch }} -O libtorch.zip
unzip libtorch.zip
- name: Download libtorch (MacOS arm64)
if: matrix.arch == 'arm64'
run: |
curl -L https://anaconda.org/pytorch/pytorch/2.0.0/download/osx-arm64/pytorch-2.0.0-py3.10_0.tar.bz2 | tar -xj
mv lib/python3.10/site-packages/torch "$TORCH_PATH"
- name: Download libtorch (Windows)
if: runner.os == 'Windows'
run: |
$wc = New-Object System.Net.WebClient
$wc.DownloadFile('${{ matrix.torch }}', 'libtorch.zip')
7z x libtorch.zip
# Build
- name: Create Build Environment
shell: bash
run: cmake -E make_directory $BUILD_PATH

- name: Configure CMake
shell: bash
working-directory: ${{ env.BUILD_PATH }}
run: cmake .. -DCMAKE_BUILD_TYPE='Release' -DSC_PATH="$SC_PATH" -DCMAKE_INSTALL_PREFIX="$INSTALL_PATH"
run: cmake .. -DCMAKE_BUILD_TYPE='Release' -DSC_PATH="$SC_PATH" -DCMAKE_INSTALL_PREFIX="$INSTALL_PATH" -DCMAKE_PREFIX_PATH="$TORCH_PATH"

- name: Build
shell: bash
Expand All @@ -60,15 +89,15 @@ jobs:
if: runner.os != 'Windows'
shell: bash
working-directory: ${{ env.INSTALL_PATH }}
run: zip -r "$ARCHIVE_NAME" "NNModel"
run: zip -r "$ARCHIVE_NAME" "nn.ar"

# Gather all files in a zip
- name: Zip up build (Windows)
if: runner.os == 'Windows'
shell: bash
working-directory: ${{ env.INSTALL_PATH }}
run: 7z a "$ARCHIVE_NAME" -tzip "NNModel"
run: 7z a "$ARCHIVE_NAME" -tzip "nn.ar"

# Upload
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
Expand Down
22 changes: 21 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ if (NOVA_SIMD)
endif()

find_package(Torch REQUIRED) # find torch

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
####################################################################################################
# Begin target NNUGens

Expand Down Expand Up @@ -103,6 +103,26 @@ if(SUPERNOVA)
target_link_libraries(NNUGens_supernova "${TORCH_LIBRARIES}")
endif()

# The following code block is suggested to be used on Windows.
# According to https://github.com/pytorch/pytorch/issues/25457,
# the DLLs need to be copied to avoid memory errors.
if (MSVC)
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
if(SCSYNTH)
add_custom_command(TARGET NNUGens_scsynth
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:NNUGens_scsynth>)
endif()
if(SUPERNOVA)
add_custom_command(TARGET NNUGens_supernova
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:NNUGens_supernova>)
endif()
endif (MSVC)
# End target NNModel
####################################################################################################

Expand Down
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,32 @@ Clone the project:
mkdir build
cd build

Then, use CMake to configure and build it:
Then, use CMake to configure:

cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release
cmake --build . --config Release --target install

You may want to manually specify the install location in the first step to point it at your
SuperCollider extensions directory: add the option `-DCMAKE_INSTALL_PREFIX=/path/to/extensions`.
Libtorch is found automatically if installed system-wise. If you followed the official install instruction for libtorch (link above), you need to add it to CMAKE_PREFIX_PATH:

cmake .. -DCMAKE_PREFIX_PAH=/path/to/libtorch/

It's expected that the SuperCollider repo is cloned at `../supercollider` relative to this repo. If
it's not: add the option `-DSC_PATH=/path/to/sc/source`.

cmake .. -DSC_PATH=/path/to/sc/source

You may want to manually specify the install location in the first step to point it at your
SuperCollider extensions directory: add the option `-DCMAKE_INSTALL_PREFIX=/path/to/extensions`.
Note that you can retrieve the Extension path from sclang with `Platform.userExtensionDir`

cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/extensions

Finally, use CMake to build the project:

cmake --build . --config Release
cmake --build . --config Release --target install



### Developing

The usual `regenerate` command was disabled because `CmakeLists.txt` needed to be manually edited to include libtorch.
Expand Down

0 comments on commit 8825f41

Please sign in to comment.