@@ -56,7 +56,25 @@ class Functor2 {
56
56
};
57
57
} // namespace ns
58
58
59
- // Case 2:
59
+ // Case 3:
60
+ // - functor class is defined in the translation unit scope.
61
+ // - the functor has two call operators defined.
62
+
63
+ class FunctorMulti {
64
+ public:
65
+ FunctorMulti (int X_,
66
+ sycl::accessor<int , 1 , sycl_read_write, sycl_device> &Acc_)
67
+ : X(X_), Acc(Acc_) {}
68
+
69
+ void operator ()(sycl::id<1 > id = 0 ) const { Acc[id] += X; }
70
+ void operator ()(sycl::id<2 > id) const {}
71
+
72
+ private:
73
+ int X;
74
+ sycl::accessor<int , 1 , sycl_read_write, sycl_device> Acc;
75
+ };
76
+
77
+ // Case 4:
60
78
// - functor class is templated and defined in the translation unit scope
61
79
// - the '()' operator:
62
80
// * has a parameter of type sycl::id<1> (to be used in 'parallel_for').
@@ -73,7 +91,7 @@ template <typename T> class TmplFunctor {
73
91
sycl::accessor<T, 1 , sycl_read_write, sycl_device> Acc;
74
92
};
75
93
76
- // Case 3 :
94
+ // Case 5 :
77
95
// - functor class is templated and defined in the translation unit scope
78
96
// - the '()' operator:
79
97
// * has a parameter of type sycl::id<1> (to be used in 'parallel_for').
@@ -156,14 +174,39 @@ template <typename T> T bar(T X) {
156
174
return res;
157
175
}
158
176
177
+ int multi (int X) {
178
+ int A[] = {10 };
179
+ {
180
+ sycl::queue Q;
181
+ sycl::buffer<int , 1 > Buf (A, 1 );
182
+
183
+ Q.submit ([&](sycl::handler &cgh) {
184
+ auto Acc = Buf.get_access <sycl_read_write, sycl_device>(cgh);
185
+ FunctorMulti F (X, Acc);
186
+ cgh.parallel_for (sycl::range<1 >(X), F);
187
+ });
188
+ }
189
+ return A[0 ];
190
+ }
191
+
159
192
int main () {
160
193
const int Res1 = foo (10 );
161
194
const int Res2 = bar (10 );
162
195
const int Gold1 = 40 ;
163
196
const int Gold2 = 80 ;
164
-
165
197
assert (Res1 == Gold1);
166
198
assert (Res2 == Gold2);
167
199
200
+ sycl::queue deviceQueue;
201
+ // This test case is currently enabled only for GPUs, and fails on CPU and
202
+ // Accelerator RT.
203
+ // TODO: Remove this conditional check after the RT issues in CPU and
204
+ // Accelerator are fixed.
205
+ if (deviceQueue.get_device ().is_gpu ()) {
206
+ const int Res3 = multi (10 );
207
+ const int Gold3 = 20 ;
208
+ assert (Res3 == Gold3);
209
+ }
210
+
168
211
return 0 ;
169
212
}
0 commit comments