|
3 | 3 | #include <array> |
4 | 4 | #include "doctest/doctest.h" |
5 | 5 |
|
| 6 | +#include "mlx/backend/metal/allocator.h" |
6 | 7 | #include "mlx/backend/metal/device.h" |
7 | 8 | #include "mlx/backend/metal/metal.h" |
8 | | -#include "mlx/backend/metal/allocator.h" |
9 | 9 | #include "mlx/mlx.h" |
10 | 10 |
|
11 | 11 | using namespace mlx::core; |
@@ -479,36 +479,37 @@ TEST_CASE("test metal enable/disable cache") { |
479 | 479 | metal::set_cache_enabled(true); |
480 | 480 | CHECK(metal::cache_enabled()); |
481 | 481 |
|
482 | | - auto &a = metal::allocator(); |
| 482 | + auto& a = metal::allocator(); |
483 | 483 | auto size = 100; |
484 | 484 | auto buf = a.malloc(size, false); |
485 | | - |
| 485 | + |
486 | 486 | // Release a |
487 | 487 | a.free(buf); |
488 | | - |
| 488 | + |
489 | 489 | // Check size should equals to size |
490 | 490 | CHECK_EQ(static_cast<MTL::Buffer*>(buf.ptr())->length(), size); |
491 | 491 | } |
492 | | - |
| 492 | + |
493 | 493 | // Test disable metal cache |
494 | 494 | { |
495 | 495 | metal::set_cache_enabled(false); |
496 | 496 | CHECK(!metal::cache_enabled()); |
497 | 497 |
|
498 | | - auto &a = metal::allocator(); |
| 498 | + auto& a = metal::allocator(); |
499 | 499 | auto size = 100; |
500 | 500 | auto buf = a.malloc(size, false); |
501 | 501 | auto buf_ptr = static_cast<MTL::Buffer*>(buf.ptr()); |
502 | 502 | unsigned char first_byte = *reinterpret_cast<unsigned char*>(buf_ptr); |
503 | 503 | printf("first byte: %d\n", first_byte); |
504 | | - |
| 504 | + |
505 | 505 | // Release a |
506 | 506 | a.free(buf); |
507 | | - |
508 | | - // If release successfully, the first byte should be different from the first byte before release |
| 507 | + |
| 508 | + // If release successfully, the first byte should be different from the |
| 509 | + // first byte before release |
509 | 510 | unsigned char new_first_byte = *reinterpret_cast<unsigned char*>(buf_ptr); |
510 | 511 | printf("new first byte: %d\n", new_first_byte); |
511 | | - |
| 512 | + |
512 | 513 | CHECK_NE(new_first_byte, first_byte); |
513 | 514 | } |
514 | 515 | } |
0 commit comments