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

Commit e6dce8d

Browse files
committed
To avoid splitting increases maintainability burden greatly, use -DENABLE_FP64 macro to split 'double' type code as following:
``` // test.cpp // RUN: ... -DENABLE_FP64=false constexpr bool EnableFP64 = ENABLE_FP64; void test() { // non-fp64-case do_smth(); if constexpr (EnableFP64) do_smth64(); } // test-fp64.cpp ; RUN: ... -DENABLE_FP64=true \#include <test-fp.cpp> ```
1 parent bb846ff commit e6dce8d

File tree

60 files changed

+2372
-3971
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2372
-3971
lines changed

SYCL/AtomicRef/assignment_atomic64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ int main() {
1717
}
1818

1919
constexpr int N = 32;
20+
#ifdef ENABLE_FP64
21+
assignment_test<double>(q, N);
22+
#endif
2023

2124
// Include long tests if they are 64 bits wide
2225
if constexpr (sizeof(long) == 8) {
Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// REQUIRES: aspect-fp64
2-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -DENABLE_FP64 %s -o %t.out
33
// RUN: %HOST_RUN_PLACEHOLDER %t.out
44
// RUN: %CPU_RUN_PLACEHOLDER %t.out
55
// RUN: %GPU_RUN_PLACEHOLDER %t.out
@@ -8,23 +8,4 @@
88
// XFAIL: hip
99
// Expected failure because hip does not have atomic64 check implementation
1010

11-
#include "assignment.h"
12-
#include <iostream>
13-
using namespace sycl;
14-
15-
int main() {
16-
queue q;
17-
if (!q.get_device().has(aspect::fp64)) {
18-
std::cout << "Skipping test\n";
19-
return 0;
20-
}
21-
if (!q.get_device().has(aspect::atomic64)) {
22-
std::cout << "Skipping test\n";
23-
return 0;
24-
}
25-
26-
constexpr int N = 32;
27-
assignment_test<double>(q, N);
28-
29-
std::cout << "Test passed." << std::endl;
30-
}
11+
#include "assignment_atomic64.cpp"

SYCL/AtomicRef/assignment_atomic64_generic.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ int main() {
2020
}
2121

2222
constexpr int N = 32;
23-
23+
#ifdef ENABLE_FP64
24+
assignment_generic_test<double>(q, N);
25+
#endif
2426
// Include long tests if they are 64 bits wide
2527
if constexpr (sizeof(long) == 8) {
2628
assignment_generic_test<long>(q, N);
@@ -37,6 +39,5 @@ int main() {
3739
if constexpr (sizeof(char *) == 8) {
3840
assignment_generic_test<char *>(q, N);
3941
}
40-
4142
std::cout << "Test passed." << std::endl;
4243
}
Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// REQUIRES: aspect-fp64
2-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -DENABLE_FP64 %s -o %t.out
33
// RUN: %HOST_RUN_PLACEHOLDER %t.out
44
// RUN: %CPU_RUN_PLACEHOLDER %t.out
55
// RUN: %GPU_RUN_PLACEHOLDER %t.out
@@ -8,23 +8,4 @@
88
// CUDA backend has had no support for the generic address space yet
99
// XFAIL: cuda || hip
1010

11-
#include "assignment.h"
12-
#include <iostream>
13-
using namespace sycl;
14-
15-
int main() {
16-
queue q;
17-
if (!q.get_device().has(aspect::fp64)) {
18-
std::cout << "Skipping test\n";
19-
return 0;
20-
}
21-
if (!q.get_device().has(aspect::atomic64)) {
22-
std::cout << "Skipping test\n";
23-
return 0;
24-
}
25-
26-
constexpr int N = 32;
27-
assignment_generic_test<double>(q, N);
28-
29-
std::cout << "Test passed." << std::endl;
30-
}
11+
#include "assignment_atomic64_generic.cpp"

SYCL/Basic/buffer/buffer.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ int main() {
2525
int data = 5;
2626
bool failed = false;
2727
buffer<int, 1> buf(&data, range<1>(1));
28+
2829
{
2930
int data1[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
3031
{
@@ -508,16 +509,26 @@ int main() {
508509
size_t size = 32;
509510
const size_t dims = 1;
510511
sycl::range<dims> r(size);
511-
512512
std::shared_ptr<bool> bool_shrd(new bool[size],
513513
[](bool *data) { delete[] data; });
514514
std::shared_ptr<int> int_shrd(new int[size],
515515
[](int *data) { delete[] data; });
516+
#ifdef ENABLE_FP64
517+
std::shared_ptr<double> double_shrd(new double[size],
518+
[](double *data) { delete[] data; });
519+
#endif
516520

517521
std::vector<bool> bool_vector;
518522
std::vector<int> int_vector;
523+
#ifdef ENABLE_FP64
524+
std::vector<double> double_vector;
525+
#endif
526+
519527
bool_vector.reserve(size);
520528
int_vector.reserve(size);
529+
#ifdef ENABLE_FP64
530+
double_vector.reserve(size);
531+
#endif
521532

522533
sycl::queue Queue;
523534
std::mutex m;
@@ -528,30 +539,55 @@ int main() {
528539
sycl::buffer<int, dims> buf_int_shrd(
529540
int_shrd, r,
530541
sycl::property_list{sycl::property::buffer::use_mutex(m)});
542+
#ifdef ENABLE_FP64
543+
sycl::buffer<double, dims> buf_double_shrd(
544+
double_shrd, r,
545+
sycl::property_list{sycl::property::buffer::use_mutex(m)});
546+
#endif
531547
m.lock();
532548
std::fill(bool_shrd.get(), (bool_shrd.get() + size), bool());
533549
std::fill(int_shrd.get(), (int_shrd.get() + size), int());
550+
#ifdef ENABLE_FP64
551+
std::fill(double_shrd.get(), (double_shrd.get() + size), double());
552+
#endif
534553
m.unlock();
535-
536554
buf_bool_shrd.set_final_data(bool_vector.begin());
537555
buf_int_shrd.set_final_data(int_vector.begin());
556+
#ifdef ENABLE_FP64
557+
buf_double_shrd.set_final_data(double_vector.begin());
558+
#endif
559+
538560
buf_bool_shrd.set_write_back(true);
539561
buf_int_shrd.set_write_back(true);
562+
#ifdef ENABLE_FP64
563+
buf_double_shrd.set_write_back(true);
564+
#endif
540565

541566
Queue.submit([&](sycl::handler &cgh) {
542567
auto Accessor_bool =
543568
buf_bool_shrd.get_access<sycl::access::mode::write>(cgh);
544569
auto Accessor_int =
545570
buf_int_shrd.get_access<sycl::access::mode::write>(cgh);
571+
#ifdef ENABLE_FP64
572+
auto Accessor_double =
573+
buf_double_shrd.get_access<sycl::access::mode::write>(cgh);
574+
#endif
546575
cgh.parallel_for<class FillBuffer>(r, [=](sycl::id<1> WIid) {
547576
Accessor_bool[WIid] = true;
548577
Accessor_int[WIid] = 3;
578+
#ifdef ENABLE_FP64
579+
Accessor_double[WIid] = 7.5;
580+
#endif
549581
});
550582
});
551583
} // Data is copied back
552584

553585
for (size_t i = 0; i < size; i++) {
554586
if (bool_vector[i] != true || int_vector[i] != 3) {
587+
#ifdef ENABLE_FP64
588+
if (bool_vector[i] != true || int_vector[i] != 3 ||
589+
double_vector[i] != 7.5) {
590+
#endif
555591
assert(false && "Data was not copied back");
556592
return 1;
557593
}
Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// REQUIRES: aspect-fp64
2-
// RUN: %clangxx %cxx_std_optionc++17 %s -o %t1.out %sycl_options
2+
// RUN: %clangxx %cxx_std_optionc++17 -DENABLE_FP64 %s -o %t1.out %sycl_options
33
// RUN: %HOST_RUN_PLACEHOLDER %t1.out
44
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t2.out
55
// RUN: %HOST_RUN_PLACEHOLDER %t2.out
@@ -15,56 +15,4 @@
1515
//
1616
//===----------------------------------------------------------------------===//
1717

18-
#include <sycl/sycl.hpp>
19-
20-
#include <cassert>
21-
#include <memory>
22-
23-
using namespace sycl;
24-
25-
template <class T> constexpr T write_back_result = T(3);
26-
template <> constexpr double write_back_result<double> = double(7.5);
27-
template <class T> class fill_buffer_for_write_back {};
28-
29-
template <class T, int D> void check_set_write_back() {
30-
size_t size = 32;
31-
sycl::range<D> r(size);
32-
std::shared_ptr<T> shrd(new T[size], [](T *data) { delete[] data; });
33-
std::vector<T> vector;
34-
vector.reserve(size);
35-
sycl::queue Queue;
36-
std::mutex m;
37-
{
38-
sycl::buffer<T, D> buf_shrd(
39-
shrd, r, sycl::property_list{sycl::property::buffer::use_mutex(m)});
40-
m.lock();
41-
std::fill(shrd.get(), (shrd.get() + size), T());
42-
m.unlock();
43-
buf_shrd.set_final_data(vector.begin());
44-
buf_shrd.set_write_back(true);
45-
Queue.submit([&](sycl::handler &cgh) {
46-
auto Accessor =
47-
buf_shrd.template get_access<sycl::access::mode::write>(cgh);
48-
cgh.parallel_for<class fill_buffer_for_write_back<T>>(
49-
r, [=](sycl::id<1> WIid) { Accessor[WIid] = write_back_result<T>; });
50-
});
51-
} // Data is copied back
52-
for (size_t i = 0; i < size; i++) {
53-
if (vector[i] != write_back_result<T>) {
54-
assert(false && "Data was not copied back");
55-
}
56-
}
57-
}
58-
59-
int main() {
60-
// Check that data is copied back after forcing write-back using
61-
// set_write_back
62-
queue q;
63-
if (!q.get_device().has(aspect::fp64)) {
64-
std::cout << "Skipping test\n";
65-
return 0;
66-
}
67-
68-
check_set_write_back<double, 1>();
69-
return 0;
70-
}
18+
#include "buffer.cpp"

SYCL/DeprecatedFeatures/SpecConsts1.2.1/specialization_constants.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#define HALF 0 // FIXME Spec constants do not support half type yet
2424

2525
class SpecializedKernel;
26-
2726
class MyBoolConst;
2827
class MyInt8Const;
2928
class MyUInt8Const;
@@ -35,6 +34,9 @@ class MyInt64Const;
3534
class MyUInt64Const;
3635
class MyHalfConst;
3736
class MyFloatConst;
37+
#ifdef ENABLE_FP64
38+
class MyDoubleConst;
39+
#endif
3840

3941
using namespace sycl;
4042

@@ -53,6 +55,9 @@ int64_t int64_ref = rnd() % std::numeric_limits<int64_t>::max();
5355
uint64_t uint64_ref = rnd() % std::numeric_limits<uint64_t>::max();
5456
half half_ref = rnd() % std::numeric_limits<uint16_t>::max();
5557
float float_ref = rnd() % std::numeric_limits<uint32_t>::max();
58+
#ifdef ENABLE_FP64
59+
double double_ref = rnd() % std::numeric_limits<uint64_t>::max();
60+
#endif
5661

5762
template <typename T1, typename T2>
5863
bool check(const T1 &test, const T2 &ref, std::string type) {
@@ -107,9 +112,11 @@ int main(int argc, char **argv) {
107112
#endif
108113
ext::oneapi::experimental::spec_constant<float, MyFloatConst> f32 =
109114
prog.set_spec_constant<MyFloatConst>(float_ref);
110-
115+
#ifdef ENABLE_FP64
116+
ext::oneapi::experimental::spec_constant<double, MyDoubleConst> f64 =
117+
prog.set_spec_constant<MyDoubleConst>(double_ref);
118+
#endif
111119
prog.build_with_kernel_type<SpecializedKernel>();
112-
113120
bool bool_test = 0;
114121
int8_t int8_test = 0;
115122
uint8_t uint8_test = 0;
@@ -121,6 +128,9 @@ int main(int argc, char **argv) {
121128
uint64_t uint64_test = 0;
122129
half half_test = 0;
123130
float float_test = 0;
131+
#ifdef ENABLE_FP64
132+
double double_test = 0;
133+
#endif
124134

125135
{
126136
buffer<bool> bool_buf(&bool_test, 1);
@@ -134,6 +144,9 @@ int main(int argc, char **argv) {
134144
buffer<uint64_t> uint64_buf(&uint64_test, 1);
135145
buffer<half> half_buf(&half_test, 1);
136146
buffer<float> float_buf(&float_test, 1);
147+
#ifdef ENABLE_FP64
148+
buffer<double> double_buf(&double_test, 1);
149+
#endif
137150

138151
q.submit([&](handler &cgh) {
139152
auto bool_acc = bool_buf.get_access<access::mode::write>(cgh);
@@ -147,6 +160,9 @@ int main(int argc, char **argv) {
147160
auto uint64_acc = uint64_buf.get_access<access::mode::write>(cgh);
148161
auto half_acc = half_buf.get_access<access::mode::write>(cgh);
149162
auto float_acc = float_buf.get_access<access::mode::write>(cgh);
163+
#ifdef ENABLE_FP64
164+
auto double_acc = double_buf.get_access<access::mode::write>(cgh);
165+
#endif
150166
cgh.single_task<SpecializedKernel>(prog.get_kernel<SpecializedKernel>(),
151167
[=]() {
152168
bool_acc[0] = i1.get();
@@ -162,6 +178,9 @@ int main(int argc, char **argv) {
162178
half_acc[0] = f16.get();
163179
#endif
164180
float_acc[0] = f32.get();
181+
#ifdef ENABLE_FP64
182+
double_acc[0] = f64.get();
183+
#endif
165184
});
166185
});
167186
}
@@ -189,6 +208,10 @@ int main(int argc, char **argv) {
189208
#endif
190209
if (!check(float_test, float_ref, "float"))
191210
return 1;
211+
#ifdef ENABLE_FP64
212+
if (!check(double_test, double_ref, "double"))
213+
return 1;
214+
#endif
192215
} catch (const exception &e) {
193216
std::cout << "an async SYCL exception was caught: "
194217
<< std::string(e.what());

0 commit comments

Comments
 (0)