Skip to content

Conversation

@reyoung
Copy link
Collaborator

@reyoung reyoung commented Dec 27, 2017

This is a part of #7092 .

@QiJune QiJune self-requested a review December 27, 2017 08:15
void operator()() const {
auto t = EigenVector<T>::Flatten(tensor_);
auto o = EigenScalar<bool>::From(*out_);
o.device(*ctx_.eigen_device()) = predicate_(t).any();
Copy link
Member

Choose a reason for hiding this comment

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

We can add a reference comment on eigen any() for better understanding
https://eigen.tuxfamily.org/dox/classEigen_1_1DenseBase.html#abfbf4cb72dd577e62fbe035b1c53e695

template <typename T>
auto operator()(const T& eigen_vec) const
-> decltype(std::declval<T>().isnan()) {
return eigen_vec.isnan();
Copy link
Member

Choose a reason for hiding this comment

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

tmp.Resize({1});
tmp.mutable_data<bool>(cpu);
platform::DeviceContextPool::Instance().Get(gpu)->Wait();
CopyFrom(out, cpu, &tmp);
Copy link
Member

Choose a reason for hiding this comment

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

If we do copy between CPU and GPU, we need to pass a DeviceContext

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

However, the device context is a global variable. We can get DeviceContext by its place.

Copy link
Member

Choose a reason for hiding this comment

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

I mean the CopyFrom interface is

inline void CopyFrom(const Tensor& src, const platform::Place& dst_place,
const platform::DeviceContext& ctx, Tensor* dst) {

#endif
}

TEST(IsNAN, CPU) {
Copy link
Member

Choose a reason for hiding this comment

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

Please add GPU unit tests at the same time.

};

template <typename Place>
struct DefaultDeviceContextType;
Copy link
Member

Choose a reason for hiding this comment

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

What is the DefaultDeviceContextType used for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is used for DeviceCtxPool::GetByPlace() method. This method will return the casted DeviceContext by PlaceType.

In the future, we could add a library type to this method.

}

// Returns true if a tensor contains NAN, i.e., Not A Number.
extern bool HasNAN(const framework::Tensor& tensor);
Copy link
Member

Choose a reason for hiding this comment

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

extern seems superfluous.

@@ -0,0 +1 @@
./tensor_util.cc No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

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

Why not move the code in tensor_util.cc to tensor_util.h. Or we can have a tensor_util_impl.h. It's a little strange to have a symbolic link.

Copy link

@tonyyang-svail tonyyang-svail Feb 13, 2018

Choose a reason for hiding this comment

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

@QiJune Reyoung probably had an offline discussion with you already. But looks like .cu is necessary to make nvcc pass the compilation...

ASSERT_TRUE(HasNAN(src));
}

TEST(IsInf, CPU) {
Copy link
Member

Choose a reason for hiding this comment

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

IsInf --> HasInf

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

@reyoung reyoung merged commit 93eaa8e into PaddlePaddle:develop Dec 29, 2017
@reyoung reyoung deleted the feature/is_nan branch January 22, 2018 04:13
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