interruptable eval

This commit is contained in:
Awni Hannun
2025-03-18 17:23:31 -07:00
parent 0a9777aa5c
commit 9ffe88841c
3 changed files with 33 additions and 1 deletions

View File

@@ -1,5 +1,4 @@
// Copyright © 2023 Apple Inc.
#include "doctest/doctest.h"
#include "mlx/mlx.h"
@@ -91,3 +90,16 @@ TEST_CASE("test eval graph retention when not tracing") {
CHECK(!a.has_primitive());
CHECK(a.is_available());
}
TEST_CASE("test interrupt eval") {
auto x = zeros({1024}, int32);
for (int i = 0; i < 1000; ++i) {
x = x + 1;
}
std::thread t([x]() { eval(x); });
interrupt_eval();
t.join();
// Check that x is not evaluated
CHECK(!x.is_available());
CHECK(array_equal(x, full({1024}, 1000, int32)).item<bool>());
}