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

Fixed build on Linux with GCC #44

Merged
merged 9 commits into from
Nov 20, 2024
Merged

Conversation

stemann
Copy link
Contributor

@stemann stemann commented Nov 19, 2024

Also, Fixed CMakeLists wrt. setting MLX_BUILD_BENCHMARKS=OFF.

Follow-up after #38

Needed for JuliaPackaging/Yggdrasil#9809

@stemann
Copy link
Contributor Author

stemann commented Nov 19, 2024

@stemann stemann force-pushed the feature/build_linux branch from b646958 to 626a6e5 Compare November 19, 2024 15:30
@stemann
Copy link
Contributor Author

stemann commented Nov 19, 2024

Never mind. Got it fixed: https://github.com/stemann/mlx-c/actions/runs/11916338116

@stemann stemann marked this pull request as ready for review November 19, 2024 15:35
@stemann stemann force-pushed the feature/build_linux branch from 626a6e5 to 846407a Compare November 19, 2024 15:36
@stemann stemann changed the title WIP Fixed build on Linux with GCC Fixed build on Linux with GCC Nov 19, 2024
@stemann
Copy link
Contributor Author

stemann commented Nov 19, 2024

I have removed the GitHub Actions build workflow from this PR, but it is available for a separate PR if you would like to get build CI via GitHub Actions: https://github.com/stemann/mlx-c/tree/feature/github_actions_build : https://github.com/stemann/mlx-c/actions/runs/11916455284

mlx/c/array.h Outdated
@@ -5,6 +5,7 @@

#include "mlx/c/string.h"

#include <cstdint>
Copy link
Member

Choose a reason for hiding this comment

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

  • I did not need this one on my side, curious which GCC compiler/system are you using, and where the error is located?
  • this is a C header, so includes should be C, not C++; is the error popping up in array.cpp or in array.h?

Copy link
Contributor Author

@stemann stemann Nov 19, 2024

Choose a reason for hiding this comment

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

GCC 11.4: https://github.com/stemann/mlx-c/actions/runs/11910841319/job/33191101517#step:4:293

In file included from /home/runner/work/mlx-c/mlx-c/mlx/c/array.cpp:5:
/home/runner/work/mlx-c/mlx-c/mlx/c/array.h:176:26: error: ‘uint8_t’ was not declared in this scope
  176 | int mlx_array_item_uint8(uint8_t* res, const mlx_array arr);
      |                          ^~~~~~~

Though, I'm using GCC 10 in JuliaPackaging/Yggdrasil#9809

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might have messed up wrt. C vs C++ headers.

Copy link
Member

Choose a reason for hiding this comment

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

Uh ok. Definitively need a stdint.h there, thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be more specific, I was using:

  • Locally, in a container mcr.microsoft.com/devcontainers/cpp:1-debian-11: GCC 10.2 (on Debian 11).
  • GitHub Actions, on "ubuntu-latest" runner: GCC 11.4
  • BinaryBuilder env. (Julia): GCC 10.2 (cross-compile env. running on an Alpine Linux (musl) - cross-compiling to various targets)

@@ -183,7 +183,7 @@ extern "C" mlx_closure_value_and_grad mlx_closure_value_and_grad_new_func(
"mlx_closure_value_and_grad returned a non-zero value");
}
auto cpp_res =
std::tie(mlx_vector_array_get_(res_0), mlx_vector_array_get_(res_1));
std::make_pair(mlx_vector_array_get_(res_0), mlx_vector_array_get_(res_1));
Copy link
Member

Choose a reason for hiding this comment

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

Sorry this is not really documented, but this file is auto-generated, so one should not modify it manually. Instead, modify mlxtypes.py

cpp_make_tuple = "std::make_pair" if n == 2 else "std::make_tuple"
    types.append(
        {
            "cpp": cpp_tuple + "<" + ", ".join(cpp_types) + ">",
            "alt": [cpp_tuple + "<" + ", ".join(alt_types) + ">"] + alts,
            "c_to_cpp": lambda s: cpp_make_tuple + "("

The file can then be generated via

python ../../python/closure_generator.py --implementation > closure.cpp

Copy link
Member

Choose a reason for hiding this comment

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

(a clang-format -i closure.cpp would need to follow)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah OK.

Copy link
Contributor Author

@stemann stemann Nov 19, 2024

Choose a reason for hiding this comment

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

I added the change to the mlxtypes.py code generator, but if I run it there are a lot more changes than I would expect (I would have expected zero - keeping my manual change).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah - got you message on clang-format now. Now executed.

mlx/c/compile.h Outdated
@@ -8,6 +8,8 @@

#include <stdio.h>

#include <cstdint>
Copy link
Member

Choose a reason for hiding this comment

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

same comments as above

  • this is a C header
  • where is the error coming up? (I do not have it on my end)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mlx/c/fast.cpp Outdated
@@ -3,6 +3,8 @@
/* This file is auto-generated. Do not edit manually. */
/* */

#include <cstdarg>
Copy link
Member

Choose a reason for hiding this comment

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

This is an auto-generated file. I do not get the error there as well, so curious to know where it occurs. For this one, and the one in metal.cpp, I would suggest to put additional includes in mlx/c/private/mlx.h

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cstdarg was for the va_x functions, like va_list, va_arg etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted, i.e. moving it to mlx/c/private/mlx.h.

mlx/c/metal.cpp Outdated
@@ -3,6 +3,8 @@
/* This file is auto-generated. Do not edit manually. */
/* */

#include <cstring>
Copy link
Member

Choose a reason for hiding this comment

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

see comment above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted, i.e. moving it to mlx/c/private/mlx.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried replacing it with <string.h>, but it failed - again complaining that there is no strncpy: https://github.com/stemann/mlx-c/actions/runs/11923235104

Using (now in mlx/c/private/mlx.h) fixes it: https://github.com/stemann/mlx-c/actions/runs/11923278948

Copy link
Member

@andresy andresy left a comment

Choose a reason for hiding this comment

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

Thanks! Asking for few changes, let me know if that works for you, as I would prefer to have these added before I tag the next MLX C version

@stemann
Copy link
Contributor Author

stemann commented Nov 19, 2024

It would be great to get these changes merged in, and a new version tagged.

Your requested changes should now be implemented - except I have not run the mlxtypes.py-script (too many unrelated changes would occur).

@stemann stemann requested a review from andresy November 19, 2024 23:31
@andresy andresy force-pushed the feature/build_linux branch from 6455e76 to 9fe2944 Compare November 20, 2024 00:34
@andresy andresy merged commit 1262536 into ml-explore:main Nov 20, 2024
@stemann stemann deleted the feature/build_linux branch November 20, 2024 08:53
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.

2 participants