BVLC / caffe

Caffe: a fast open framework for deep learning.
http://caffe.berkeleyvision.org/
Other
33.97k stars 18.72k forks source link

explicit specialization of 'device_type_name<bool>' after instantiation, first implicit instantiation here: https://github.com/BVLC/caffe/blob/3f2b97e93ed5ab612b6d00995294e37a422f0931/src/caffe/backend/device_program.cpp#L240 #6910

Open alexismailov2 opened 4 years ago

alexismailov2 commented 4 years ago

https://github.com/BVLC/caffe/blob/3f2b97e93ed5ab612b6d00995294e37a422f0931/src/caffe/backend/device_program.cpp#L410

alexismailov2 commented 4 years ago

All these specializations can be moved ahead line 240.

rajhlinux commented 1 year ago

I'm getting the same error, how did you solve the issue?

/home/user/caffe/src/caffe/backend/device_program.cpp:410:23: error: explicit specialization of 'device_type_name<bool>' after instantiation
string DeviceProgram::device_type_name<bool>() const {
                      ^
/home/user/caffe/src/caffe/backend/device_program.cpp:240:30: note: implicit instantiation first required here
                       this->device_type_name<Dtype>() + std::to_string(i));
                             ^
/home/user/caffe/src/caffe/backend/device_program.cpp:414:23: error: explicit specialization of 'device_type_name<char>' after instantiation
string DeviceProgram::device_type_name<char>() const {

Thanks

rajhlinux commented 1 year ago

Alright, I was able to fix the problem, all of the specializations were moved up, but right bellow the function template scope of line 240.

Thanks.

I'll clarify for those who need more detail:

The error Is caused due to using Clang compiler, it seems the Caffe project was built using GCC without any compilation error checks for devs who uses Clang compilers (MacOS and FreeBSD uses Clang as the native compiler). I think the easiest way to solve the issue is to use GCC...

Clang will throw error in "explicit specialization and first implicit instantiation", I'm sure there is an error flag which can be set to tell Clang to discard these errors during compilation.

Anyhow, since I would rather use Clang, here is what I did to solve the issue, need to go to the file: /usr/home/user/caffe/src/caffe/backend/device_program.cpp

And move the specializations code starting at line 472 till 527, to some where on line 250, basically after the entire template scope which contains the function this->device_type_name<Dtype>().

Save and recompile.