|
433 | 433 | "\n", |
434 | 434 | "It is common for parallel kernels to produce a single output resulting from some combination of all inputs (e.g. the sum). Writing efficient reductions is a complex task, depending on both device and runtime characteristics. Providing an abstraction for reductions in SYCL would greatly improve programmer productivity.\n", |
435 | 435 | "\n", |
436 | | - "`sycl::ext::oneapi::reduction` object in parallel_for encapsulates the reduction variable, an optional operator identity and the reduction operator as shown below:\n", |
| 436 | + "`sycl::reduction` object in parallel_for encapsulates the reduction variable, an optional operator identity and the reduction operator as shown below:\n", |
437 | 437 | "\n", |
438 | 438 | "```cpp\n", |
439 | | - " q.parallel_for(nd_range<1>{N, B}, sycl::ext::oneapi::reduction(sum, 0, sycl::plus<>()), [=](nd_item<1> it, auto& temp) {\n", |
| 439 | + " q.parallel_for(nd_range<1>{N, B}, sycl::reduction(sum, sycl::plus<>()), [=](nd_item<1> it, auto& temp) {\n", |
440 | 440 | " int i = it.get_global_id(0);\n", |
441 | 441 | " temp.combine(data[i]);\n", |
442 | 442 | " });\n", |
|
454 | 454 | "cell_type": "markdown", |
455 | 455 | "metadata": {}, |
456 | 456 | "source": [ |
457 | | - "The code below uses __sycl::ext::oneapi::reduction__ object in _parallel_for_ to compute the reduction with just one kernel using Unified Shared Memory(USM) for memory management.\n", |
| 457 | + "The code below uses __sycl::reduction__ object in _parallel_for_ to compute the reduction with just one kernel using Unified Shared Memory(USM) for memory management.\n", |
458 | 458 | "\n", |
459 | 459 | "The DPC++ code below demonstrates reduction in parallel_for with USM: Inspect code, there are no modifications necessary:\n", |
460 | 460 | "\n", |
|
469 | 469 | "metadata": {}, |
470 | 470 | "outputs": [], |
471 | 471 | "source": [ |
472 | | - "%%writefile lab/sum_oneapi_reduction_usm.cpp\n", |
| 472 | + "%%writefile lab/sum_reduction_usm.cpp\n", |
473 | 473 | "//==============================================================\n", |
474 | 474 | "// Copyright © 2020 Intel Corporation\n", |
475 | 475 | "//\n", |
|
496 | 496 | " *sum = 0;\n", |
497 | 497 | "\n", |
498 | 498 | " //# nd-range kernel parallel_for with reduction parameter\n", |
499 | | - " q.parallel_for(nd_range<1>{N, B}, ext::oneapi::reduction(sum, 0, plus<>()), [=](nd_item<1> it, auto& temp) {\n", |
| 499 | + " q.parallel_for(nd_range<1>{N, B}, reduction(sum, plus<>()), [=](nd_item<1> it, auto& temp) {\n", |
500 | 500 | " auto i = it.get_global_id(0);\n", |
501 | 501 | " temp.combine(data[i]);\n", |
502 | 502 | " }).wait();\n", |
|
523 | 523 | "metadata": {}, |
524 | 524 | "outputs": [], |
525 | 525 | "source": [ |
526 | | - "! chmod 755 q; chmod 755 run_sum_oneapi_reduction_usm.sh; if [ -x \"$(command -v qsub)\" ]; then ./q run_sum_oneapi_reduction_usm.sh; else ./run_sum_oneapi_reduction_usm.sh; fi" |
| 526 | + "! chmod 755 q; chmod 755 run_sum_reduction_usm.sh; if [ -x \"$(command -v qsub)\" ]; then ./q run_sum_reduction_usm.sh; else ./run_sum_reduction_usm.sh; fi" |
527 | 527 | ] |
528 | 528 | }, |
529 | 529 | { |
|
545 | 545 | "cell_type": "markdown", |
546 | 546 | "metadata": {}, |
547 | 547 | "source": [ |
548 | | - "The code below uses __sycl::ext::oneapi::reduction__ object in _parallel_for_ to compute the reduction with just one kernel using SYCL buffers and accessors for memory management.\n", |
| 548 | + "The code below uses __sycl::reduction__ object in _parallel_for_ to compute the reduction with just one kernel using SYCL buffers and accessors for memory management.\n", |
549 | 549 | "\n", |
550 | 550 | "The DPC++ code below demonstrates reduction in parallel_for with Buffers: Inspect code, there are no modifications necessary:\n", |
551 | 551 | "\n", |
|
560 | 560 | "metadata": {}, |
561 | 561 | "outputs": [], |
562 | 562 | "source": [ |
563 | | - "%%writefile lab/sum_oneapi_reduction_buffers.cpp\n", |
| 563 | + "%%writefile lab/sum_reduction_buffers.cpp\n", |
564 | 564 | "//==============================================================\n", |
565 | 565 | "// Copyright © 2020 Intel Corporation\n", |
566 | 566 | "//\n", |
|
586 | 586 | " buffer buf_sum(&sum, range(1));\n", |
587 | 587 | "\n", |
588 | 588 | " q.submit([&](handler& h) {\n", |
589 | | - " //# create accessors for buffers\n", |
| 589 | + " //# create accessors for buffer\n", |
590 | 590 | " accessor acc_data(buf_data, h, read_only);\n", |
591 | | - " accessor acc_sum(buf_sum, h);\n", |
592 | 591 | "\n", |
593 | 592 | " //# nd-range kernel parallel_for with reduction parameter\n", |
594 | | - " h.parallel_for(nd_range<1>{N, B}, ext::oneapi::reduction(acc_sum, 0, plus<>()), [=](nd_item<1> it, auto& temp) {\n", |
| 593 | + " h.parallel_for(nd_range<1>{N, B}, reduction(buf_sum, h, plus<>()), [=](nd_item<1> it, auto& temp) {\n", |
595 | 594 | " auto i = it.get_global_id(0);\n", |
596 | 595 | " temp.combine(acc_data[i]);\n", |
597 | 596 | " });\n", |
|
617 | 616 | "metadata": {}, |
618 | 617 | "outputs": [], |
619 | 618 | "source": [ |
620 | | - "! chmod 755 q; chmod 755 run_sum_oneapi_reduction_buffers.sh; if [ -x \"$(command -v qsub)\" ]; then ./q run_sum_oneapi_reduction_buffers.sh; else ./run_sum_oneapi_reduction_buffers.sh; fi" |
| 619 | + "! chmod 755 q; chmod 755 run_sum_reduction_buffers.sh; if [ -x \"$(command -v qsub)\" ]; then ./q run_sum_reduction_buffers.sh; else ./run_sum_reduction_buffers.sh; fi" |
621 | 620 | ] |
622 | 621 | }, |
623 | 622 | { |
|
639 | 638 | "cell_type": "markdown", |
640 | 639 | "metadata": {}, |
641 | 640 | "source": [ |
642 | | - "The code below uses multiple __sycl::ext::oneapi::reduction__ objects in _parallel_for_ to compute the reductions with just one kernel using SYCL buffers and accessors for memory management.\n", |
| 641 | + "The code below uses multiple __sycl::reduction__ objects in _parallel_for_ to compute the reductions with just one kernel using SYCL buffers and accessors for memory management.\n", |
643 | 642 | "\n", |
644 | 643 | "Multiple reductions are also supported with just one kernel, the code snippet below shows how to definne a kernel using parallel_for with multiple reduction objects:\n", |
645 | 644 | "\n", |
|
693 | 692 | " q.submit([&](handler& h) {\n", |
694 | 693 | " //# create accessors for data and results\n", |
695 | 694 | " accessor acc_data(buf_data, h, read_only);\n", |
696 | | - " accessor acc_sum(buf_sum, h);\n", |
697 | | - " accessor acc_min(buf_min, h);\n", |
698 | | - " accessor acc_max(buf_max, h);\n", |
699 | 695 | " \n", |
700 | 696 | " //# define reduction objects for sum, min, max reduction\n", |
701 | | - " auto reduction_sum = ext::oneapi::reduction(acc_sum, 0, plus<>());\n", |
702 | | - " auto reduction_min = ext::oneapi::reduction(acc_min, 0, minimum<>());\n", |
703 | | - " auto reduction_max = ext::oneapi::reduction(acc_max, 0, maximum<>());\n", |
| 697 | + " auto reduction_sum = reduction(buf_sum, h, plus<>());\n", |
| 698 | + " auto reduction_min = reduction(buf_min, h, minimum<>());\n", |
| 699 | + " auto reduction_max = reduction(buf_max, h, maximum<>());\n", |
704 | 700 | " \n", |
705 | 701 | " //# parallel_for with multiple reduction objects\n", |
706 | 702 | " h.parallel_for(nd_range<1>{N, B}, reduction_sum, reduction_min, reduction_max, [=](nd_item<1> it, auto& temp_sum, auto& temp_min, auto& temp_max) {\n", |
|
760 | 756 | "cell_type": "markdown", |
761 | 757 | "metadata": {}, |
762 | 758 | "source": [ |
763 | | - "The code below uses __sycl::ext::oneapi::reduction__ object in _parallel_for_ to compute the reduction object that uses a custom operator to find minumum value and index.\n", |
| 759 | + "The code below uses __sycl::reduction__ object in _parallel_for_ to compute the reduction object that uses a custom operator to find minumum value and index.\n", |
764 | 760 | "\n", |
765 | 761 | "The DPC++ code below demonstrates reduction in parallel_for with custom user defined operator to perform reduction: Inspect code, there are no modifications necessary:\n", |
766 | 762 | "\n", |
|
775 | 771 | "metadata": {}, |
776 | 772 | "outputs": [], |
777 | 773 | "source": [ |
778 | | - "%%writefile lab/oneapi_reduction_custom_operator.cpp\n", |
| 774 | + "%%writefile lab/reduction_custom_operator.cpp\n", |
779 | 775 | "//==============================================================\n", |
780 | 776 | "// Copyright © 2020 Intel Corporation\n", |
781 | 777 | "//\n", |
|
815 | 811 | " //# custom operator for reduction to find minumum and index\n", |
816 | 812 | " pair<int, int> operator_identity = {std::numeric_limits<int>::max(), std::numeric_limits<int>::min()};\n", |
817 | 813 | " *result = operator_identity;\n", |
818 | | - " auto reduction_object = ext::oneapi::reduction(result, operator_identity, minimum<pair<int, int>>());\n", |
| 814 | + " auto reduction_object = reduction(result, operator_identity, minimum<pair<int, int>>());\n", |
819 | 815 | "\n", |
820 | 816 | " //# parallel_for with user defined reduction object\n", |
821 | 817 | " q.parallel_for(nd_range<1>{N, B}, reduction_object, [=](nd_item<1> item, auto& temp) {\n", |
|
845 | 841 | "metadata": {}, |
846 | 842 | "outputs": [], |
847 | 843 | "source": [ |
848 | | - "! chmod 755 q; chmod 755 run_oneapi_reduction_custom_operator.sh; if [ -x \"$(command -v qsub)\" ]; then ./q run_oneapi_reduction_custom_operator.sh; else ./run_oneapi_reduction_custom_operator.sh; fi" |
| 844 | + "! chmod 755 q; chmod 755 run_reduction_custom_operator.sh; if [ -x \"$(command -v qsub)\" ]; then ./q run_reduction_custom_operator.sh; else ./run_reduction_custom_operator.sh; fi" |
849 | 845 | ] |
850 | 846 | }, |
851 | 847 | { |
|
867 | 863 | "cell_type": "markdown", |
868 | 864 | "metadata": {}, |
869 | 865 | "source": [ |
870 | | - "`sycl::reduce_over_group` function for sub_group/work_group and `sycl::ext::oneapi::reduction` in parallel_for helps to optimize and simplify reduction computation in DPC++" |
| 866 | + "`sycl::reduce_over_group` function for sub_group/work_group and `sycl::reduction` in parallel_for helps to optimize and simplify reduction computation in DPC++" |
871 | 867 | ] |
872 | | - }, |
873 | | - { |
874 | | - "cell_type": "code", |
875 | | - "execution_count": null, |
876 | | - "metadata": {}, |
877 | | - "outputs": [], |
878 | | - "source": [] |
879 | 868 | } |
880 | 869 | ], |
881 | 870 | "metadata": { |
|
0 commit comments