-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
CPU-only build #561
CPU-only build #561
Conversation
This is very useful. It shortens the compilation time when I develop on a machine without the GPU.
|
@kloudkl thanks for pointing that out. Such tests will need to be separated out for Travis-CI integration until a custom build bot system is configured. |
@jeffdonahue has opened a cmake branch from the cmake pr. How we want to handle PR and commits like this one that edit Makefile? Is needed to duplicate any effort but with a risk of having Cmake and Makefile out of sync often in the future. |
In the short term, keeping them in sync for the CPU and GPU platforms is not very hard. CMake is a flexible cross platform build tool. I believe that it will finally help Caffe support many more platforms in the long term. For example, it is easier to use CMake to cross compile Caffe for the Android or iOS mobile platforms that are usually deployed on the ARM or other hardware architectures. The Windows support needed by some users can be handled too. Meanwhile, the CMake system will stay highly readable and manageable. In general, the CMake build scripts for different platforms will all be in their own modules instead of cramming together. |
My experience with other project is that maintain two build system is not a good choice. |
@@ -12,6 +12,8 @@ namespace caffe { | |||
|
|||
const float kBNLL_THRESHOLD = 50.; | |||
|
|||
#ifndef CPU_ONLY | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this intentional? seems like it should be in either all the .cu files or none of them. (and probably it should be in none of them as we can just not attempt to build .cu files in cpu only mode)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, these were accidental. Thanks for the catch. Will fix shortly.
Le lundi 30 juin 2014, Jeff Donahue [email protected] a écrit :
In src/caffe/layers/bnll_layer.cu:
@@ -12,6 +12,8 @@ namespace caffe {
const float kBNLL_THRESHOLD = 50.;
+#ifndef CPU_ONLY
+was this intentional? seems like it should be in either all the .cu files
or none of them. (and probably it should be in none of them as we can just
not attempt to build .cu files in cpu only mode)—
Reply to this email directly or view it on GitHub
https://github.com/BVLC/caffe/pull/561/files#r14361634.
@jeffdonahue the I introduced a further preprocessing guard in 080893d for the device typdefs to exclude the GPU when |
Look at the "make runtestnogpu" I added for Travis to use -- does that do
|
Thanks for the pointer! I took the new filter for the CPU-only @jeffdonahue in general how do you feel about this approach to a CPU-only build? Too much of a hack, or acceptable while BVLC:device-abstraction is readied? Is it worth seeing this approach through? If so, my next step is to isolate the CUDA includes into a single header that will conditionally actually include CUDA or stub out the GPU functions instead for CPU-only. Then we can eliminate the CUDA dependencies for CPU-only Caffe. |
p.s. The CPU-only build and testing takes 69 s with
|
Totally in favor of removing runtestnogpu and controlling it via the flag. I think the approach is good, I wouldn't think there's any way around using ifdefs. |
I had one other thought -- you could also add ifdefs to not use the two new GPU test types I defined in test_caffe_main.hop. then you could skip the new 2/3 things in the gtest_filter because it would compile without the GPU tests. |
Note: worked @ 9a28c2b except for timing (see 48469ca) but broken by more drastic separation attempted in 4caec0b that tries to remove CUDA dependency for CPU-only installation. Once I address the tests, tools, and throw in a few more guards this should be set. |
We have CPU-only brewing with no CUDA dependency! @jeffdonahue please review for merge. There are more ifdef guards scattered about than I would like, but I think BVLC:feature-abstraction should concentrate them and make the code less messy. |
Sweet, I'll check it out today.
|
INCLUDE_DIRS += ./src ./include $(CUDA_INCLUDE_DIR) | ||
INCLUDE_DIRS += $(BUILD_INCLUDE_DIR) ./src ./include | ||
ifneq ($(CPU_ONLY), 1) | ||
INCLUDE_DIRS += $(CUDA_INCLUDE_DIR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add indent between ifneq and endif
Looks good! Made a couple small comments on the makefile changes -- please glance at them, make any fixes, and merge. |
I have a concern that I hadn't thought about previously -- while having a CPU-only build is great for many reasons, are we sure it's the best idea to use it exclusively in our Travis build? While Travis can't run the GPU unit tests to check for functional correctness (since the VMs don't have any CUDA GPU access), it does at least test that the full system, including CUDA code, compiles. Should we consider having Travis do the full non-cpu-only build as well as the cpu-only one that it actually tests? |
Agreed, we should run both the CPU-only build and CPU + GPU builds ...like the fact that I pushed a broken state of the normal build here Will fix that, adjust the Travis build to do both builds, and address your Le jeudi 17 juillet 2014, Jeff Donahue [email protected] a écrit :
|
- collect CUDA includes in device_alternate.hpp - add guards for CUDA code - move GPU code into cu from cpp - make CUDA includes and libraries conditional in Makefile - drop CUDA dependency from travis-ci build
CPU-only build no GPU, no CUDA, no problem!
Thanks for the quick review and build consideration @jeffdonahue! @kloudkl give this a try sometime and let me know if you run into any trouble. I'll follow-up with documentation soon. |
CPU-only build no GPU, no CUDA, no problem!
CPU-only build no GPU, no CUDA, no problem!
How do I compile it for FreeBSD 13.1 without GPU? |
Note: the CUDA libraries are still required for now.
CPU_ONLY
flag to Makefile to skip GPU compilationThis adds a CPU-only switch to the
Makefile.config
that builds Caffe without compiling any GPU code. When this flag is uncommentedmake
builds libcaffe.so and libcaffe.a without any GPU compilation at all (not a single call to nvcc).make test
builds the tests as usual.make runtest
only runs the CPU tests.Mostly I was curious what this would take since it partially addresses #150. With this build we should be able to configure a Travis-CI hook for CPU testing of PRs and such.
Not that we should necessarily merge this as-is or at all however, especially with the grossness of 81791ec, and the macro pollution I added in 871b0ce.
I imagine the #415, BVLC:device-abstraction work would make carrying out the CPU / CUDA separation at compilation simpler. Perhaps this is useful all the same?
What does everybody think?