Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a015f1e
Add bitonic-sort sample.
lqnguyen Jul 13, 2020
d3ab219
Add a note about common file in README.
lqnguyen Jul 14, 2020
8818264
Move 1d_HeatTransfer sample to open source GitHub.
lqnguyen Jul 14, 2020
8cf6c7a
Merge branch 'master' of https://github.com/oneapi-src/oneAPI-samples
lqnguyen Jul 16, 2020
39a5118
Merge pull request #2 from oneapi-src/master
lqnguyen Aug 14, 2020
306e10b
Updating License file to remove date
lqnguyen Aug 14, 2020
d8b1c57
Adding Buffer Object approach.
lqnguyen Aug 14, 2020
74e5ec0
Add comment about the location of dpc_common.hpp.
lqnguyen Aug 14, 2020
e2e8d01
New sample: Prefix Sum.
lqnguyen Aug 14, 2020
4f4a320
Remove new sample.
lqnguyen Aug 14, 2020
9de715d
New code sample PrefixSum in ParallelPatterns.
lqnguyen Aug 18, 2020
83f58ee
Merge pull request #3 from oneapi-src/master
lqnguyen Aug 18, 2020
e2e39f1
Integrate MPI code sample with dpc_reduce code sample.
lqnguyen Aug 21, 2020
9cf98ad
Update README.md
JoeOster Aug 21, 2020
6a8a521
Update main.cpp
JoeOster Aug 21, 2020
7bb9631
Integrate MPI with latest dpc_reduce for beta09.
lqnguyen Aug 27, 2020
116ec93
Update README.md
JoeOster Aug 27, 2020
99ae832
Update main.cpp
JoeOster Aug 27, 2020
f13fe3b
Merge pull request #4 from oneapi-src/master
JoeOster Aug 27, 2020
f170e71
Update main.cpp
JoeOster Aug 27, 2020
7a8b961
Update README.md
JoeOster Aug 27, 2020
c71b305
Update CXX to icpx and compiler option for beta09.
lqnguyen Aug 27, 2020
0507e5e
Add "export I_MPI_CXX=dpcpp" in sample.json file.
lqnguyen Aug 28, 2020
ca398c6
Update json file.
lqnguyen Sep 18, 2020
3852b9b
merged and resolved the conflict in CMakeLists.txt, README.md, sample…
lqnguyen Sep 19, 2020
47a915d
Merge branch 'master' of https://github.com/oneapi-src/oneAPI-samples
lqnguyen Sep 24, 2020
d80d94a
Sync with master.
lqnguyen Sep 24, 2020
c56d424
Update 1d_HeatTransfer code sample according to the new guideline.
lqnguyen Oct 2, 2020
70e159f
Add comment about dpc_common.hpp .
lqnguyen Oct 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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" ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@
//
//******************************************************************************
#include <CL/sycl.hpp>
#include <dpc_common.hpp>
#include <fstream>
#include <iomanip>
#include <iostream>
// dpc_common.hpp can be found in the dev-utilities include folder.
// e.g., $ONEAPI_ROOT/dev-utilities/<version>/include/dpc_common.hpp
#include "dpc_common.hpp"

using namespace sycl;
using namespace std;

constexpr float dt = 0.002f;
constexpr float dx = 0.01f;
Expand All @@ -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> <i>\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> <i>\n\n";
cout << " n : Number of points to simulate \n";
cout << " i : Number of timesteps \n";
}

//************************************
Expand All @@ -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<info::device::name>() << "\n";
cout << "Kernel runs on " << q.get_device().get_info<info::device::name>()
<< "\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<float, 1> arr_buf(current_data_ptr, range<1>{num_p + 2});
buffer<float, 1> 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<access::mode::read_write>(h);
auto arr_next_acc =
arr_next_buf.get_access<access::mode::read_write>(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
Expand All @@ -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<access::mode::read_write>(h);
auto arr_next_acc =
arr_next_buf.get_access<access::mode::read_write>(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
Expand All @@ -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)
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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;
Expand Down