Skip to content

Commit 2118c3d

Browse files
authored
fix (#255)
1 parent a002797 commit 2118c3d

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

mlx/backend/metal/device.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace fs = std::filesystem;
1717

1818
namespace mlx::core::metal {
1919

20+
static Device metal_device_;
21+
2022
namespace {
2123

2224
// TODO nicer way to set this or possibly expose as an environment variable
@@ -108,16 +110,6 @@ MTL::Library* load_library(
108110
}
109111
}
110112

111-
struct PoolHolder {
112-
PoolHolder() {
113-
p = NS::AutoreleasePool::alloc()->init();
114-
}
115-
~PoolHolder() {
116-
p->release();
117-
}
118-
NS::AutoreleasePool* p;
119-
};
120-
121113
} // namespace
122114

123115
Device::Device()
@@ -293,13 +285,13 @@ MTL::ComputePipelineState* Device::get_kernel(
293285
}
294286

295287
Device& device(mlx::core::Device) {
296-
static Device metal_device_;
297288
return metal_device_;
298289
}
299290

300291
NS::AutoreleasePool*& thread_autorelease_pool() {
301-
static thread_local PoolHolder pool{};
302-
return pool.p;
292+
static thread_local NS::AutoreleasePool* p =
293+
NS::AutoreleasePool::alloc()->init();
294+
return p;
303295
}
304296

305297
void new_stream(Stream stream) {

0 commit comments

Comments
 (0)