Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
awni authored Dec 22, 2023
1 parent a002797 commit 2118c3d
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions mlx/backend/metal/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace fs = std::filesystem;

namespace mlx::core::metal {

static Device metal_device_;

namespace {

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

struct PoolHolder {
PoolHolder() {
p = NS::AutoreleasePool::alloc()->init();
}
~PoolHolder() {
p->release();
}
NS::AutoreleasePool* p;
};

} // namespace

Device::Device()
Expand Down Expand Up @@ -293,13 +285,13 @@ MTL::ComputePipelineState* Device::get_kernel(
}

Device& device(mlx::core::Device) {
static Device metal_device_;
return metal_device_;
}

NS::AutoreleasePool*& thread_autorelease_pool() {
static thread_local PoolHolder pool{};
return pool.p;
static thread_local NS::AutoreleasePool* p =
NS::AutoreleasePool::alloc()->init();
return p;
}

void new_stream(Stream stream) {
Expand Down

0 comments on commit 2118c3d

Please sign in to comment.