Skip to content
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

ggml-alloc : use virtual memory for measurement #2973

Merged
merged 3 commits into from
Sep 3, 2023
Merged

ggml-alloc : use virtual memory for measurement #2973

merged 3 commits into from
Sep 3, 2023

Conversation

slaren
Copy link
Collaborator

@slaren slaren commented Sep 2, 2023

Instead of using a fixed memory address, allocates an uncommitted virtual memory region that is guaranteed to not overlap with any other allocations. Should solve issues with most 32-bit platforms and OS X. Wasm may still be an issue, as I don't think it supports mmap.

@slaren slaren marked this pull request as draft September 2, 2023 20:39
@slaren slaren mentioned this pull request Sep 2, 2023
13 tasks
@slaren slaren marked this pull request as ready for review September 2, 2023 22:03
@slaren
Copy link
Collaborator Author

slaren commented Sep 2, 2023

I have tested this successfully under Linux and Windows, including 32-bit builds, but I would need some help testing with OS X.

@CoruNethron
Copy link

I have tested this successfully under Linux and Windows, including 32-bit builds, but I would need some help testing with OS X.

I'll do. What kind of test could I perform?

@slaren
Copy link
Collaborator Author

slaren commented Sep 3, 2023

All you would need to do is make sure it builds without errors and generate a few tokens using main or any other example.

@CoruNethron
Copy link

@slaren, I've tested alloc-vmem (c031b6c) - all binaries built without errors or warnings. Generated few tokens without any problem on Mac M1.

@slaren
Copy link
Collaborator Author

slaren commented Sep 3, 2023

Awesome, thanks!

Copy link
Owner

@ggerganov ggerganov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some testing on M2 Ultra and it works.

I wonder, should we fallback to the old strategy if mmap is not available?
I'm planning soon to update whisper.cpp to use ggml-alloc and update the WASM examples.

@slaren
Copy link
Collaborator Author

slaren commented Sep 3, 2023

I have added a fallback for systems without virtual memory, however I noticed that emscripten has a shim for mmap that just allocates memory, which is not great. It should still work, but the memory usage will be high, so we may have to add a check to disable mmap when building with emscripten.

@slaren slaren merged commit cf9b084 into master Sep 3, 2023
26 checks passed
@slaren slaren deleted the alloc-vmem branch September 3, 2023 18:34
@staviq
Copy link
Collaborator

staviq commented Sep 3, 2023

As a sidenote

Considering mmap, this seems related: WebAssembly/WASI#304

There's also this project which I have used successfully before, and it's simple enough so extending it is not very complicated, and it uses clang to produce wasm: https://github.com/schellingb/wajic

Edit: It should be possible to get rid of emscripten in favour of clang, if that helps in any way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants