-
Notifications
You must be signed in to change notification settings - Fork 11.9k
ggml : add metal backend registry / device #9713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
37de34c
to
a62ea59
Compare
058430f
to
ae56ec2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This seems to be working now. |
7e8d2a9
to
84c3b2a
Compare
84c3b2a
to
6dcb899
Compare
Should we put a deprecate notice for these API calls? |
ggml/src/ggml-metal.m
Outdated
|
||
ggml_backend_t ggml_backend_reg_metal_init(const char * params, void * user_data) { | ||
static const char * ggml_backend_metal_device_get_description(ggml_backend_dev_t dev) { | ||
return [[g_state.mtl_device name] UTF8String]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is a guarantee that mtl_device
is initialized here, it probably needs a call to ggml_backend_metal_get_device
/ggml_backend_metal_free_device
like in ggml_backend_metal_device_get_memory
. However, I imagine that could cause issues with the lifetime of the string returned by MTLDevice
, so it may be necessary to keep a copy of the string in the context instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now.
I also reworked the implementation to avoid accessing g_state
when we can get the device context locally. Should be much cleaner now and easier to add multi-GPU support in the future if needed.
ggml/src/ggml-metal.m
Outdated
#if TARGET_OS_OSX || (TARGET_OS_IOS && __clang_major__ >= 15) | ||
if (@available(macOS 10.12, iOS 16.0, *)) { | ||
GGML_LOG_INFO("%s: recommendedMaxWorkingSetSize = %8.2f MB\n", __func__, ctx->device.recommendedMaxWorkingSetSize / 1e6); | ||
GGML_LOG_INFO("%s: recommendedMaxWorkingSetSize = %8.2f MB\n", __func__, device.recommendedMaxWorkingSetSize / 1e6); | ||
} | ||
#elif TARGET_OS_OSX | ||
if (ctx->device.maxTransferRate != 0) { | ||
GGML_LOG_INFO("%s: maxTransferRate = %8.2f MB/s\n", __func__, ctx->device.maxTransferRate / 1e6); | ||
if (device.maxTransferRate != 0) { | ||
GGML_LOG_INFO("%s: maxTransferRate = %8.2f MB/s\n", __func__, device.maxTransferRate / 1e6); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this #if/#elif
is correct, this will never be printed.
I think it may be too early for that, it's probably better to wait a bit until all the backends and the ggml examples are updated. |
* ggml : add metal backend registry / device ggml-ci * metal : fix names [no ci] * metal : global registry and device instances ggml-ci * cont : alternative initialization of global objects ggml-ci * llama : adapt to backend changes ggml-ci * fixes * metal : fix indent * metal : fix build when MTLGPUFamilyApple3 is not available ggml-ci * fix merge * metal : avoid unnecessary singleton accesses ggml-ci * metal : minor fix [no ci] * metal : g_state -> g_ggml_ctx_dev_main [no ci] * metal : avoid reference of device context in the backend context ggml-ci * metal : minor [no ci] * metal : fix maxTransferRate check * metal : remove transfer rate stuff --------- Co-authored-by: slaren <[email protected]>
* ggml : add metal backend registry / device ggml-ci * metal : fix names [no ci] * metal : global registry and device instances ggml-ci * cont : alternative initialization of global objects ggml-ci * llama : adapt to backend changes ggml-ci * fixes * metal : fix indent * metal : fix build when MTLGPUFamilyApple3 is not available ggml-ci * fix merge * metal : avoid unnecessary singleton accesses ggml-ci * metal : minor fix [no ci] * metal : g_state -> g_ggml_ctx_dev_main [no ci] * metal : avoid reference of device context in the backend context ggml-ci * metal : minor [no ci] * metal : fix maxTransferRate check * metal : remove transfer rate stuff --------- Co-authored-by: slaren <[email protected]>
* ggml : add metal backend registry / device ggml-ci * metal : fix names [no ci] * metal : global registry and device instances ggml-ci * cont : alternative initialization of global objects ggml-ci * llama : adapt to backend changes ggml-ci * fixes * metal : fix indent * metal : fix build when MTLGPUFamilyApple3 is not available ggml-ci * fix merge * metal : avoid unnecessary singleton accesses ggml-ci * metal : minor fix [no ci] * metal : g_state -> g_ggml_ctx_dev_main [no ci] * metal : avoid reference of device context in the backend context ggml-ci * metal : minor [no ci] * metal : fix maxTransferRate check * metal : remove transfer rate stuff --------- Co-authored-by: slaren <[email protected]>
target #9707
Adapt the Metal backend to the new registry and device interfaces.