forked from oneapi-src/SYCLomatic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCLomatic oneapi-src#1760] Compare the random number generated from…
… CPU and GPU (oneapi-src#644) Signed-off-by: Jiang, Zhiwei <[email protected]>
- Loading branch information
Showing
6 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<test driverID="test_multi_devices" name="TEMPLATE"> | ||
<description>WARNING: DON'T UPDATE THIS FILE MANUALLY!!! | ||
This is auto-generated accessors configuration file which affects all tests in ported gcc suites | ||
If you have any issue with this file please contact Compiler QA team</description> | ||
<files> | ||
<file path="src/${testName}.cpp"/> | ||
</files> | ||
<rules> | ||
<optlevelRule GPUFeature="NOT double" excludeOptlevelNameString="gpu"/> | ||
<optlevelRule excludeOptlevelNameString="cuda" /> | ||
</rules> | ||
</test> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<suite> | ||
<description>multi devices test</description> | ||
<tests> | ||
<test testName="rng" configFile="config/TEMPLATE_multi_devices.xml" splitGroup="double"/> | ||
</tests> | ||
</suite> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// ===------- rng.cpp ------------------------------------- *- C++ -* ----=== // | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// ===--------------------------------------------------------------------=== // | ||
|
||
#include <sycl/sycl.hpp> | ||
#include <dpct/rng_utils.hpp> | ||
#include <cstdio> | ||
|
||
int main() { | ||
sycl::queue cpu_q(sycl::cpu_selector_v, sycl::property::queue::in_order()); | ||
sycl::queue gpu_q(sycl::gpu_selector_v, sycl::property::queue::in_order()); | ||
|
||
float *h_data = (float *)std::malloc(sizeof(float) * 10); | ||
float *d_data; | ||
d_data = sycl::malloc_shared<float>(10, gpu_q); | ||
|
||
dpct::rng::host_rng_ptr h_rng; | ||
dpct::rng::host_rng_ptr d_rng; | ||
|
||
h_rng = dpct::rng::create_host_rng(dpct::rng::random_engine_type::mt2203, cpu_q); | ||
d_rng = dpct::rng::create_host_rng(dpct::rng::random_engine_type::mt2203, gpu_q); | ||
h_rng->set_engine_idx(1); | ||
d_rng->set_engine_idx(1); | ||
|
||
h_rng->generate_gaussian(h_data, 10, 0, 1); | ||
d_rng->generate_gaussian(d_data, 10, 0, 1); | ||
|
||
cpu_q.wait(); | ||
gpu_q.wait(); | ||
|
||
for (int i = 0; i < 10; i++) | ||
printf("%f, ", h_data[i]); | ||
printf("\n"); | ||
for (int i = 0; i < 10; i++) | ||
printf("%f, ", d_data[i]); | ||
printf("\n"); | ||
|
||
for (int i = 0; i < 10; i++) { | ||
if (std::abs(h_data[i] - d_data[i]) > 0.01f) | ||
return -1; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<testDrivers> | ||
<testDriver driverID="test_multi_devices" file="test_multi_devices.py" title="test_multi_devices"> | ||
<description>Test driver for multi_devices test of DPCT</description> | ||
</testDriver> | ||
</testDrivers> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# ===------ test_multi_devices.py ------------------------ *- Python -* ----===# | ||
# | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ===-----------------------------------------------------------------------===# | ||
|
||
import os | ||
import re | ||
import sys | ||
from pathlib import Path | ||
parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | ||
sys.path.append(parent) | ||
|
||
from test_utils import * | ||
|
||
def setup_test(): | ||
return True | ||
|
||
def migrate_test(): | ||
return True | ||
|
||
def build_test(): | ||
if (os.path.exists(test_config.current_test)): | ||
os.chdir(test_config.current_test) | ||
test_config.out_root = os.getcwd() | ||
|
||
mkl_related = ["rng"] | ||
|
||
srcs = [] | ||
cmp_opts = [] | ||
link_opts = [] | ||
objects = [] | ||
|
||
for dirpath, dirnames, filenames in os.walk(test_config.out_root): | ||
srcs.append(os.path.abspath(os.path.join(dirpath, test_config.current_test + ".cpp"))) | ||
|
||
if test_config.current_test in mkl_related: | ||
mkl_opts = [] | ||
if platform.system() == "Linux": | ||
mkl_opts = test_config.mkl_link_opt_lin | ||
else: | ||
mkl_opts = test_config.mkl_link_opt_win | ||
link_opts += mkl_opts | ||
cmp_opts.append("-DMKL_ILP64") | ||
|
||
ret = compile_and_link(srcs, cmp_opts, objects, link_opts) | ||
return ret | ||
|
||
def run_test(): | ||
args = [] | ||
ret = run_binary_with_args(args) | ||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters