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

allow inclusion in C programs #4608

Merged
merged 8 commits into from
Oct 5, 2021
Merged

allow inclusion in C programs #4608

merged 8 commits into from
Oct 5, 2021

Conversation

drewmiller
Copy link
Contributor

Including "c_api.h" from programs compiled with C compilers errors due to required inclusion of C++ headers. These edits allow c_api.h to be included directly in C programs.

@jameslamb
Copy link
Collaborator

Thanks for this @drewmiller !

Is it possible to share a link to the C project you're working on that needs to link against LightGBM? No worries if not, we'll understand if it's proprietary.

Also would you be willing to write up a feature request at https://github.com/microsoft/LightGBM/issues explaining why it would be valuable for C projects to be able to link against LightGBM directly, with specific examples of such projects if you have them? If this is a feature that people care about, we'll want to add a continuous integration job that tests that linking such a project works, to ensure that compatibility issues aren't accidentally introduced in the future.

@drewmiller
Copy link
Contributor Author

Thanks for this @drewmiller !

Is it possible to share a link to the C project you're working on that needs to link against LightGBM? No worries if not, we'll understand if it's proprietary.

Unfortunately, it's proprietary.

Also would you be willing to write up a feature request at https://github.com/microsoft/LightGBM/issues explaining why it would be valuable for C projects to be able to link against LightGBM directly, with specific examples of such projects if you have them? If this is a feature that people care about, we'll want to add a continuous integration job that tests that linking such a project works, to ensure that compatibility issues aren't accidentally introduced in the future.

Sure.

@drewmiller
Copy link
Contributor Author

Thanks for the great product, MS team. I've added a simple feature request, and I'm happy to help write a toy example for inclusion in a unit testing pipeline if helpful. I'm not super familiar with the code base yet, so I recognize my "trivial" commit may have cascading effects. However, this software would be more useful to me with this feature, so I thought I'd open the door with some proposed changes, and I'm happy to help bring them into existence however I can. That includes bulking out the feature request as necessary. Warm regards.

@jameslamb
Copy link
Collaborator

Thanks very much for opening #4609. I think it's something we should consider supporting and should having tests for, but that work doesn't need to be done on this PR.

Could you please merge the latest master into this branch? We recently had to turn off the CUDA CI jobs due to some infrastructure problems (#4611). Sorry for the inconvenience.

@drewmiller
Copy link
Contributor Author

drewmiller commented Sep 22, 2021

Thanks very much for opening #4609. I think it's something we should consider supporting and should having tests for, but that work doesn't need to be done on this PR.

Could you please merge the latest master into this branch? We recently had to turn off the CUDA CI jobs due to some infrastructure problems (#4611). Sorry for the inconvenience.

Done; although the CI seems to be hanging at all-successful.

@StrikerRUS
Copy link
Collaborator

although the CI seems to be hanging at all-successful.

This is a GitHub protection from miners: #4266 (comment). We have to click Approve and run button for PRs from a first-time contributors after each their commit.

@@ -1321,7 +1328,9 @@ LIGHTGBM_C_EXPORT int LGBM_NetworkInitWithFunctions(int num_machines,
void* reduce_scatter_ext_fun,
void* allgather_ext_fun);

#if defined(_MSC_VER)
#ifndef __cplusplus
#define THREAD_LOCAL /*!< \brief Thread local specifier no-op in C builds. */
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems C11 also has thread_local, refer to https://en.wikipedia.org/wiki/C11_(C_standard_revision)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The follow-up changes take advantage of _Thread_local from C11. They also make the C API header compatible with ANSI C. If the changes to the comments disrupt doc generation, they could be rolled back in favor of abandoning support for C versions prior to C99. The attached test.c.gz can be gunzipped in c_api_test/ and used to test both code generation and compilation with the below:

Code generation:
gcc test.c -ansi -I../../include/ -E - should exclude inline and _Thread_local
gcc test.c -std=c99 -I../../include/ -E - should include inline and exclude _Thread_local
gcc test.c -std=c11 -I../../include/ -E - should include inline and _Thread_local
g++ test.c -I../../include/ -E - should include inline and thread_local

Remove the -E switch on the above to confirm compilation for each setting.

@ghost
Copy link

ghost commented Sep 25, 2021

CLA assistant check
All CLA requirements met.

@guolinke
Copy link
Collaborator

@shiyu1994 can you take a look on this?

@StrikerRUS
Copy link
Collaborator

StrikerRUS commented Sep 26, 2021

/gha run r-valgrind

Workflow R valgrind tests has been triggered! 🚀
https://github.com/microsoft/LightGBM/actions/runs/1275540121

Status: success ✔️.

@StrikerRUS
Copy link
Collaborator

StrikerRUS commented Sep 26, 2021

/gha run r-solaris

Workflow Solaris CRAN check has been triggered! 🚀
https://github.com/microsoft/LightGBM/actions/runs/1275540385

solaris-x86-patched: https://builder.r-hub.io/status/lightgbm_3.2.1.99.tar.gz-56fa0cb3567643248793465ecb7b2a5f
solaris-x86-patched-ods: https://builder.r-hub.io/status/lightgbm_3.2.1.99.tar.gz-91f1b85bd8dc412594a3661602179f3c
Reports also have been sent to LightGBM public e-mail: https://yopmail.com?lightgbm_rhub_checks
Status: success ✔️.

Copy link
Collaborator

@shiyu1994 shiyu1994 left a comment

Choose a reason for hiding this comment

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

@drewmiller Thanks for your contribution. The changes LGTM.

@StrikerRUS StrikerRUS merged commit f3037c1 into microsoft:master Oct 5, 2021
@jameslamb jameslamb mentioned this pull request Oct 6, 2021
16 tasks
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants