Skip to content

Commit 617fd9c

Browse files
authored
Use C++20 (ml-explore#3050)
1 parent 8e93b74 commit 617fd9c

7 files changed

Lines changed: 21 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ project(
2222

2323
# ----------------------------- Setup -----------------------------
2424
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
25-
set(CMAKE_CXX_STANDARD 17)
25+
set(CMAKE_CXX_STANDARD 20)
2626
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2727
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2828
set(CMAKE_INSTALL_MESSAGE NEVER)

docs/src/dev/mlx_in_cpp.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The next step is to setup a CMake file in ``CMakeLists.txt``:
4545
4646
project(example LANGUAGES CXX)
4747
48-
set(CMAKE_CXX_STANDARD 17)
48+
set(CMAKE_CXX_STANDARD 20)
4949
set(CMAKE_CXX_STANDARD_REQUIRED ON)
5050
5151

docs/src/install.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Build from source
8383
Build Requirements
8484
^^^^^^^^^^^^^^^^^^
8585

86-
- A C++ compiler with C++17 support (e.g. Clang >= 5.0)
86+
- A C++ compiler with C++20 support (e.g. Clang >= 15.0)
8787
- `cmake <https://cmake.org/>`_ -- version 3.25 or later, and ``make``
8888
- Xcode >= 15.0 and macOS SDK >= 14.0
8989

mlx/backend/cpu/simd/base_simd.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#pragma once
22

3+
// Required for using M_LN2 in MSVC.
4+
#define _USE_MATH_DEFINES
5+
6+
#include <math.h>
37
#include <stdint.h>
48
#include <algorithm>
5-
#include <cmath>
69
#include <complex>
710
#include <functional>
811

mlx/backend/cuda/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ endif()
126126
target_compile_options(
127127
mlx PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:--Wno-deprecated-gpu-targets>")
128128

129-
# Suppress nvcc warnings on MLX headers.
130-
target_compile_options(mlx PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-Xcudafe
131-
--diag_suppress=997>)
129+
# Suppress nvcc warnings on C++ headers.
130+
target_compile_options(
131+
mlx PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-Xcudafe="--diag_suppress=997,20208">)
132132

133133
# Use stronger binaries compression. This feature was introduced in CUDA 12.8
134134
# and requires drivers released after CUDA 12.4.

mlx/backend/metal/indexing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ void MaskedScatter::eval_gpu(const std::vector<array>& inputs, array& out) {
697697
auto lib = d.get_library(kernel_name, [&]() {
698698
std::string source = metal::utils();
699699
source += metal::masked_scatter();
700-
source += fmt::format(
701-
std::string(masked_assign_kernel), kernel_name, value_type, contiguous);
700+
source +=
701+
fmt::format(masked_assign_kernel, kernel_name, value_type, contiguous);
702702
return source;
703703
});
704704
auto kernel = d.get_kernel(kernel_name, lib);

tests/einsum_tests.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55

66
using namespace mlx::core;
77

8+
namespace std {
9+
10+
// Required to make doctest compile.
11+
ostream& operator<<(ostream& os, const vector<vector<int>>&) {
12+
return os;
13+
}
14+
15+
} // namespace std
16+
817
TEST_CASE("test einsum path") {
918
std::vector<std::vector<int>> expected = {{1, 2}, {0, 1}};
1019
auto path =

0 commit comments

Comments
 (0)