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 data transform fn #6953

Merged
merged 19 commits into from
Dec 26, 2017

Conversation

jacquesqiao
Copy link
Member

@jacquesqiao jacquesqiao commented Dec 25, 2017

fix: #6823

@jacquesqiao jacquesqiao changed the title [WIP]Add data transform fn Add data transform fn Dec 26, 2017
data_transform_map = new DataTransformFnMap();
}
return *data_transform_map;
}
Copy link
Member

Choose a reason for hiding this comment

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

Following is a thread-safe singleton:

DataTransformFnMap& DataTransformFnMap::Instance() {
  static DataTransformFnMap inst;
  return inst;  
}

refer to https://stackoverflow.com/questions/11711920/how-to-implement-multithread-safe-singleton-in-c11-without-using-mutex

Copy link
Member Author

Choose a reason for hiding this comment

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

done

namespace paddle {
namespace framework {

using DataTransformFN =
Copy link
Collaborator

Choose a reason for hiding this comment

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

DataTransform should not only use Tensor as its argument type.

How about SelectedRows? LoDTensor? vector<Scope>? It should take Variable as its argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

Copy link
Member Author

Choose a reason for hiding this comment

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

done

size_t left_hasher = kernel_type_hasher(kernel_pair.first) << 1;
size_t right_hasher = kernel_type_hasher(kernel_pair.second);
std::hash<size_t> hasher;
return hasher(left_hasher + right_hasher);
Copy link
Member

Choose a reason for hiding this comment

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

A little concern on the correctness of hash calculation.

Copy link
Member Author

@jacquesqiao jacquesqiao Dec 26, 2017

Choose a reason for hiding this comment

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

ok, I will find a better way to do hash

Copy link
Contributor

Choose a reason for hiding this comment

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

HashCombine fit here well.

Copy link
Contributor

Choose a reason for hiding this comment

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

HashCombine combinate the different hash value without any conflict, as @QiJune shows in previous PR, https://stackoverflow.com/questions/2590677/how-do-i-combine-hash-values-in-c0x

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, done

Copy link
Member

@QiJune QiJune left a comment

Choose a reason for hiding this comment

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

LGTM

const Variable& in, Variable* out)>;
using KernelTypePair = std::pair<OpKernelType, OpKernelType>;

static void hash_combine(std::size_t& seed, const OpKernelType& t) {
Copy link
Member

Choose a reason for hiding this comment

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

Code style is:

template <class T>
inline void HashCombine(const T& v, std::size_t* seed) {
  std::hash<T> hasher;
  *seed ^= hasher(v) + 0x9e3779b9 + (*seed << 6) + (*seed >> 2);
}

We can fix it later.

@jacquesqiao jacquesqiao merged commit f97f69f into PaddlePaddle:develop Dec 26, 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.

DataTransformFn register mechanism
4 participants