Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Tc check #460

Merged
merged 4 commits into from
Jun 11, 2018
Merged

Tc check #460

merged 4 commits into from
Jun 11, 2018

Conversation

thetheodor
Copy link

closes #351

@skimo-openhub
Copy link
Contributor

skimo-openhub commented May 29, 2018 via email

Copy link
Contributor

@skimo-openhub skimo-openhub left a 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, {}, {});
}
Copy link
Contributor

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?

Copy link
Author

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_;
Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Author

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:

  1. The optional/extra information is maintained on a separate string.
  2. 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(CHECK, Vector) {
std::stringstream expected;
expected << "Check failed [" << __FILE__ << ':' << __LINE__ + 3 << ']'
Copy link
Contributor

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.

Copy link
Author

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.

{
std::stringstream expected;
expected << "Check failed [" << __FILE__ << ':' << __LINE__ + 2
<< "] 1 not less than " << 1;
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

@skimo-openhub skimo-openhub left a 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.

<< "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";
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

what's this?

Copy link
Author

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"
Copy link
Contributor

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?

@@ -18,9 +18,10 @@
#include <algorithm>
#include <sstream>

#include <glog/logging.h>
//#include <glog/logging.h>
Copy link
Contributor

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

@skimo-openhub
Copy link
Contributor

skimo-openhub commented May 30, 2018 via email

@thetheodor
Copy link
Author

Υ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.

@skimo-openhub
Copy link
Contributor

skimo-openhub commented May 30, 2018 via email

@skimo-openhub
Copy link
Contributor

skimo-openhub commented May 31, 2018 via email

@thetheodor thetheodor force-pushed the tc_check branch 2 times, most recently from 0c1e9c2 to 0ef9454 Compare May 31, 2018 13:30
@thetheodor
Copy link
Author

All comments were addressed.

Copy link
Contributor

@skimo-openhub skimo-openhub left a 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.

skimo-openhub
skimo-openhub previously approved these changes May 31, 2018
Copy link
Contributor

@nicolasvasilache nicolasvasilache left a 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?

@thetheodor
Copy link
Author

Being able to specify the exception type makes a lot of sense. How about adding "overloads" with an extra exception type parameter? For example:

CHECK_LT(i,size, std::out_of_range);

@nicolasvasilache
Copy link
Contributor

@ttheodor sounds good to me but let's do it as a followup PR? No point in delaying landing this nice improvement.

skimo-openhub
skimo-openhub previously approved these changes Jun 1, 2018
Copy link
Contributor

@skimo-openhub skimo-openhub left a 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).

@thetheodor
Copy link
Author

@nicolasvasilache since this was still unmerged I went ahead and implemented the checks with custom exception types.

@nicolasvasilache
Copy link
Contributor

@ttheodor you should be able to rebase and land this now

@thetheodor
Copy link
Author

Rebased

ftynse
ftynse previously approved these changes Jun 4, 2018
@nicolasvasilache
Copy link
Contributor

rebase again I guess

nicolasvasilache and others added 2 commits June 10, 2018 18:38
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.
Theodoros Theodoridis added 2 commits June 10, 2018 20:30
The type of the exception thrown on failed checks can now be specified.
E.g., TC_CHECK(i, v.size(), std::out_of_range)
@nicolasvasilache
Copy link
Contributor

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.

Copy link
Contributor

@nicolasvasilache nicolasvasilache left a comment

Choose a reason for hiding this comment

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

Great @ttheodor , thanks!

@nicolasvasilache nicolasvasilache merged commit de3eea1 into master Jun 11, 2018
@nicolasvasilache nicolasvasilache deleted the tc_check branch June 11, 2018 03:53
@@ -161,7 +161,7 @@ MappingOptionsView& MappingOptionsView::scheduleFusionStrategy(

MappingOptionsView& MappingOptionsView::scheduleFusionStrategy(
const std::string& str) {
FusionStrategy fs;
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement CHECK macros as exceptions
5 participants