diff --git a/DirectProgramming/DPC++/ParallelPatterns/PrefixSum/sample.json b/DirectProgramming/DPC++/ParallelPatterns/PrefixSum/sample.json index def268a2f8..71a54aeb58 100644 --- a/DirectProgramming/DPC++/ParallelPatterns/PrefixSum/sample.json +++ b/DirectProgramming/DPC++/ParallelPatterns/PrefixSum/sample.json @@ -1,7 +1,7 @@ { "guid": "5D274319-02EE-44B0-B055-71E4C50D05E0", "name": "PrefixSum", - "categories": [ "Toolkit/Intel® oneAPI Base Toolkit/oneAPI DPC++ Compiler/CPU and GPU" ], + "categories": [ "Toolkit/Intel® oneAPI Base Toolkit/Intel® oneAPI DPC++/C++ Compiler/CPU and GPU" ], "description": "Compute Prefix Sum using Intel® oneAPI DPC++ Language", "toolchain": [ "dpcpp" ], "targetDevice": [ "CPU", "GPU" ], diff --git a/DirectProgramming/DPC++/StructuredGrids/1d_HeatTransfer/src/1d_HeatTransfer.cpp b/DirectProgramming/DPC++/StructuredGrids/1d_HeatTransfer/src/1d_HeatTransfer.cpp index 83f3405ba3..7b9827753b 100644 --- a/DirectProgramming/DPC++/StructuredGrids/1d_HeatTransfer/src/1d_HeatTransfer.cpp +++ b/DirectProgramming/DPC++/StructuredGrids/1d_HeatTransfer/src/1d_HeatTransfer.cpp @@ -34,12 +34,15 @@ // //****************************************************************************** #include -#include #include #include #include +// dpc_common.hpp can be found in the dev-utilities include folder. +// e.g., $ONEAPI_ROOT/dev-utilities//include/dpc_common.hpp +#include "dpc_common.hpp" using namespace sycl; +using namespace std; constexpr float dt = 0.002f; constexpr float dx = 0.01f; @@ -49,12 +52,12 @@ constexpr float temp = 100.0f; // Initial temperature. //************************************ // Function description: display input parameters used for this sample. //************************************ -void Usage(std::string programName) { - std::cout << " Incorrect parameters \n"; - std::cout << " Usage: "; - std::cout << programName << " \n\n"; - std::cout << " n : Number of points to simulate \n"; - std::cout << " i : Number of timesteps \n"; +void Usage(string programName) { + cout << " Incorrect parameters \n"; + cout << " Usage: "; + cout << programName << " \n\n"; + cout << " n : Number of points to simulate \n"; + cout << " i : Number of timesteps \n"; } //************************************ @@ -75,43 +78,40 @@ float* ComputeHeatDeviceParallel(float* arr, float* arr_next, float C, try { // Define the device queue queue q = default_selector{}; - std::cout << "Kernel runs on " - << q.get_device().get_info() << "\n"; + cout << "Kernel runs on " << q.get_device().get_info() + << "\n"; // Set boundary condition at one end. arr[0] = arr_next[0] = temp; float* current_data_ptr = arr; float* next_data_ptr = arr_next; - // current_data_ptr = arr; - // next_data_ptr = arr_next; // Buffer scope { - buffer arr_buf(current_data_ptr, range<1>{num_p + 2}); - buffer arr_next_buf(next_data_ptr, range<1>{num_p + 2}); + buffer temperature_buf(current_data_ptr, range(num_p + 2)); + buffer temperature_next_buf(next_data_ptr, range(num_p + 2)); // Iterate over timesteps for (i = 1; i <= num_iter; i++) { if (i % 2 != 0) { - q.submit([&](handler& h) { + q.submit([&](auto& h) { // The size of memory amount that will be given to the buffer. range<1> num_items{num_p + 2}; - auto arr_acc = arr_buf.get_access(h); - auto arr_next_acc = - arr_next_buf.get_access(h); + accessor temperature(temperature_buf, h); + accessor temperature_next(temperature_next_buf, h); h.parallel_for(num_items, [=](id<1> k) { size_t gid = k.get(0); if (gid == 0) { } else if (gid == num_p + 1) { - arr_next_acc[k] = arr_acc[k - 1]; + temperature_next[k] = temperature[k - 1]; } else { - arr_next_acc[k] = - C * (arr_acc[k + 1] - 2 * arr_acc[k] + arr_acc[k - 1]) + - arr_acc[k]; + temperature_next[k] = + C * (temperature[k + 1] - 2 * temperature[k] + temperature[k - 1]) + + temperature[k]; } }); // end parallel for loop in kernel1 }); // end device queue @@ -121,20 +121,19 @@ float* ComputeHeatDeviceParallel(float* arr, float* arr_next, float C, // The size of memory amount that will be given to the buffer. range<1> num_items{num_p + 2}; - auto arr_acc = arr_buf.get_access(h); - auto arr_next_acc = - arr_next_buf.get_access(h); + accessor temperature(temperature_buf, h); + accessor temperature_next(temperature_next_buf, h); h.parallel_for(num_items, [=](id<1> k) { size_t gid = k.get(0); if (gid == 0) { } else if (gid == num_p + 1) { - arr_acc[k] = arr_next_acc[k - 1]; + temperature[k] = temperature_next[k - 1]; } else { - arr_acc[k] = C * (arr_next_acc[k + 1] - 2 * arr_next_acc[k] + - arr_next_acc[k - 1]) + - arr_next_acc[k]; + temperature[k] = C * (temperature_next[k + 1] - 2 * temperature_next[k] + + temperature_next[k - 1]) + + temperature_next[k]; } }); // end parallel for loop in kernel2 }); // end device queue @@ -144,8 +143,8 @@ float* ComputeHeatDeviceParallel(float* arr, float* arr_next, float C, q.wait_and_throw(); - } catch (cl::sycl::exception e) { - std::cout << "SYCL exception caught: " << e.what() << "\n"; + } catch (sycl::exception e) { + cout << "SYCL exception caught: " << e.what() << "\n"; } if (i % 2 != 0) @@ -197,7 +196,7 @@ bool CompareResults(float* device_results, float* host_results, double norm2 = 0; bool err = false; - std::ofstream err_file; + ofstream err_file; err_file.open("error_diff.txt"); err_file << " \t idx\theat[i]\t\theat_CPU[i] \n"; @@ -225,16 +224,16 @@ int main(int argc, char* argv[]) { // Read input parameters try { - n_point = std::stoi(argv[1]); - n_iteration = std::stoi(argv[2]); + n_point = stoi(argv[1]); + n_iteration = stoi(argv[2]); } catch (...) { Usage(argv[0]); return (-1); } - std::cout << "Number of points: " << n_point << "\n"; - std::cout << "Number of iterations: " << n_iteration << "\n"; + cout << "Number of points: " << n_point << "\n"; + cout << "Number of iterations: " << n_iteration << "\n"; // Array heat and heat_next arrays store temperatures of the current and next // iteration of n_point (calculated in kernel) @@ -260,7 +259,7 @@ int main(int argc, char* argv[]) { ComputeHeatDeviceParallel(heat, heat_next, C, n_point, n_iteration, temp); // Display time used by device - std::cout << "Kernel time: " << t_par.Elapsed() << " sec\n"; + cout << "Elapsed time: " << t_par.Elapsed() << " sec\n"; // Compute heat in CPU in (for comparision) float* final_CPU = NULL; @@ -273,10 +272,10 @@ int main(int argc, char* argv[]) { bool err = CompareResults(final_device, final_CPU, n_point, C); if (err == true) - std::cout << "Please check the error_diff.txt file ...\n"; + cout << "Please check the error_diff.txt file ...\n"; else - std::cout << "PASSED! There is no difference between the results computed " - "in host and in kernel.\n"; + cout << "PASSED! There is no difference between the results computed " + "in host and in kernel.\n"; // Cleanup delete[] heat;