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

Convert id tests to Catch2, update for SYCL 2020 #246

Merged
merged 6 commits into from
Jan 31, 2022

Conversation

psalz
Copy link
Contributor

@psalz psalz commented Jan 7, 2022

This is a comprehensive overhaul of the tests for the sycl::id class, using the new Catch2 testing framework idioms. The tests should now cover everything prescribed by the SYCL 2020 Revision 4 specification.

I'm trying out a new pattern here, where instead of performing a bunch of tests on a SYCL device and recording each "assertion's" result in a buffer that is then bulk-asserted on the host, I'm offloading individual expressions to the device using the DEVICE_EVAL macro. This, in my opinion, makes for overall much more readable test cases.

It currently only compiles for DPC++ because:

  • hipSYCL does not implement all operators
  • ComputeCpp does not support unnamed kernel lambdas yet (at least in the stable compiler, the experimental 2.8.0 compiler does support it); also it does not implement all operators

@psalz
Copy link
Contributor Author

psalz commented Jan 7, 2022

(Looks like I forgot to add id to the ComputeCpp CI filter...)

tests/id/id.cpp Outdated Show resolved Hide resolved
@psalz psalz changed the base branch from catch2 to SYCL-2020 January 13, 2022 17:19
Copy link
Member

@keryell keryell left a comment

Choose a reason for hiding this comment

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

Interesting.
I wonder whether it would not me to have more functional programming to have kernel fusion to have all the DEVICE_EVAL contents to be evaluated in a few kernels instead of 1 kernel per DEVICE_EVAL. I am just thinking to the kernel compilation time on FPGA... ;-)

*/
#define DEVICE_EVAL(expr) DEVICE_EVAL_T(decltype(expr), expr)

#endif // __SYCLCTS_TESTS_COMMON_DEVICE_EVAL_H
Copy link
Member

Choose a reason for hiding this comment

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

Missing EOL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added an .editorconfig file with the appropriate setting.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting https://editorconfig.org/
I didn't know about it.

* - Operands must exist in surrounding scope ([=] capture).
* - No lambda expressions (requires C++20). Use DEVICE_EVAL_T instead.
*/
#define DEVICE_EVAL(expr) DEVICE_EVAL_T(decltype(expr), expr)
Copy link
Member

Choose a reason for hiding this comment

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

Why using macros DEVICE_EVAL_T or DEVICE_EVAL at the first place instead of functions or lambdas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean, how would I pass an unevaluated expression into a function/lambda?

Copy link
Member

Choose a reason for hiding this comment

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

I see: no C++20. :-(

#include <sycl/sycl.hpp>

#define DEVICE_EVAL_T(T, expr) \
([=]() { \
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
([=]() { \
([=] { \

sycl_cts::util::get_cts_object::queue() \
.submit([=, &result_buf](sycl::handler& cgh) { \
sycl::accessor result{result_buf, cgh, sycl::write_only}; \
cgh.single_task([=]() { result[0] = expr; }); \
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cgh.single_task([=]() { result[0] = expr; }); \
cgh.single_task([=] { result[0] = expr; }); \

};
} // namespace Catch

#endif // __SYCLCTS_TESTS_COMMON_STRING_MAKERS_H
Copy link
Member

Choose a reason for hiding this comment

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

Missing EOL

tests/id/id.cpp Outdated
CHECK(DEVICE_EVAL(a[i]) == values[i]);
}

#define ASSIGN_COMPONENT(operand_value, c, v) \
Copy link
Member

Choose a reason for hiding this comment

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

Why a macro?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because once you work with macros too much, everything seems like an opportunity for a macro ;-). Fixed.

CHECK(DEVICE_EVAL(b >= a) == idh<D>::get(0, 0, 1));
}

#define COMPOUND_OP(operand_value, expr) \
Copy link
Member

Choose a reason for hiding this comment

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

Why a macro?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as for DEVICE_EVAL, I want to pass an unevaluated expr into here.

Configured to use UNIX line endings for all files and add final newline.
@psalz
Copy link
Contributor Author

psalz commented Jan 27, 2022

I've addressed some of the feedback and added a note to the common by-value semantics test case that there is some uncertainty around its definition (cf KhronosGroup/SYCL-Docs#210). Also I need to take a look at @vasilytric's common_semantics.h utilities and if/how they could be unified with this.

Copy link
Member

@keryell keryell left a comment

Choose a reason for hiding this comment

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

Good!

Copy link
Contributor

@bader bader left a comment

Choose a reason for hiding this comment

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

Recent changes in the target branch conflict with this patch.

@psalz psalz merged commit d4d5aaf into KhronosGroup:SYCL-2020 Jan 31, 2022
@psalz psalz deleted the convert-id-tests-catch2 branch January 31, 2022 16:20
@psalz psalz mentioned this pull request Mar 2, 2022
3 tasks
@psalz psalz linked an issue Mar 2, 2022 that may be closed by this pull request
3 tasks
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.

Update sycl::id tests for SYCL 2020
3 participants