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

Cleanup pthread code for data layers #710

Merged
merged 1 commit into from
Jul 29, 2014
Merged

Cleanup pthread code for data layers #710

merged 1 commit into from
Jul 29, 2014

Conversation

arntanguy
Copy link
Contributor

While creating a new data layer class needed for my Siamese network, I noticed that the
pthread code wasn't particularely clean.

Thus I

  • Got rid of the needless friend functions. Previously the threads were defined as a friend function.
    This forced to pass a pointer to the current layer, and do needless casts and pointer checks.
  • Created an InternalThread class that makes it easy to create a class requiring a single thread (such as DataLayer, ImageDataLayer...).
    It is done by inheriting the InternalThread class, and overriding the InternalThreadEntry virtual function to
    define the thread's code. It has the necessary mechanism to start and wait for a thread.

This is my first contribution to Caffe, I hope I followed all the guidelines properly ;)

Cheers,
Arnaud

@jeffdonahue
Copy link
Contributor

Nice, this code has needed some cleanup for a while. Can you run "make lint" and fix the style errors it returns? (Or look at them in the Travis build output.)

One thing I'm not sure about is the multiple inheritance -- the Google style guide pretty much forbids it, but I think I'd be okay with using it here (especially given that it's replacing a friend class, which seems more dangerous to me even though GSG is okay with them) unless there's some real danger -- anyone care to comment?

@arntanguy
Copy link
Contributor Author

All right, all fixed! For some reason "make lint" always returns no errors for me. I ran the cpp_lint.py script manually.

Multiple inheritance is a feature of the language, and it makes no sense to avoid it all together.
It should be used sparsely, and only when needed of course. In this case, since it adds a very specific
feature to the child class, and introduces no risk of confusion (only one member variable, and 3 very specific functions), there is very little risk involved, and a cleaner more reusable code.

@shelhamer
Copy link
Member

The use here is a good application of multiple inheritance and this kind of
setting justifies the language feature to me.

However I am not as well-versed in Google Style and its underlying reasons
as @jeffdonahue and @Yangqing so I defer handling this PR to them.

On Thu, Jul 17, 2014 at 12:40 PM, TANGUY Arnaud notifications@github.com
wrote:

All right, all fixed! For some reason "make lint" always returns no errors
for me. I ran the cpp_lint.py script manually.

Multiple inheritance is a feature of the language, and it makes no sense
to avoid it all together.
It should be used sparsely, and only when needed of course. In this case,
since it adds a very specific
feature to the child class, and introduces no risk of confusion (only one
member variable, and 3 very specific functions), there is very little risk
involved, and a cleaner more reusable code.


Reply to this email directly or view it on GitHub
#710 (comment).

Get rid of the ugly "friend" thread function. Simplify the creation of the
thread by inheriting from a base class. Thus, defining the thread is as
simple as overriding a virtual function.
@jeffdonahue
Copy link
Contributor

Alright, given that I have no real understanding of the potential issues associated with multiple inheritance, I'll defer to @GeenuX and @shelhamer's endorsements and merge. Thanks for the cleanup!

jeffdonahue added a commit that referenced this pull request Jul 29, 2014
Cleanup pthread code for data layers
@jeffdonahue jeffdonahue merged commit 8b7964b into BVLC:dev Jul 29, 2014
mitmul pushed a commit to mitmul/caffe that referenced this pull request Sep 30, 2014
Cleanup pthread code for data layers
RazvanRanca pushed a commit to RazvanRanca/caffe that referenced this pull request Nov 4, 2014
Cleanup pthread code for data layers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants