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

WIP Feature/cpp #4155

Closed
wants to merge 10 commits into from
Closed

Conversation

jmikedupont2
Copy link

This is a work in progress to compile with C++ and add in the magic header,
I just got the first version to compile by commenting out the initializers and things that did not work.
am sharing this with the community for comments, please do not merge.

@cebtenzzre
Copy link
Collaborator

Hm, I don't think ggerganov would approve of this. https://github.com/ggerganov/ggml is written in C for simplicity.

@jmikedupont2
Copy link
Author

jmikedupont2 commented Nov 21, 2023 via email

@jmikedupont2
Copy link
Author

jmikedupont2 commented Nov 21, 2023 via email

@jmikedupont2
Copy link
Author

jmikedupont2 commented Nov 21, 2023 via email

@cebtenzzre
Copy link
Collaborator

for example converting a float to an int might not be what you want

You can also build master with cmake -B build -DCMAKE_C_FLAGS='-Wfloat-conversion' && make -C build main to see this warning. That probably is a bug, so perhaps we should enable -Wfloat-conversion by default.

@jmikedupont2
Copy link
Author

jmikedupont2 commented Nov 21, 2023 via email

now compiling again,
@jmikedupont2
Copy link
Author

This is another thing that popped up, bunch of the types dont have the full complement of functions

ggml.cpp:2034:3: warning: missing initializer for member ‘ggml_type_traits_t::from_float’\
 [-Wmissing-field-initializers]

@jmikedupont2
Copy link
Author

Its running and producing text!
Screenshot_20231121_210848_Termux

@@ -718,7 +718,7 @@ add_library(llama
)

target_include_directories(llama PUBLIC .)
target_compile_features(llama PUBLIC cxx_std_11) # don't bump
target_compile_features(llama PUBLIC cxx_std_20) # don't bump
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, that's probably not gonna happen either... for the most part this project uses a subset of C++11 that barely even includes templates. Kerfuffle and I are proposing to add some in #4092, we'll see how it goes - it could be that it ends up getting rewritten to do things the C way. C++20, a language which has modules, coroutines, and concepts, is almost certainly out of the question.

@jmikedupont2
Copy link
Author

jmikedupont2 commented Nov 22, 2023 via email

@ggerganov
Copy link
Owner

for example converting a float to an int might not be what you want

You can also build master with cmake -B build -DCMAKE_C_FLAGS='-Wfloat-conversion' && make -C build main to see this warning. That probably is a bug, so perhaps we should enable -Wfloat-conversion by default.

It's not a bug - it was added with the YOLO example to support padding with odd number:

ggerganov/ggml#576

It needs better comment for ggml_pool_2d and explicit cast to int

Regarding turning ggml to C++ - definitely not an option.
But appreciate the effort in this PR and don't mind having it live as a separate branch.

We can think about adding C++ bindings as proposed in ggerganov/ggml#581

@jmikedupont2
Copy link
Author

jmikedupont2 commented Nov 22, 2023 via email

@jmikedupont2
Copy link
Author

Also If we can just refactor those bits like the initializers so the live in a different module or use conditional compliation then we can have the code compile without change in c++and c as well. I am not trying to refactor everything or remove malloc etc. So this could actually be cleaned up so it would be an optional flag.

@jmikedupont2
Copy link
Author

#4209 see this better pr

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.

3 participants