mirror of
https://github.com/ml-explore/mlx.git
synced 2025-06-24 09:21:16 +08:00
fix version and expose command queue getter (#1892)
This commit is contained in:
parent
10b271d963
commit
8ff84b5c43
@ -1,8 +1,14 @@
|
|||||||
cmake_minimum_required(VERSION 3.25)
|
cmake_minimum_required(VERSION 3.25)
|
||||||
|
|
||||||
if(NOT MLX_VERSION)
|
if(NOT MLX_VERSION)
|
||||||
set(MLX_VERSION 0.23.1)
|
file(STRINGS "mlx/version.h" _mlx_h_version REGEX "^#define MLX_VERSION_.*$")
|
||||||
set(MLX_PROJECT_VERSION ${MLX_VERSION})
|
string(REGEX MATCH "#define MLX_VERSION_MAJOR ([0-9]+)" _ "${_mlx_h_version}")
|
||||||
|
set(_major ${CMAKE_MATCH_1})
|
||||||
|
string(REGEX MATCH "#define MLX_VERSION_MINOR ([0-9]+)" _ "${_mlx_h_version}")
|
||||||
|
set(_minor ${CMAKE_MATCH_1})
|
||||||
|
string(REGEX MATCH "#define MLX_VERSION_PATCH ([0-9]+)" _ "${_mlx_h_version}")
|
||||||
|
set(_patch ${CMAKE_MATCH_1})
|
||||||
|
set(MLX_PROJECT_VERSION "${_major}.${_minor}.${_patch}")
|
||||||
else()
|
else()
|
||||||
string(REGEX REPLACE "^([0-9]+\.[0-9]+\.[0-9]+).*" "\\1" MLX_PROJECT_VERSION
|
string(REGEX REPLACE "^([0-9]+\.[0-9]+\.[0-9]+).*" "\\1" MLX_PROJECT_VERSION
|
||||||
${MLX_VERSION})
|
${MLX_VERSION})
|
||||||
@ -35,17 +41,7 @@ option(MLX_BUILD_BLAS_FROM_SOURCE "Build OpenBLAS from source code" OFF)
|
|||||||
option(MLX_METAL_JIT "Use JIT compilation for Metal kernels" OFF)
|
option(MLX_METAL_JIT "Use JIT compilation for Metal kernels" OFF)
|
||||||
option(BUILD_SHARED_LIBS "Build mlx as a shared library" OFF)
|
option(BUILD_SHARED_LIBS "Build mlx as a shared library" OFF)
|
||||||
|
|
||||||
math(
|
add_compile_definitions("MLX_VERSION=${MLX_VERSION}")
|
||||||
EXPR
|
|
||||||
MLX_VERSION_NUMERIC
|
|
||||||
"1000000 * ${PROJECT_VERSION_MAJOR} + 1000 * ${PROJECT_VERSION_MINOR} + ${PROJECT_VERSION_PATCH}"
|
|
||||||
OUTPUT_FORMAT DECIMAL)
|
|
||||||
add_compile_definitions(
|
|
||||||
"MLX_VERSION=${MLX_VERSION}"
|
|
||||||
"MLX_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}"
|
|
||||||
"MLX_VERSION_MINOR=${PROJECT_VERSION_MINOR}"
|
|
||||||
"MLX_VERSION_PATCH=${PROJECT_VERSION_PATCH}"
|
|
||||||
"MLX_VERSION_NUMERIC=${MLX_VERSION_NUMERIC}")
|
|
||||||
|
|
||||||
# --------------------- Processor tests -------------------------
|
# --------------------- Processor tests -------------------------
|
||||||
message(
|
message(
|
||||||
|
@ -17,6 +17,7 @@ target_sources(
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/transforms.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/transforms.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/linalg.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/linalg.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/version.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/backend/metal/metal.h)
|
${CMAKE_CURRENT_SOURCE_DIR}/backend/metal/metal.h)
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
|
@ -254,9 +254,6 @@ Device::~Device() {
|
|||||||
|
|
||||||
void Device::new_queue(int index) {
|
void Device::new_queue(int index) {
|
||||||
auto thread_pool = metal::new_scoped_memory_pool();
|
auto thread_pool = metal::new_scoped_memory_pool();
|
||||||
|
|
||||||
// Multiple threads can ask the device for queues
|
|
||||||
// We lock this as a critical section for safety
|
|
||||||
auto q = device_->newCommandQueue(MAX_BUFFERS_PER_QUEUE);
|
auto q = device_->newCommandQueue(MAX_BUFFERS_PER_QUEUE);
|
||||||
debug_set_stream_queue_label(q, index);
|
debug_set_stream_queue_label(q, index);
|
||||||
if (!q) {
|
if (!q) {
|
||||||
@ -269,6 +266,10 @@ void Device::new_queue(int index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MTL::CommandQueue* Device::get_queue(Stream stream) {
|
||||||
|
return get_stream_(stream.index).queue;
|
||||||
|
}
|
||||||
|
|
||||||
bool Device::command_buffer_needs_commit(int index) {
|
bool Device::command_buffer_needs_commit(int index) {
|
||||||
auto& stream = get_stream_(index);
|
auto& stream = get_stream_(index);
|
||||||
if (stream.buffer_ops > max_ops_per_buffer_ ||
|
if (stream.buffer_ops > max_ops_per_buffer_ ||
|
||||||
|
@ -178,6 +178,9 @@ class Device {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void new_queue(int index);
|
void new_queue(int index);
|
||||||
|
|
||||||
|
MTL::CommandQueue* get_queue(Stream stream);
|
||||||
|
|
||||||
MTL::CommandBuffer* get_command_buffer(int index);
|
MTL::CommandBuffer* get_command_buffer(int index);
|
||||||
bool command_buffer_needs_commit(int index);
|
bool command_buffer_needs_commit(int index);
|
||||||
void commit_command_buffer(int index);
|
void commit_command_buffer(int index);
|
||||||
|
16
mlx/version.cpp
Normal file
16
mlx/version.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright © 2025 Apple Inc.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "mlx/version.h"
|
||||||
|
|
||||||
|
#define STRINGIFY(x) #x
|
||||||
|
#define TOSTRING(x) STRINGIFY(x)
|
||||||
|
|
||||||
|
namespace mlx::core {
|
||||||
|
|
||||||
|
std::string version() {
|
||||||
|
return TOSTRING(MLX_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace mlx::core
|
@ -1,32 +1,20 @@
|
|||||||
// Copyright © 2023-2024 Apple Inc.
|
// Copyright © 2025 Apple Inc.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#define MLX_VERSION_MAJOR 0
|
||||||
|
#define MLX_VERSION_MINOR 24
|
||||||
#define STRINGIFY(x) #x
|
#define MLX_VERSION_PATCH 2
|
||||||
#define TOSTRING(x) STRINGIFY(x)
|
#define MLX_VERSION_NUMERIC \
|
||||||
|
(100000 * MLX_VERSION_MAJOR + 1000 * MLX_VERSION_MINOR + MLX_VERSION_PATCH)
|
||||||
|
|
||||||
namespace mlx::core {
|
namespace mlx::core {
|
||||||
|
|
||||||
constexpr const char* version() {
|
/* A string representation of the MLX version in the format
|
||||||
return TOSTRING(MLX_VERSION);
|
* "major.minor.patch".
|
||||||
}
|
*
|
||||||
|
* For dev builds, the version will include the suffix ".devYYYYMMDD+hash"
|
||||||
constexpr int version_major() {
|
*/
|
||||||
return MLX_VERSION_MAJOR;
|
std::string version();
|
||||||
}
|
|
||||||
|
|
||||||
constexpr int version_minor() {
|
|
||||||
return MLX_VERSION_MINOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr int version_patch() {
|
|
||||||
return MLX_VERSION_PATCH;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr int version_numeric() {
|
|
||||||
return MLX_VERSION_NUMERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace mlx::core
|
} // namespace mlx::core
|
||||||
|
Loading…
Reference in New Issue
Block a user