Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Build: Fix potential race condition #8781

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

Merged
merged 4 commits into from
Jul 31, 2024
Merged

Conversation

HanClinto
Copy link
Collaborator

This implements the fix suggested by @fairydreaming as reported in #8776.

So far I have not been able to reproduce the original issue as reported.

@slaren
Copy link
Member

slaren commented Jul 30, 2024

I think you also need to remove the first line in the targets (the $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)), since that's meant to compile the source file, which is already done in the deprecation-warning.o target.

Makefile Outdated
# NOTE: We currently will always build the deprecation-warning `main` and `server` binaries to help users migrate.
# Eventually we will want to remove these target from building all the time.
main: examples/deprecation-warning/deprecation-warning.cpp
main: examples/deprecation-warning/deprecation-warning.o
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should remove these $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) in all legacy targets, as they will use the examples/deprecation-warning/deprecation-warning.o object, so there is no need to compile and overwrite it again

Makefile Outdated
# NOTE: We currently will always build the deprecation-warning `main` and `server` binaries to help users migrate.
# Eventually we will want to remove these target from building all the time.
main: examples/deprecation-warning/deprecation-warning.cpp
main: examples/deprecation-warning/deprecation-warning.o
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
$(CXX) $(CXXFLAGS) $(filter-out $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think GET_OBJ_FILE is not needed here, you can directly use $< as it's the object file now.

Makefile Outdated
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
$(CXX) $(CXXFLAGS) $(filter-out $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
main: examples/deprecation-warning/deprecation-warning.o
$(CXX) $(LDFLAGS) $< -o $@
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is probably just being cautious, but I'd keep CXXFLAGS here at the front and LDFLAGS at the end of the command like it was before. It may matter when cross-compiling for some weird platform.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for the help!

If you can't tell, I'm not the strongest with makefiles -- if you feel like you'd rather open the PR, I would not be offended!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Naah, if you fix this one thing I think it will be good to go.

@HanClinto
Copy link
Collaborator Author

@fairydreaming Thank you for the repro case included here -- that helped a ton! That let me consistently reproduce the issue on Ubuntu, and it also gives us the data point that I was unable to get it to fail on OSX.

Super helpful, thank you!

Copy link
Collaborator

@fairydreaming fairydreaming left a comment

Choose a reason for hiding this comment

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

Looks good now, thank you!

Makefile Outdated
@@ -1605,42 +1605,41 @@ llama-q8dot: pocs/vdot/q8dot.cpp ggml/src/ggml.o \
# Mark legacy binary targets as .PHONY so that they are always checked.
.PHONY: main quantize perplexity embedding server

# Define the object file target
examples/deprecation-warning/deprecation-warning.o: examples/deprecation-warning/deprecation-warning.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@ $(LDFLAGS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ugh I missed one. I think LDFLAGS is not needed here, it's only required when creating libraries or binaries, for object files CXXFLAGS is enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Very helpful, thank you!!

@HanClinto HanClinto marked this pull request as ready for review July 31, 2024 04:28
@fairydreaming
Copy link
Collaborator

For me this is ready to merge. @slaren do you see anything to improve?

Copy link
Member

@slaren slaren left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@HanClinto HanClinto merged commit ed9d285 into ggml-org:master Jul 31, 2024
53 checks passed
@HanClinto
Copy link
Collaborator Author

Thank you very much, @fairydreaming and @slaren !

arthw pushed a commit to arthw/llama.cpp that referenced this pull request Aug 2, 2024
* Fix potential race condition as pointed out by @fairydreaming in ggml-org#8776

* Reference the .o rather than rebuilding every time.

* Adding in CXXFLAGS and LDFLAGS

* Removing unnecessary linker flags.
mccoylstevens pushed a commit to mccoylstevens/llama.cpp that referenced this pull request May 15, 2025
* Fix potential race condition as pointed out by @fairydreaming in ggml-org#8776

* Reference the .o rather than rebuilding every time.

* Adding in CXXFLAGS and LDFLAGS

* Removing unnecessary linker flags.
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.

Bug: Random compilation error when using multiple jobs (make -j8)
3 participants