5#include <Metal/Metal.hpp>
9#include <unordered_map>
10#include <unordered_set>
18 std::vector<std::tuple<const void*, MTL::DataType, NS::UInteger>>;
27 enc.concurrent =
true;
30 enc.concurrent =
false;
32 enc.concurrent_outputs.begin(), enc.concurrent_outputs.end());
33 enc.concurrent_outputs.clear();
58 int num_dispatches{0};
59 MTL::CommandBuffer* cbuf;
60 MTL::ComputeCommandEncoder* enc;
61 bool concurrent{
false};
62 std::unordered_set<MTL::Resource*> outputs;
63 std::unordered_set<MTL::Resource*> concurrent_outputs;
86 const std::string& lib_name,
87 const std::string& lib_path);
94 const std::string& name,
95 const std::string& source_string,
99 const std::string& name,
100 const MTL::StitchedLibraryDescriptor* desc,
104 const std::string& base_name,
105 MTL::Library* mtl_lib,
106 const std::string& specialized_name =
"",
110 const std::string& base_name,
111 const std::string& lib_name =
"mlx",
112 const std::string& specialized_name =
"",
116 const std::string& base_name,
117 MTL::Library* mtl_lib,
118 const std::string& hash_name =
"",
120 const std::vector<MTL::Function*>& linked_functions = {});
123 const std::string& base_name,
124 const std::string& lib_name =
"mlx",
125 const std::string& hash_name =
"",
127 const std::vector<MTL::Function*>& linked_functions = {});
130 const std::vector<MTL::ArgumentDescriptor*>& arg_descs)
const;
133 MTL::Library* get_library_cache_(
const std::string& name);
135 MTL::Library* get_library_(
const std::string& source_string);
136 MTL::Library* get_library_(
const MTL::StitchedLibraryDescriptor* desc);
138 MTL::Function* get_function_(
const std::string& name, MTL::Library* mtl_lib);
140 MTL::Function* get_function_(
141 const std::string& name,
142 const std::string& specialized_name,
144 MTL::Library* mtl_lib);
146 MTL::LinkedFunctions* get_linked_functions_(
147 const std::vector<MTL::Function*>& funcs);
149 MTL::ComputePipelineState* get_kernel_(
150 const std::string& name,
151 const MTL::Function* mtl_function);
153 MTL::ComputePipelineState* get_kernel_(
154 const std::string& name,
155 const MTL::Function* mtl_function,
156 const MTL::LinkedFunctions* linked_functions);
158 MTL::Device* device_;
159 std::unordered_map<int32_t, MTL::CommandQueue*> queue_map_;
160 std::unordered_map<int32_t, std::pair<int, MTL::CommandBuffer*>> buffer_map_;
161 std::unordered_map<int32_t, std::unique_ptr<CommandEncoder>> encoder_map_;
162 std::unordered_map<std::string, MTL::ComputePipelineState*> kernel_map_;
163 std::unordered_map<std::string, MTL::Library*> library_map_;
~ConcurrentContext()
Definition device.h:29
ConcurrentContext(CommandEncoder &enc)
Definition device.h:26