Skip to content

Commit dad7d1a

Browse files
committed
[SYCL] Add #ifdef __SYCL_DEVICE_ONLY__ guards
Signed-off-by: John Pennycook <[email protected]>
1 parent b382ba6 commit dad7d1a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

sycl/include/CL/sycl/intel/sub_group.hpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,39 +475,69 @@ struct sub_group {
475475
__SYCL_DEPRECATED("Collectives in the sub-group class are deprecated. Use "
476476
"sycl::intel::broadcast instead.")
477477
EnableIfIsScalarArithmetic<T> broadcast(T x, id<1> local_id) const {
478+
#ifdef __SYCL_DEVICE_ONLY__
478479
return sycl::detail::spirv::GroupBroadcast<sub_group>(x, local_id);
480+
#else
481+
(void)x;
482+
(void)local_id;
483+
throw runtime_error("Sub-groups are not supported on host device.",
484+
PI_INVALID_DEVICE);
485+
#endif
479486
}
480487

481488
template <typename T, class BinaryOperation>
482489
__SYCL_DEPRECATED("Collectives in the sub-group class are deprecated. Use "
483490
"sycl::intel::reduce instead.")
484491
EnableIfIsScalarArithmetic<T> reduce(T x, BinaryOperation op) const {
492+
#ifdef __SYCL_DEVICE_ONLY__
485493
return sycl::detail::calc<T, __spv::GroupOperation::Reduce,
486494
__spv::Scope::Subgroup>(
487495
typename sycl::detail::GroupOpTag<T>::type(), x, op);
496+
#else
497+
(void)x;
498+
(void)op;
499+
throw runtime_error("Sub-groups are not supported on host device.",
500+
PI_INVALID_DEVICE);
501+
#endif
488502
}
489503

490504
template <typename T, class BinaryOperation>
491505
__SYCL_DEPRECATED("Collectives in the sub-group class are deprecated. Use "
492506
"sycl::intel::reduce instead.")
493507
EnableIfIsScalarArithmetic<T> reduce(T x, T init, BinaryOperation op) const {
508+
#ifdef __SYCL_DEVICE_ONLY__
494509
return op(init, reduce(x, op));
510+
#else
511+
(void)x;
512+
(void)init;
513+
(void)op;
514+
throw runtime_error("Sub-groups are not supported on host device.",
515+
PI_INVALID_DEVICE);
516+
#endif
495517
}
496518

497519
template <typename T, class BinaryOperation>
498520
__SYCL_DEPRECATED("Collectives in the sub-group class are deprecated. Use "
499521
"sycl::intel::exclusive_scan instead.")
500522
EnableIfIsScalarArithmetic<T> exclusive_scan(T x, BinaryOperation op) const {
523+
#ifdef __SYCL_DEVICE_ONLY__
501524
return sycl::detail::calc<T, __spv::GroupOperation::ExclusiveScan,
502525
__spv::Scope::Subgroup>(
503526
typename sycl::detail::GroupOpTag<T>::type(), x, op);
527+
#else
528+
(void)x;
529+
(void)op;
530+
throw runtime_error("Sub-groups are not supported on host device.",
531+
PI_INVALID_DEVICE);
532+
#endif
504533
}
505534

506535
template <typename T, class BinaryOperation>
507536
__SYCL_DEPRECATED("Collectives in the sub-group class are deprecated. Use "
508537
"sycl::intel::exclusive_scan instead.")
509538
EnableIfIsScalarArithmetic<T> exclusive_scan(T x, T init,
510539
BinaryOperation op) const {
540+
#ifdef __SYCL_DEVICE_ONLY__
511541
if (get_local_id().get(0) == 0) {
512542
x = op(init, x);
513543
}
@@ -516,26 +546,48 @@ struct sub_group {
516546
scan = init;
517547
}
518548
return scan;
549+
#else
550+
(void)x;
551+
(void)init;
552+
(void)op;
553+
throw runtime_error("Sub-groups are not supported on host device.",
554+
PI_INVALID_DEVICE);
555+
#endif
519556
}
520557

521558
template <typename T, class BinaryOperation>
522559
__SYCL_DEPRECATED("Collectives in the sub-group class are deprecated. Use "
523560
"sycl::intel::inclusive_scan instead.")
524561
EnableIfIsScalarArithmetic<T> inclusive_scan(T x, BinaryOperation op) const {
562+
#ifdef __SYCL_DEVICE_ONLY__
525563
return sycl::detail::calc<T, __spv::GroupOperation::InclusiveScan,
526564
__spv::Scope::Subgroup>(
527565
typename sycl::detail::GroupOpTag<T>::type(), x, op);
566+
#else
567+
(void)x;
568+
(void)op;
569+
throw runtime_error("Sub-groups are not supported on host device.",
570+
PI_INVALID_DEVICE);
571+
#endif
528572
}
529573

530574
template <typename T, class BinaryOperation>
531575
__SYCL_DEPRECATED("Collectives in the sub-group class are deprecated. Use "
532576
"sycl::intel::inclusive_scan instead.")
533577
EnableIfIsScalarArithmetic<T> inclusive_scan(T x, BinaryOperation op,
534578
T init) const {
579+
#ifdef __SYCL_DEVICE_ONLY__
535580
if (get_local_id().get(0) == 0) {
536581
x = op(init, x);
537582
}
538583
return inclusive_scan(x, op);
584+
#else
585+
(void)x;
586+
(void)op;
587+
(void)init;
588+
throw runtime_error("Sub-groups are not supported on host device.",
589+
PI_INVALID_DEVICE);
590+
#endif
539591
}
540592

541593
protected:

0 commit comments

Comments
 (0)