Windows CI (#3021)

This commit is contained in:
Cheng
2026-01-21 08:06:32 +09:00
committed by GitHub
parent 83bb7891db
commit bfd62a50f4
8 changed files with 107 additions and 6 deletions
+18
View File
@@ -0,0 +1,18 @@
name: 'Build on Windows'
runs:
using: 'composite'
steps:
- name: Build CPP only
shell: cmd
env:
# For MSVC, Ninja/Release is the only config supported by ccache.
CMAKE_ARGS: >-
-G Ninja
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=cl
-DCMAKE_CXX_COMPILER=cl
-DCMAKE_RC_COMPILER=rc
run: |
cmake . -B build %CMAKE_ARGS%
cmake --build build -j %NUMBER_OF_PROCESSORS%
+37
View File
@@ -0,0 +1,37 @@
name: 'Setup Windows environment'
inputs:
python-version:
description: 'Version of python to set up'
required: false
default: '3.14'
use-ccache:
description: 'Whether to enable ccache'
required: false
default: 'true'
runs:
using: 'composite'
steps:
- name: Use ccache
if: ${{ inputs.use-ccache == 'true' }}
uses: hendrikmuhs/[email protected]
with:
key: ccache-${{ runner.os }}-${{ runner.arch }}-cpu
max-size: 1GB
- uses: actions/setup-python@v6
with:
python-version: ${{ inputs.python-version }}
- name: Setup Visual Studio cmd
shell: cmd
run: |
:: Find out path to VS.
pushd "C:\Program Files (x86)\Microsoft Visual Studio\Installer\"
for /f "delims=" %%x in ('.\vswhere.exe -latest -property InstallationPath') do set VSPATH=%%x
popd
:: Import VS vars.
call "%VSPATH%\VC\Auxiliary\Build\vcvarsall.bat" x64
:: Export to all steps.
>>%GITHUB_ENV% set
+13
View File
@@ -0,0 +1,13 @@
name: 'Run tests on Windows'
runs:
using: 'composite'
steps:
- name: Run CPP tests - CPU
shell: bash
env:
DEVICE: cpu
run: |
echo "::group::CPP tests - CPU"
./build/tests/tests -tce="*gguf*,test random uniform"
echo "::endgroup::"
+12
View File
@@ -76,6 +76,18 @@ jobs:
- uses: ./.github/actions/setup-macos
- uses: ./.github/actions/build-macos
windows_build_and_test:
name: Windows (cpu, x86_64)
needs: check_lint
runs-on: windows-2025
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/setup-windows
with:
use-ccache: false
- uses: ./.github/actions/build-windows
- uses: ./.github/actions/test-windows
build_documentation:
name: Build Documentation
if: github.repository == 'ml-explore/mlx'
-4
View File
@@ -150,10 +150,6 @@ cmake_policy(SET CMP0135 NEW)
add_library(mlx)
# Supress warnings: note: parameter passing for argument of type
# std::pair<float, float> when C++17 is enabled changed to match C++14 in GCC
# 10.1
target_compile_options(mlx PRIVATE -Wno-psabi)
target_compile_options(mlx PUBLIC ${SANITIZER_COMPILE_FLAGS})
target_link_options(mlx PUBLIC ${SANITIZER_LINK_FLAGS})
+12
View File
@@ -24,9 +24,21 @@ add_library(mlx_version OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp)
target_compile_definitions(mlx_version PRIVATE MLX_VERSION="${MLX_VERSION}")
target_link_libraries(mlx PRIVATE $<BUILD_INTERFACE:mlx_version>)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Supress warnings: note: parameter passing for argument of type
# std::pair<float, float> when C++17 is enabled changed to match C++14 in
# GCC 10.1
target_compile_options(mlx PRIVATE -Wno-psabi)
endif()
if(MSVC)
# Disable some MSVC warnings to speed up compilation.
target_compile_options(mlx PUBLIC /wd4068 /wd4244 /wd4267 /wd4804)
# Enable /bigobj for heavily templated code (e.g., binary.cpp) that exceeds
# the default 65,535 section limit in COFF object files. Use generator
# expression to only apply to C/CXX, not CUDA (NVCC doesn't understand /bigobj
# directly).
target_compile_options(mlx PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/bigobj>)
endif()
if(WIN32)
+1 -1
View File
@@ -761,7 +761,7 @@ void masked_scatter_impl(const array& mask, const array& src, array& out) {
const size_t mask_batch_size = mask.size() / batch_count;
const size_t src_batch_size = src.size() / batch_count;
for (uint b = 0; b < batch_count; ++b) {
for (size_t b = 0; b < batch_count; ++b) {
size_t src_consumed = 0;
src_it.seek(b * src_batch_size);
+14 -1
View File
@@ -6,6 +6,10 @@
#include <complex>
#include <functional>
#ifdef _MSC_VER
#include <intrin.h> // For _BitScanReverse
#endif
namespace mlx::core::simd {
template <typename T, int N>
struct Simd;
@@ -105,7 +109,7 @@ Simd<T, 1> log1p(Simd<T, 1> in) {
if (r == 0) { // handle underflow
return Simd<T, 1>{T{x, theta}};
}
return Simd<T, 1>{T{((typeof(x))(0.5)) * std::log1p(r), theta}};
return Simd<T, 1>{T{((decltype(x))(0.5)) * std::log1p(r), theta}};
} else {
auto z0 = std::hypot(x + 1, y);
return Simd<T, 1>{T{std::log(z0), theta}};
@@ -173,7 +177,16 @@ DEFAULT_BINARY(||)
template <typename T>
Simd<T, 1> clz(Simd<T, 1> x_) {
#ifdef _MSC_VER
// MSVC doesn't have __builtin_clz, use _BitScanReverse instead
unsigned long index;
if (_BitScanReverse(&index, static_cast<unsigned long>(x_.value))) {
return static_cast<T>(31 - index);
}
return static_cast<T>(32); // All zeros case
#else
return __builtin_clz(x_.value);
#endif
}
template <typename T>