Skip to content

Problem when use with iOS and Metal: GGML_METAL_ADD_KERNEL #1377

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

Closed
paulocoutinhox opened this issue Oct 18, 2023 · 5 comments
Closed

Problem when use with iOS and Metal: GGML_METAL_ADD_KERNEL #1377

paulocoutinhox opened this issue Oct 18, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@paulocoutinhox
Copy link

Hi,

Im trying compile for iOS, but get this error:

/Users/paulo/Developer/workspaces/cpp/ai-kit/vendor/whisper/ggml-metal.m:218:9: error: cast of Objective-C pointer type 'id<MTLComputePipelineState>' to C pointer type 'void *' requires a bridged cast
        GGML_METAL_ADD_KERNEL(add);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/paulo/Developer/workspaces/cpp/ai-kit/vendor/whisper/ggml-metal.m:210:107: note: expanded from macro 'GGML_METAL_ADD_KERNEL'
        metal_printf("%s: loaded %-32s %16p | th_max = %4d | th_width = %4d\n", __func__, "kernel_"#name, (void *) ctx->pipeline_##name, \
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/paulo/Developer/workspaces/cpp/ai-kit/vendor/whisper/ggml-metal.m:18:43: note: expanded from macro 'metal_printf'
#define metal_printf(...) fprintf(stderr, __VA_ARGS__)
                                          ^~~~~~~~~~~
/Users/paulo/Developer/workspaces/cpp/ai-kit/vendor/whisper/ggml-metal.m:218:9: note: use __bridge to convert directly (no change in ownership)
/Users/paulo/Developer/workspaces/cpp/ai-kit/vendor/whisper/ggml-metal.m:210:107: note: expanded from macro 'GGML_METAL_ADD_KERNEL'
        metal_printf("%s: loaded %-32s %16p | th_max = %4d | th_width = %4d\n", __func__, "kernel_"#name, (void *) ctx->pipeline_##name, \
                                                                                                          ^
/Users/paulo/Developer/workspaces/cpp/ai-kit/vendor/whisper/ggml-metal.m:218:9: note: use CFBridgingRetain call to make an ARC object available as a +1 'void *'
/Users/paulo/Developer/workspaces/cpp/ai-kit/vendor/whisper/ggml-metal.m:210:116: note: expanded from macro 'GGML_METAL_ADD_KERNEL'
        metal_printf("%s: loaded %-32s %16p | th_max = %4d | th_width = %4d\n", __func__, "kernel_"#name, (void *) ctx->pipeline_##name, \

In this line:
https://github.com/ggerganov/whisper.cpp/blob/master/ggml-metal.m#L207-L218

How can i solve this?

Thanks.

@bobqianic
Copy link
Collaborator

See this #1293

@bobqianic bobqianic added the bug Something isn't working label Oct 18, 2023
@jhen0409
Copy link
Contributor

jhen0409 commented Oct 19, 2023

I think it's because the project has ARC enabled, try to use -fno-objc-arc for ggml-metal.m if allowed (I did this in #1293), or try to patch it like I did in whisper.rn.

@paulocoutinhox
Copy link
Author

paulocoutinhox commented Oct 19, 2023

Hi,

I have created a new project (has main.cpp and CMakeLists.txt) to try do what you sad and it pass when i add -fno-obj-arc:
https://github.com/paulocoutinhox/ggml-test

Now, it stop in other problem, ggml methods are not visible:
https://github.com/paulocoutinhox/ggml-test/actions/runs/6570636731/job/17848379609#step:6:391

I tried a lof of options and nothing.

Log:

Ld /Users/runner/work/ggml-test/ggml-test/build/lib/sample.framework/sample normal (in target 'sample' from project 'sample')
    cd /Users/runner/work/ggml-test/ggml-test
    /Applications/Xcode_14.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target arm64-apple-ios11.0 -dynamiclib -isysroot /Applications/Xcode_14.2.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.2.sdk -L/Users/runner/work/ggml-test/ggml-test/build/EagerLinkingTBDs -L/Users/runner/work/ggml-test/ggml-test/build/lib -F/Users/runner/work/ggml-test/ggml-test/build/EagerLinkingTBDs -F/Users/runner/work/ggml-test/ggml-test/build/lib -filelist /Users/runner/work/ggml-test/ggml-test/build/sample.build/Debug-iphoneos/sample.build/Objects-normal/arm64/sample.LinkFileList -install_name @rpath/sample.framework/sample -dead_strip -Xlinker -object_path_lto -Xlinker /Users/runner/work/ggml-test/ggml-test/build/sample.build/Debug-iphoneos/sample.build/Objects-normal/arm64/sample_lto.o -Xlinker -no_deduplicate -stdlib\=libc++ -rpath @executable_path/Frameworks -rpath @loader_path/Frameworks -Xlinker -framework -Xlinker Foundation -Xlinker -framework -Xlinker Accelerate -Xlinker -framework -Xlinker Metal -Xlinker -framework -Xlinker MetalKit /Users/runner/work/ggml-test/ggml-test/build/whisper/lib/libwhisper.a -compatibility_version 1.0.0 -current_version 1.0.0 -Xlinker -dependency_info -Xlinker /Users/runner/work/ggml-test/ggml-test/build/sample.build/Debug-iphoneos/sample.build/Objects-normal/arm64/sample_dependency_info.dat -o /Users/runner/work/ggml-test/ggml-test/build/lib/sample.framework/sample
Undefined symbols for architecture arm64:
  "_ggml_add", referenced from:
      ggml_mul_mat_pad(ggml_context*, ggml_tensor*, ggml_tensor*, int) in libwhisper.a(whisper.o)
      whisper_build_graph_conv(whisper_context&, whisper_state&, int) in libwhisper.a(whisper.o)
      whisper_build_graph_encoder(whisper_context&, whisper_state&) in libwhisper.a(whisper.o)
      whisper_build_graph_cross(whisper_context&, whisper_state&) in libwhisper.a(whisper.o)
      whisper_build_graph_decoder(whisper_context&, whisper_state&, whisper_decoder&, int const*, int, int) in libwhisper.a(whisper.o)
  "_ggml_allocr_alloc", referenced from:
      whisper_build_graph_conv(whisper_context&, whisper_state&, int) in libwhisper.a(whisper.o)
      whisper_build_graph_encoder(whisper_context&, whisper_state&) in libwhisper.a(whisper.o)
      whisper_build_graph_cross(whisper_context&, whisper_state&) in libwhisper.a(whisper.o)
      whisper_build_graph_decoder(whisper_context&, whisper_state&, whisper_decoder&, int const*, int, int) in libwhisper.a(whisper.o)
  "_ggml_allocr_alloc_graph", referenced from:
      whisper_allocr_graph_init(whisper_allocr&, std::__1::function<ggml_cgraph* ()>&&) in libwhisper.a(whisper.o)
      whisper_encode_internal(whisper_context&, whisper_state&, int, int, bool (*)(void*), void*) in libwhisper.a(whisper.o)
      whisper_decode_internal(whisper_context&, whisper_state&, whisper_decoder&, int const*, int, int, int, bool (*)(void*), void*) in libwhisper.a(whisper.o)
  "_ggml_allocr_free", referenced from:
      whisper_allocr_graph_init(whisper_allocr&, std::__1::function<ggml_cgraph* ()>&&) in libwhisper.a(whisper.o)
      whisper_allocr_free(whisper_allocr&) in libwhisper.a(whisper.o)
  "_ggml_allocr_is_measure", referenced from:
      whisper_build_graph_conv(whisper_context&, whisper_state&, int) in libwhisper.a(whisper.o)
      whisper_build_graph_encoder(whisper_context&, whisper_state&) in libwhisper.a(whisper.o)
      whisper_build_graph_cross(whisper_context&, whisper_state&) in libwhisper.a(whisper.o)
      whisper_build_graph_decoder(whisper_context&, whisper_state&, whisper_decoder&, int const*, int, int) in libwhisper.a(whisper.o)
  "_ggml_allocr_new", referenced from:
      whisper_allocr_graph_init(whisper_allocr&, std::__1::function<ggml_cgraph* ()>&&) in libwhisper.a(whisper.o)
  "_ggml_allocr_new_measure", referenced from:
      whisper_allocr_graph_init(whisper_allocr&, std::__1::function<ggml_cgraph* ()>&&) in libwhisper.a(whisper.o)
  "_ggml_allocr_reset", referenced from:
      whisper_encode_internal(whisper_context&, whisper_state&, int, int, bool (*)(void*), void*) in libwhisper.a(whisper.o)
      whisper_decode_internal(whisper_context&, whisper_state&, whisper_decoder&, int const*, int, int, int, bool (*)(void*), void*) in libwhisper.a(whisper.o)

@paulocoutinhox
Copy link
Author

There is something that i need set in CMake to make ggml visible? Their symbols are not visible.

@paulocoutinhox
Copy link
Author

Hi,

I solve the problems adding C to the cmake project language.

project(xplpc LANGUAGES C CXX)

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants