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

Add Majel's Dim to Paddle #2202

Merged
merged 5 commits into from
May 19, 2017
Merged

Add Majel's Dim to Paddle #2202

merged 5 commits into from
May 19, 2017

Conversation

JiayiFeng
Copy link
Collaborator

Dim is used in Majel to describe array size or element index. It is the foundation of higher level structs like Array.
Implements of Dim are contained in dim.h, ddim.h and ddim.cc.
hostdevice.h and util.h are for macro definition.

@JiayiFeng JiayiFeng requested review from a user, gangliao and QiJune May 18, 2017 10:11

std::vector<int> v3;

assert(v1.size() == v2.size());
Copy link
Contributor

@gangliao gangliao May 18, 2017

Choose a reason for hiding this comment

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

Why not use the MAJEL_ASSERT directly?

Copy link
Collaborator Author

@JiayiFeng JiayiFeng May 18, 2017

Choose a reason for hiding this comment

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

According to util.h, MAJEL_ASSERT is available only in kernel code of Apple GPU. In other cases, we should use assert instead.

@@ -0,0 +1,222 @@
#include <majel/ddim.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

#include "paddle/majel/ddim.h"

  1. Please use double-quotes instead of angle-brackets, which is for system header files. More details at here: https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes

  2. Please make sure to use the full #include path. This makes sure that there is only one way to include each header file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -2,6 +2,11 @@ cc_test(place_test
SRCS place_test.cc
DEPS majel)

cc_test(ddim_test
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the next PR, we need to move all unit tests, e.g., place_test.cc and ddim_test.cc, to one folder level above. According to the convention here https://google.github.io/styleguide/cppguide.html#File_Names, we want three files of each module xxx

  • xxx.h
  • xxx.{cc,cu}
  • xxx_test.{cc,cu}

in the same place, so to ease code browsing.

I created an issue #2209 to remind us about this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, to avoid clutter, I'm going to keep the folder structure unchanged temporarily and wait for the adjust in next PR.

namespace detail {

inline int div_up(int x, int y) { return (x + y - 1) / y; }
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

There should be an empty line between L37 and L38, because you put an empty in the corresponding place at L33.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


inline int div_up(int x, int y) { return (x + y - 1) / y; }
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please follow https://google.github.io/styleguide/cppguide.html#Namespaces to add comments after the closing parenthesis of namespace:

}  // namespace detail
}  // namespace majel

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -1,4 +1,4 @@
cc_library(majel SRCS place.cc)
cc_library(majel SRCS place.cc ddim.cc)
Copy link
Collaborator

Choose a reason for hiding this comment

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

According to our design, I believe that this line should be

cc_library(place SRCS place.cc)
cc_library(dim SRCS dim.cc)
cc_library(ddim SRCS ddim.cc DEPS dim)

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we need to add an optional OBJECT, because CMake add_library(name OBJECT source) can generate *.o

Copy link
Collaborator Author

@JiayiFeng JiayiFeng May 19, 2017

Choose a reason for hiding this comment

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

done.
But Dim is only a part of DDim, it is not an independent module and only has a dim.h file. So maybe these lines should be

cc_library(place SRCS place.cc)
cc_library(ddim SRCS ddim.cc)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it. Thanks!

#include <type_traits>

#include "majel/hostdevice.h"
#include "majel/util.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about moving this header file majel/util.h into majel/detail/assert.h? Please see my comments in this file for more details.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done. And I moved hostdevice.h into folder detail as well.

namespace majel {
namespace detail {

inline int div_up(int x, int y) { return (x + y - 1) / y; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function div_up is not used in the ported part of Majel. Also, I checked that it's used in the following files of Majel:

$ for i in $(du -a | grep '\.h$' | cut -f 2); do if grep 'div_up' $i > /dev/null; then echo $i; fi; done
./detail/bsxfun.h
./detail/util.h
./gpu/detail/gather.h
./gpu/detail/gather_with_indices.h
./gpu/detail/ops.h
./gpu/detail/quantize_ops.h
./gpu/detail/reduce.h
./gpu/detail/row_conv_ops.h
./gpu/detail/scatter_with_indices.h

I am not sure if we will need it soon. How about we don't port it right now? If so, we can name this header file paddle/majel/detial/assert.

Copy link
Collaborator Author

@JiayiFeng JiayiFeng May 19, 2017

Choose a reason for hiding this comment

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

Function div_up has been removed. But I feel it's better to keep the file's name util.h. Because in this file, we #include the system's assert.h. It may be confusing if both of them are named assert.h.
Or maybe cuda_assert.h is a better name? For it is only used in cuda kernel code.

} // namespace
// Static access to constant Dim
template <int i, int l>
HOSTDEVICE int get(const Dim<l>& d) {
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 that get and operator[] do the same thing? Do we need both?

Copy link
Collaborator Author

@JiayiFeng JiayiFeng May 19, 2017

Choose a reason for hiding this comment

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

They indeed do the same thing. I'm not sure whether both of them are required by higher level structs. However, I guess offering more interfaces is unlikely to be bad, is it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right. I asked Greg. He confirmed that they are doing the same thing. :-)

@JiayiFeng JiayiFeng merged commit 48de5ff into PaddlePaddle:develop May 19, 2017
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.

3 participants