Skip to content

Commit 936a60b

Browse files
committed
[SQUASH] Address review comments.
Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent 7f81052 commit 936a60b

19 files changed

+118
-546
lines changed

sycl/test/esimd/on-device/BitonicSortK.cpp

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
// TODO enable on WIndows
1+
// TODO enable on Windows
22
// REQUIRES: linux
33
// REQUIRES: gpu
44
// RUN: %clangxx-esimd -fsycl %s -o %t.out
55
// RUN: %ESIMD_RUN_PLACEHOLDER %t.out
66

7+
#include "esimd_test_utils.hpp"
8+
79
#include <CL/sycl.hpp>
810
#include <CL/sycl/intel/esimd.hpp>
911
#include <algorithm>
@@ -508,46 +510,6 @@ static double report_time(const string &msg, event e0, event en) {
508510
return elapsed;
509511
}
510512

511-
// This is the class provided to SYCL runtime by the application to decide
512-
// on which device to run, or whether to run at all.
513-
// When selecting a device, SYCL runtime first takes (1) a selector provided by
514-
// the program or a default one and (2) the set of all available devices. Then
515-
// it passes each device to the '()' operator of the selector. Device, for
516-
// which '()' returned the highest number, is selected. If a negative number
517-
// was returned for all devices, then the selection process will cause an
518-
// exception.
519-
class ESIMDSelector : public device_selector {
520-
// Require GPU device unless HOST is requested in SYCL_DEVICE_TYPE env
521-
virtual int operator()(const device &device) const {
522-
if (const char *dev_type = getenv("SYCL_DEVICE_TYPE")) {
523-
if (!strcmp(dev_type, "GPU"))
524-
return device.is_gpu() ? 1000 : -1;
525-
if (!strcmp(dev_type, "HOST"))
526-
return device.is_host() ? 1000 : -1;
527-
std::cerr << "Supported 'SYCL_DEVICE_TYPE' env var values are 'GPU' and "
528-
"'HOST', '"
529-
<< dev_type << "' is not.\n";
530-
return -1;
531-
}
532-
// If "SYCL_DEVICE_TYPE" not defined, only allow gpu device
533-
return device.is_gpu() ? 1000 : -1;
534-
}
535-
};
536-
537-
auto exception_handler = [](exception_list l) {
538-
for (auto ep : l) {
539-
try {
540-
std::rethrow_exception(ep);
541-
} catch (cl::sycl::exception &e0) {
542-
std::cout << "sycl::exception: " << e0.what() << std::endl;
543-
} catch (std::exception &e) {
544-
std::cout << "std::exception: " << e.what() << std::endl;
545-
} catch (...) {
546-
std::cout << "generic exception\n";
547-
}
548-
}
549-
};
550-
551513
struct BitonicSort {
552514
enum {
553515
base_sort_size_ = 256,
@@ -703,7 +665,7 @@ int main(int argc, char *argv[]) {
703665
int size = 1 << LOG2_ELEMENTS;
704666
cout << "BitonicSort (" << size << ") Start..." << std::endl;
705667

706-
queue q(ESIMDSelector{}, exception_handler,
668+
queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler(),
707669
property::queue::enable_profiling{});
708670

709671
BitonicSort bitonicSort;

sycl/test/esimd/on-device/BitonicSortKv2.cpp

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
// TODO enable on WIndows
1+
// TODO enable on Windows
22
// REQUIRES: linux
33
// REQUIRES: gpu
44
// RUN: %clangxx-esimd -fsycl %s -o %t.out
55
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
66
// RUN: %ESIMD_RUN_PLACEHOLDER %t.out
77

8+
#include "esimd_test_utils.hpp"
9+
810
#include <CL/sycl.hpp>
911
#include <CL/sycl/intel/esimd.hpp>
1012
#include <algorithm>
@@ -423,46 +425,6 @@ static double report_time(const string &msg, event e0, event en) {
423425
return elapsed;
424426
}
425427

426-
// This is the class provided to SYCL runtime by the application to decide
427-
// on which device to run, or whether to run at all.
428-
// When selecting a device, SYCL runtime first takes (1) a selector provided by
429-
// the program or a default one and (2) the set of all available devices. Then
430-
// it passes each device to the '()' operator of the selector. Device, for
431-
// which '()' returned the highest number, is selected. If a negative number
432-
// was returned for all devices, then the selection process will cause an
433-
// exception.
434-
class ESIMDSelector : public device_selector {
435-
// Require GPU device unless HOST is requested in SYCL_DEVICE_TYPE env
436-
virtual int operator()(const device &device) const {
437-
if (const char *dev_type = getenv("SYCL_DEVICE_TYPE")) {
438-
if (!strcmp(dev_type, "GPU"))
439-
return device.is_gpu() ? 1000 : -1;
440-
if (!strcmp(dev_type, "HOST"))
441-
return device.is_host() ? 1000 : -1;
442-
std::cerr << "Supported 'SYCL_DEVICE_TYPE' env var values are 'GPU' and "
443-
"'HOST', '"
444-
<< dev_type << "' is not.\n";
445-
return -1;
446-
}
447-
// If "SYCL_DEVICE_TYPE" not defined, only allow gpu device
448-
return device.is_gpu() ? 1000 : -1;
449-
}
450-
};
451-
452-
auto exception_handler = [](exception_list l) {
453-
for (auto ep : l) {
454-
try {
455-
std::rethrow_exception(ep);
456-
} catch (cl::sycl::exception &e0) {
457-
std::cout << "sycl::exception: " << e0.what() << std::endl;
458-
} catch (std::exception &e) {
459-
std::cout << "std::exception: " << e.what() << std::endl;
460-
} catch (...) {
461-
std::cout << "generic exception\n";
462-
}
463-
}
464-
};
465-
466428
struct BitonicSort {
467429
enum {
468430
base_sort_size_ = 256,
@@ -618,7 +580,7 @@ int main(int argc, char *argv[]) {
618580
int size = 1 << LOG2_ELEMENTS;
619581
cout << "BitonicSort (" << size << ") Start..." << std::endl;
620582

621-
queue q(ESIMDSelector{}, exception_handler,
583+
queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler(),
622584
property::queue::enable_profiling{});
623585

624586
BitonicSort bitonicSort;

sycl/test/esimd/on-device/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This directory contains ESIMD tests which are run on Intel GPU device only.
2+
Some of them can run on host device too, but in general it is not always
3+
possible as some of ESIMD APIs (e.g. memory access via accessors) is not
4+
implemented for the host device.
Binary file not shown.

sycl/test/esimd/on-device/accessor.cpp

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,20 @@
1-
// TODO enable on WIndows
1+
// TODO enable on Windows
22
// REQUIRES: linux
33
// REQUIRES: gpu
44
// RUN: %clangxx-esimd -fsycl -D_CRT_SECURE_NO_WARNINGS=1 %s -o %t.out
55
// RUN: %ESIMD_RUN_PLACEHOLDER %t.out
66

77
// This test checks that accessor-based memory accesses work correctly in ESIMD.
88

9+
#include "esimd_test_utils.hpp"
10+
911
#include <CL/sycl.hpp>
1012
#include <CL/sycl/intel/esimd.hpp>
1113

1214
#include <iostream>
1315

1416
using namespace cl::sycl;
1517

16-
class ESIMDSelector : public device_selector {
17-
// Require GPU device unless HOST is requested in SYCL_DEVICE_TYPE env
18-
virtual int operator()(const device &device) const {
19-
if (const char *dev_type = getenv("SYCL_DEVICE_TYPE")) {
20-
if (!strcmp(dev_type, "GPU"))
21-
return device.is_gpu() ? 1000 : -1;
22-
if (!strcmp(dev_type, "HOST"))
23-
return device.is_host() ? 1000 : -1;
24-
std::cerr << "Supported 'SYCL_DEVICE_TYPE' env var values are 'GPU' and "
25-
"'HOST', '"
26-
<< dev_type << "' is not.\n";
27-
return -1;
28-
}
29-
// If "SYCL_DEVICE_TYPE" not defined, only allow gpu device
30-
return device.is_gpu() ? 1000 : -1;
31-
}
32-
};
33-
34-
auto exception_handler = [](exception_list l) {
35-
for (auto ep : l) {
36-
try {
37-
std::rethrow_exception(ep);
38-
} catch (cl::sycl::exception &e0) {
39-
std::cout << "sycl::exception: " << e0.what() << std::endl;
40-
} catch (std::exception &e) {
41-
std::cout << "std::exception: " << e.what() << std::endl;
42-
} catch (...) {
43-
std::cout << "generic exception\n";
44-
}
45-
}
46-
};
47-
4818
constexpr unsigned int VL = 1024 * 128;
4919

5020
using Ty = float;
@@ -59,7 +29,7 @@ int main() {
5929
}
6030

6131
try {
62-
queue q(ESIMDSelector{}, exception_handler);
32+
queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler());
6333

6434
buffer<Ty, 1> buf0(data0, range<1>(VL));
6535
buffer<Ty, 1> buf1(data1, range<1>(VL));

sycl/test/esimd/on-device/mandelbrot/esimd_test_utils.hpp renamed to sycl/test/esimd/on-device/esimd_test_utils.hpp

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#include <CL/sycl.hpp>
22

33
#define NOMINMAX
44

@@ -9,7 +9,51 @@
99
#include <iterator>
1010
#include <vector>
1111

12-
namespace esimd_test_utils {
12+
using namespace cl::sycl;
13+
14+
namespace esimd_test {
15+
16+
// This is the class provided to SYCL runtime by the application to decide
17+
// on which device to run, or whether to run at all.
18+
// When selecting a device, SYCL runtime first takes (1) a selector provided by
19+
// the program or a default one and (2) the set of all available devices. Then
20+
// it passes each device to the '()' operator of the selector. Device, for
21+
// which '()' returned the highest number, is selected. If a negative number
22+
// was returned for all devices, then the selection process will cause an
23+
// exception.
24+
class ESIMDSelector : public device_selector {
25+
// Require GPU device unless HOST is requested in SYCL_DEVICE_TYPE env
26+
virtual int operator()(const device &device) const {
27+
if (const char *dev_type = getenv("SYCL_DEVICE_TYPE")) {
28+
if (!strcmp(dev_type, "GPU"))
29+
return device.is_gpu() ? 1000 : -1;
30+
if (!strcmp(dev_type, "HOST"))
31+
return device.is_host() ? 1000 : -1;
32+
std::cerr << "Supported 'SYCL_DEVICE_TYPE' env var values are 'GPU' and "
33+
"'HOST', '"
34+
<< dev_type << "' is not.\n";
35+
return -1;
36+
}
37+
// If "SYCL_DEVICE_TYPE" not defined, only allow gpu device
38+
return device.is_gpu() ? 1000 : -1;
39+
}
40+
};
41+
42+
inline auto createExceptionHandler() {
43+
return [](exception_list l) {
44+
for (auto ep : l) {
45+
try {
46+
std::rethrow_exception(ep);
47+
} catch (cl::sycl::exception &e0) {
48+
std::cout << "sycl::exception: " << e0.what() << std::endl;
49+
} catch (std::exception &e) {
50+
std::cout << "std::exception: " << e.what() << std::endl;
51+
} catch (...) {
52+
std::cout << "generic exception\n";
53+
}
54+
}
55+
};
56+
}
1357

1458
template <typename T>
1559
std::vector<T> read_binary_file(const char *fname, size_t num = 0) {
@@ -106,4 +150,4 @@ To bit_cast(const From &src) noexcept {
106150
return dst;
107151
}
108152

109-
} // namespace esimd_test_utils
153+
} // namespace esimd_test

sycl/test/esimd/on-device/histogram.cpp

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,19 @@
1-
// TODO enable on WIndows
1+
// TODO enable on Windows
22
// REQUIRES: linux
33
// REQUIRES: gpu
44
// RUN: %clangxx-esimd -fsycl %s -o %t.out
55
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
66
// RUN: %ESIMD_RUN_PLACEHOLDER %t.out
77

8+
#include "esimd_test_utils.hpp"
9+
810
#include <CL/sycl.hpp>
911
#include <CL/sycl/intel/esimd.hpp>
1012
#include <array>
1113
#include <iostream>
1214

1315
using namespace cl::sycl;
1416

15-
class ESIMDSelector : public device_selector {
16-
// Require GPU device unless HOST is requested in SYCL_DEVICE_TYPE env
17-
virtual int operator()(const device &device) const {
18-
if (const char *dev_type = getenv("SYCL_DEVICE_TYPE")) {
19-
if (!strcmp(dev_type, "GPU"))
20-
return device.is_gpu() ? 1000 : -1;
21-
if (!strcmp(dev_type, "HOST"))
22-
return device.is_host() ? 1000 : -1;
23-
std::cerr << "Supported 'SYCL_DEVICE_TYPE' env var values are 'GPU' and "
24-
"'HOST', '"
25-
<< dev_type << "' is not.\n";
26-
return -1;
27-
}
28-
// If "SYCL_DEVICE_TYPE" not defined, only allow gpu device
29-
return device.is_gpu() ? 1000 : -1;
30-
}
31-
};
32-
33-
auto exception_handler = [](exception_list l) {
34-
for (auto ep : l) {
35-
try {
36-
std::rethrow_exception(ep);
37-
} catch (cl::sycl::exception &e0) {
38-
std::cout << "sycl::exception: " << e0.what() << std::endl;
39-
} catch (std::exception &e) {
40-
std::cout << "std::exception: " << e.what() << std::endl;
41-
} catch (...) {
42-
std::cout << "generic exception\n";
43-
}
44-
}
45-
};
46-
4717
#define NUM_BINS 256
4818
#define IMG_WIDTH 1024
4919
#define IMG_HEIGHT 1024
@@ -103,7 +73,7 @@ int main(int argc, char *argv[]) {
10373
// Read in image luma plane
10474

10575
// Allocate Input Buffer
106-
queue q(ESIMDSelector{}, exception_handler);
76+
queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler());
10777

10878
auto dev = q.get_device();
10979
auto ctxt = q.get_context();

sycl/test/esimd/on-device/histogram_2d.cpp

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,19 @@
1-
// TODO enable on WIndows
1+
// TODO enable on Windows
22
// REQUIRES: linux
33
// REQUIRES: gpu
44
// RUN: %clangxx-esimd -fsycl %s -o %t.out
55
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
66
// RUN: %ESIMD_RUN_PLACEHOLDER %t.out
77

8+
#include "esimd_test_utils.hpp"
9+
810
#include <CL/sycl.hpp>
911
#include <CL/sycl/intel/esimd.hpp>
1012
#include <array>
1113
#include <iostream>
1214

1315
using namespace cl::sycl;
1416

15-
class ESIMDSelector : public device_selector {
16-
// Require GPU device unless HOST is requested in SYCL_DEVICE_TYPE env
17-
virtual int operator()(const device &device) const {
18-
if (const char *dev_type = getenv("SYCL_DEVICE_TYPE")) {
19-
if (!strcmp(dev_type, "GPU"))
20-
return device.is_gpu() ? 1000 : -1;
21-
if (!strcmp(dev_type, "HOST"))
22-
return device.is_host() ? 1000 : -1;
23-
std::cerr << "Supported 'SYCL_DEVICE_TYPE' env var values are 'GPU' and "
24-
"'HOST', '"
25-
<< dev_type << "' is not.\n";
26-
return -1;
27-
}
28-
// If "SYCL_DEVICE_TYPE" not defined, only allow gpu device
29-
return device.is_gpu() ? 1000 : -1;
30-
}
31-
};
32-
33-
auto exception_handler = [](exception_list l) {
34-
for (auto ep : l) {
35-
try {
36-
std::rethrow_exception(ep);
37-
} catch (cl::sycl::exception &e0) {
38-
std::cout << "sycl::exception: " << e0.what() << std::endl;
39-
} catch (std::exception &e) {
40-
std::cout << "std::exception: " << e.what() << std::endl;
41-
} catch (...) {
42-
std::cout << "generic exception\n";
43-
}
44-
}
45-
};
46-
4717
#define NUM_BINS 256
4818
#define IMG_WIDTH 1024
4919
#define IMG_HEIGHT 1024
@@ -103,7 +73,7 @@ int main(int argc, char *argv[]) {
10373
// Read in image luma plane
10474

10575
// Allocate Input Buffer
106-
queue q(ESIMDSelector{}, exception_handler);
76+
queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler());
10777

10878
auto dev = q.get_device();
10979
auto ctxt = q.get_context();

0 commit comments

Comments
 (0)