-
Notifications
You must be signed in to change notification settings - Fork 212
Conversation
On Tue, May 29, 2018 at 08:37:19AM -0700, Theodoros Theodoridis wrote:
closes #351
I haven't looked at it in detail yet, but this looks great.
skimo
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have some documentation in 72f22d3.
Otherwise looks good.
tc/core/check.cc
Outdated
Checker tc_check(bool condition, const char* filename, uint64_t lineno) { | ||
if (condition) { | ||
return Checker(condition, {}, {}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this special case? Is it to avoid calling makeLocation
?
Why not simply store filename
and lineno
?
Also, why does only this variant have such a special case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the condition
holds then the strings are not used, it's an "optimization".
It was present in the rest of tc_check_*
but I removed it because it didn't feel very useful. I forgot to remove this one.
bool condition_; | ||
std::string location_; | ||
std::string baseErrorMsg_; | ||
std::string additionalMsg_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to make a distinction between these two types of messages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need. I'll merge them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a second thought there is one use case:
TC_CHECK_X(...) << "A" << "B";
What I initially implemented will print the following:
Check failed [file:lineno] "what failed": AB
The "what failed"
depends on the type of check, e.g. for TC_CHECK_EQ(1,2)
it would be 1 not equal to 2
. This part of the output is always present.
Extra information (passed with <<
) is optional. The reason I keep track of it in a separate string is to figure out if and where the separator (:
) and the space before it should be printed.
There are two options:
- The optional/extra information is maintained on a separate string.
- The space and separator is appended on the first call to
operator<<
and there is extra state that keeps track of it (e.g., a boolean).
test/test_check.cc
Outdated
|
||
TEST(CHECK, Vector) { | ||
std::stringstream expected; | ||
expected << "Check failed [" << __FILE__ << ':' << __LINE__ + 3 << ']' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fragile and probably compiler dependent.
Why can you assume that the reported line number is the last line of
the macro invocation? Better make sure ASSERT_THROW_WHAT
call
is within a single line in these tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still have format checking enabled on CI? If yes, then it will complain.
test/test_check.cc
Outdated
{ | ||
std::stringstream expected; | ||
expected << "Check failed [" << __FILE__ << ':' << __LINE__ + 2 | ||
<< "] 1 not less than " << 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the second "1" outside the string (and not the first one)?
Similarly below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason. I'll fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should obviously be reformatted.
tc/lang/gfg/parser.cc
should probably be reformatted separately first.
tc/autotuner/genetic_search.cc
Outdated
<< "the mutation rate (" << mutationRate \ | ||
<< ") should be in the [0,100] interval"; \ | ||
CHECK(crossOverRate >= 0 and crossOverRate <= 100) \ | ||
TC_CHECK(crossOverRate >= 0 and crossOverRate <= 100) \ | ||
<< "the crossover (" << crossOverRate \ | ||
<< ") rate should be in the [0,100] interval"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reformat
tc/autotuner/msg
Outdated
@@ -0,0 +1 @@ | |||
#259 switched from TC function names to using whole TCs (canonicalized) as part of compilation cache keys. However, the final step of the autotuner, that is retrieving the best found options, was not updated and it used just the function name. As a result, an empty optional<CudaMappingOptions> was always returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must have accidentally committed this.
@@ -20,6 +20,7 @@ | |||
#include <cuda_runtime.h> | |||
#include <nvrtc.h> | |||
|
|||
#include "tc/core/check.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only here (and a couple of other places)? Shouldn't every file that uses these calls have this include?
tc/core/tensor-inl.h
Outdated
@@ -18,9 +18,10 @@ | |||
#include <algorithm> | |||
#include <sstream> | |||
|
|||
#include <glog/logging.h> | |||
//#include <glog/logging.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove instead of commenting out
On Wed, May 30, 2018 at 06:18:15AM -0700, Theodoros Theodoridis wrote:
ttheodor commented on this pull request.
> + std::stringstream expected;
+ expected << "Check failed [" << __FILE__ << ':' << __LINE__ + 1 << ']';
+ ASSERT_THROW_WHAT(TC_CHECK(false), expected.str());
+ }
+
+ {
+ std::stringstream expected;
+ expected << "Check failed [" << __FILE__ << ':' << __LINE__ + 2 << ']'
+ << ": 1+1=3";
+ ASSERT_THROW_WHAT(TC_CHECK(false) << "1+1=3", expected.str());
+ }
+}
+
+TEST(CHECK, Vector) {
+ std::stringstream expected;
+ expected << "Check failed [" << __FILE__ << ':' << __LINE__ + 3 << ']'
Do we still have format checking enabled on CI? If yes, then it will complain.
Yes. Complain about what?
skimo
|
This:
|
On Wed, May 30, 2018 at 06:26:23AM -0700, Theodoros Theodoridis wrote:
> Υes. Complain about what?
This:
> This looks fragile and probably compiler dependent.
> Why can you assume that the reported line number is the last line of
> the macro invocation? Better make sure ASSERT_THROW_WHAT call
> is within a single line in these tests.
Why would it complain if you arrange for all ASSERT_THROW_WHAT calls
to stay within a line?
skimo
|
On Thu, May 31, 2018 at 05:51:53AM -0700, Theodoros Theodoridis wrote:
Extra information (passed with `<<`) is optional. The reason I keep track of it in a separate string is to figure out if and where the separator (`:`) and the space before it should be printed.
OK.
skimo
|
0c1e9c2
to
0ef9454
Compare
All comments were addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems you dragged in some other commits. Can we have just the top two on top of master?
Also CI is complaining.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great @ttheodor this is a welcome cleanup.
As a follow up do you intend to have a way to pass the type of exception to TC_CHECK_XXX
like (I think) we had discussed at some point or do you think the vast majority of cases are handled just by CHECK + explicit throw?
Being able to specify the exception type makes a lot of sense. How about adding "overloads" with an extra exception type parameter? For example:
|
@ttheodor sounds good to me but let's do it as a followup PR? No point in delaying landing this nice improvement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the documentation. I fixed the CI issue (hopefully).
@nicolasvasilache since this was still unmerged I went ahead and implemented the checks with custom exception types. |
@ttheodor you should be able to rebase and land this now |
Rebased |
rebase again I guess |
634c512
to
2226b13
Compare
For some reason they only triggered for me when trying to rebase tc_check. This is still relevant as an independent fix.
The glog CHECK macros terminate on failure. Instead of termination the TC_CHECK macros throw exceptions. The available macros are: TC_CHECK(condition) (boolean argument) TC_CHECK_EQ(x, y) (checks if x == y) TC_CHECK_NE(x, y) (checks if x != y) TC_CHECK_LT(x, y) (checks if x < y) TC_CHECK_GT(x, y) (checks if x > y) TC_CHECK_GE(x, y) (checks if x <= y) TC_CHECK_LE(x, y) (checks if x >= y) Additional information can be passed through operator<< and is included in the exception's error message, e.g.: TC_CHECK_EQ(x, 42) << "x is not the answer"; Implementation detail: Information passed with calls to operator<< is maintained in a separate string. The reason is that a separator is printed between the base message and the additional info if it is present (e.g., 1 is not equal to 42: x is not the answer). Maintaining two strings helps determining the correct location for the separator.
2226b13
to
9c31a0c
Compare
The type of the exception thrown on failed checks can now be specified. E.g., TC_CHECK(i, v.size(), std::out_of_range)
9c31a0c
to
3682a4f
Compare
Landing this now without extra reviews because it has been accepted multiple times and ends up being delayed over and over since everything conflicts with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great @ttheodor , thanks!
@@ -161,7 +161,7 @@ MappingOptionsView& MappingOptionsView::scheduleFusionStrategy( | |||
|
|||
MappingOptionsView& MappingOptionsView::scheduleFusionStrategy( | |||
const std::string& str) { | |||
FusionStrategy fs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who complains about this and why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #500, I did not understand that either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #504 (it should show in the CI)
closes #351