Skip to content
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
120 changes: 120 additions & 0 deletions .github/workflows/windows_amd64_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Based on version from @dfalbel in https://github.com/r-xla/pjrt-builds
on:
workflow_dispatch:

name: Build PJRT

permissions:
contents: write

jobs:
build:
name: "Build Windows (amd64) Plugin"

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

defaults:
run:
shell:
bash

# artifact_name: pjrt_cpu.dll
# target: pjrt_c_api_cpu_plugin.so
# setup: |
steps:
- uses: actions/checkout@v4

- run: |
choco install llvm -y
# Remove MSVC from PATH to force clang usage
echo "PATH=$(echo $PATH | tr ':' '\n' | grep -v 'Microsoft Visual Studio' | grep -v 'VC/Tools/MSVC' | tr '\n' ':')" >> $GITHUB_ENV

- run: |
git clone https://github.com/openxla/xla
cd xla
HASH=$(cat ../XLA_COMMIT_HASH.txt)
echo "Checking out XLA at commit: $HASH"
git checkout $HASH

- run: |
BUILDER_VERSION="$(cat BUILDER_VERSION.txt)"
MAJOR=$(grep -E '#define PJRT_API_MAJOR' "${PJRT_C_API_HEADER}" | awk '{print $3}')
MINOR=$(grep -E '#define PJRT_API_MINOR' "${PJRT_C_API_HEADER}" | awk '{print $3}')
echo "Building PJRT CPU plugin for version ${MAJOR}.${MINOR} (to be used in go-xla as v${MAJOR}.${MINOR}.${BUILDER_VERSION})"
echo "RELEASE=v${MAJOR}.${MINOR}.${BUILDER_VERSION}" >> $GITHUB_ENV

- run: |
cd xla
python configure.py --backend=cpu --os=windows --host_compiler=clang --clang_path=C:/PROGRA~1/LLVM/bin/clang.exe
cat xla_configure.bazelrc

- name: Fix Windows paths in bazelrc
run: |
cd xla
# Fix Windows paths for Bazel compatibility
# Replace "Program Files" with short name (handles both / and \ separators)
sed -i 's|Program Files|PROGRA~1|g' xla_configure.bazelrc
# Convert all backslashes to forward slashes
sed -i 's|\\|/|g' xla_configure.bazelrc
cat xla_configure.bazelrc

echo "Applying dllexport patch ---------------"
git apply ../patches/windows/export.patch

- run: |
cd xla
printf "\nStarting XLA bazel build:\n"
bazel build \
--config=clang_local \
--action_env=CC=C:/PROGRA~1/LLVM/bin/clang.exe \
--action_env=CXX=C:/PROGRA~1/LLVM/bin/clang++.exe \
--linkopt="--ld-path=C:/PROGRA~1/LLVM/bin/ld.lld.exe" \
--repo_env=BAZEL_COMPILER=C:/PROGRA~1/LLVM/bin/clang.exe \
--repo_env=USE_CLANG_CL=1 \
--copt=-march=native \
--define xnn_enable_arm_fp16_scalar=false \
--define xnn_enable_arm_fp16_vector=false \
--define xnn_enable_arm_bf16=false \
--define xnn_enable_arm_dotprod=false \
--define xnn_enable_arm_i8mm=false \
--define xnn_enable_arm_sme=false \
--define xnn_enable_arm_sme2=false \
--define xnn_enable_riscv_vector=false \
--define xnn_enable_riscv_fp16_vector=false \
--define xnn_enable_avxvnni=false \
--define xnn_enable_avxvnniint8=false \
--define xnn_enable_avx256skx=false \
--define xnn_enable_avx256vnni=false \
--define xnn_enable_avx256vnnigfni=false \
--define xnn_enable_avx512f=false \
--define xnn_enable_avx512skx=false \
--define xnn_enable_avx512vbmi=false \
--define xnn_enable_avx512vnni=false \
--define xnn_enable_avx512vnnigfni=false \
--define xnn_enable_avx512amx=false \
--define xnn_enable_avx512fp16=false \
--define xnn_enable_avx512bf16=false \
--define xnn_enable_hvx=false \
//xla/pjrt/c:pjrt_c_api_cpu_plugin.so

- name: "Package the binary"
run: |
# Create the tarball.
PJRT_C_API_HEADER="./xla/xla/pjrt/c/pjrt_c_api.h"
ZIP_NAME="pjrt_cpu_windows_amd64.zip"
BINARY_DIR="xla/bazel-bin/xla/pjrt/c"
BINARY_NAME="pjrt_c_api_cpu_plugin.so"
TARGET_NAME="pjrt_c_api_cpu_plugin.dll"
mv "xla/bazel-bin/xla/pjrt/c/${BINARY_NAME}" "${TARGET_NAME}"
7z a "$ZIP_NAME" "${TARGET_NAME}"
echo "ZIP_NAME=${ZIP_NAME}" >> $GITHUB_ENV

- name: Upload release asset
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.RELEASE }}
files: ${{ env.ZIP_NAME }}
name: CPU
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 10 additions & 0 deletions internal/patches/windows/export.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff --git a/xla/pjrt/c/pjrt_c_api_cpu.cc b/xla/pjrt/c/pjrt_c_api_cpu.cc
index 90e391f8..d5d51dd4 100644
--- a/xla/pjrt/c/pjrt_c_api_cpu.cc
+++ b/xla/pjrt/c/pjrt_c_api_cpu.cc
@@ -17,4 +17,5 @@ limitations under the License.
#include "xla/pjrt/c/pjrt_c_api.h"
#include "xla/pjrt/c/pjrt_c_api_cpu_internal.h"

+extern "C" __declspec(dllexport)
const PJRT_Api* GetPjrtApi() { return pjrt::cpu_plugin::GetCpuPjrtApi(); }