Skip to content
Open
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
18 changes: 18 additions & 0 deletions .github/actions/build-windows/action.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 37 additions & 0 deletions .github/actions/setup-windows/action.yml
Original file line number Diff line number Diff line change
@@ -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/ccache-action@v1.2
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 changes: 13 additions & 0 deletions .github/actions/test-windows/action.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
12 changes: 12 additions & 0 deletions mlx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mlx/backend/cpu/indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
15 changes: 14 additions & 1 deletion mlx/backend/cpu/simd/base_simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}};
Expand Down Expand Up @@ -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>
Expand Down
Loading