From 3d99a8d31d344d10c23cc8704bbdbea568df9071 Mon Sep 17 00:00:00 2001 From: Awni Hannun Date: Thu, 18 Jan 2024 10:01:59 -0800 Subject: [PATCH] Fix format / build (#489) --- mlx/backend/no_metal/metal.cpp | 6 ++++++ tests/metal_tests.cpp | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/mlx/backend/no_metal/metal.cpp b/mlx/backend/no_metal/metal.cpp index 0005a65a9..257fcbb5d 100644 --- a/mlx/backend/no_metal/metal.cpp +++ b/mlx/backend/no_metal/metal.cpp @@ -19,4 +19,10 @@ std::function make_task( "[metal::make_task] Cannot make GPU task without metal backend"); } +// No cache for CPU only +bool cache_enabled(void) { + return false; +} +void set_cache_enabled(bool) {} + } // namespace mlx::core::metal diff --git a/tests/metal_tests.cpp b/tests/metal_tests.cpp index 9e6264d7c..1c748268e 100644 --- a/tests/metal_tests.cpp +++ b/tests/metal_tests.cpp @@ -3,9 +3,9 @@ #include #include "doctest/doctest.h" +#include "mlx/backend/metal/allocator.h" #include "mlx/backend/metal/device.h" #include "mlx/backend/metal/metal.h" -#include "mlx/backend/metal/allocator.h" #include "mlx/mlx.h" using namespace mlx::core; @@ -479,36 +479,37 @@ TEST_CASE("test metal enable/disable cache") { metal::set_cache_enabled(true); CHECK(metal::cache_enabled()); - auto &a = metal::allocator(); + auto& a = metal::allocator(); auto size = 100; auto buf = a.malloc(size, false); - + // Release a a.free(buf); - + // Check size should equals to size CHECK_EQ(static_cast(buf.ptr())->length(), size); } - + // Test disable metal cache { metal::set_cache_enabled(false); CHECK(!metal::cache_enabled()); - auto &a = metal::allocator(); + auto& a = metal::allocator(); auto size = 100; auto buf = a.malloc(size, false); auto buf_ptr = static_cast(buf.ptr()); unsigned char first_byte = *reinterpret_cast(buf_ptr); printf("first byte: %d\n", first_byte); - + // Release a a.free(buf); - - // If release successfully, the first byte should be different from the first byte before release + + // If release successfully, the first byte should be different from the + // first byte before release unsigned char new_first_byte = *reinterpret_cast(buf_ptr); printf("new first byte: %d\n", new_first_byte); - + CHECK_NE(new_first_byte, first_byte); } }