Skip to content

Commit 77df794

Browse files
author
Diptorup Deb
authored
Merge pull request #349 from diptorupd/fix/crashes_reported_in_345_344
Fix/crashes reported in 345 344
2 parents ec0de51 + 1d7ee7d commit 77df794

11 files changed

+427
-353
lines changed

dpctl-capi/source/dpctl_sycl_platform_interface.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ __dpctl_give DPCTLSyclPlatformRef DPCTLPlatform_CreateFromSelector(
8484
PRef = wrap(P);
8585
} catch (std::bad_alloc const &ba) {
8686
std::cerr << ba.what() << '\n';
87+
} catch (runtime_error const &re) {
88+
std::cerr << re.what() << '\n';
89+
return nullptr;
8790
}
8891
}
8992
else {

dpctl-capi/source/dpctl_sycl_queue_manager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ struct QueueManager
6464
delete unwrap(CRef);
6565
} catch (std::bad_alloc const &ba) {
6666
std::cerr << ba.what() << '\n';
67+
} catch (runtime_error const &re) {
68+
std::cerr << re.what() << '\n';
6769
}
6870

6971
return qs;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//===--- test_sycl_device_invalid_filters.cpp - -ve tests for device iface ===//
2+
//
3+
// Data Parallel Control (dpctl)
4+
//
5+
// Copyright 2020-2021 Intel Corporation
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
///
21+
/// \file
22+
/// Negative test cases for SYCL device creation with invalid filter selectors.
23+
///
24+
//===----------------------------------------------------------------------===//
25+
26+
#include "dpctl_sycl_device_interface.h"
27+
#include "dpctl_sycl_device_selector_interface.h"
28+
#include <CL/sycl.hpp>
29+
#include <gtest/gtest.h>
30+
31+
using namespace cl::sycl;
32+
struct TestUnsupportedFilters : public ::testing::TestWithParam<const char *>
33+
{
34+
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
35+
36+
TestUnsupportedFilters()
37+
{
38+
EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLFilterSelector_Create(GetParam()));
39+
}
40+
41+
void SetUp()
42+
{
43+
if (!DSRef) {
44+
auto message = "Skipping as no device of type " +
45+
std::string(GetParam()) + ".";
46+
GTEST_SKIP_(message.c_str());
47+
}
48+
}
49+
50+
~TestUnsupportedFilters()
51+
{
52+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
53+
}
54+
};
55+
56+
TEST_P(TestUnsupportedFilters, Chk_DPCTLDevice_CreateFromSelector)
57+
{
58+
DPCTLSyclDeviceRef DRef = nullptr;
59+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
60+
ASSERT_TRUE(DRef == nullptr);
61+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
62+
}
63+
64+
INSTANTIATE_TEST_SUITE_P(
65+
NegativeDeviceCreationTests,
66+
TestUnsupportedFilters,
67+
::testing::Values("abc", "-1", "invalid_filter", "cuda:cpu:0"));

dpctl-capi/tests/test_sycl_device_selector_interface.cpp

Lines changed: 80 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ struct TestDeviceSelectorInterface : public ::testing::Test
4646
struct TestFilterSelector : public ::testing::TestWithParam<const char *>
4747
{
4848
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
49+
DPCTLSyclDeviceRef DRef = nullptr;
4950

5051
TestFilterSelector()
5152
{
5253
EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLFilterSelector_Create(GetParam()));
54+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
5355
}
5456

5557
void SetUp()
5658
{
57-
if (!DSRef) {
59+
if (!DRef) {
5860
auto message = "Skipping as no device of type " +
5961
std::string(GetParam()) + ".";
6062
GTEST_SKIP_(message.c_str());
@@ -64,6 +66,7 @@ struct TestFilterSelector : public ::testing::TestWithParam<const char *>
6466
~TestFilterSelector()
6567
{
6668
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
69+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
6770
}
6871
};
6972

@@ -76,15 +79,6 @@ struct TestUnsupportedFilters : public ::testing::TestWithParam<const char *>
7679
EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLFilterSelector_Create(GetParam()));
7780
}
7881

79-
void SetUp()
80-
{
81-
if (!DSRef) {
82-
auto message = "Skipping as no device of type " +
83-
std::string(GetParam()) + ".";
84-
GTEST_SKIP_(message.c_str());
85-
}
86-
}
87-
8882
~TestUnsupportedFilters()
8983
{
9084
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
@@ -94,84 +88,107 @@ struct TestUnsupportedFilters : public ::testing::TestWithParam<const char *>
9488
TEST_F(TestDeviceSelectorInterface, Chk_DPCTLAcceleratorSelector_Create)
9589
{
9690
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
91+
DPCTLSyclDeviceRef DRef = nullptr;
92+
9793
EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLAcceleratorSelector_Create());
98-
if (DSRef) {
99-
DPCTLSyclDeviceRef DRef = nullptr;
100-
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
101-
ASSERT_TRUE(DRef != nullptr);
102-
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceMgr_PrintDeviceInfo(DRef));
103-
EXPECT_TRUE(DPCTLDevice_IsAccelerator(DRef));
94+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
95+
96+
if (!DRef) {
97+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
10498
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
99+
GTEST_SKIP_("Device not found. Skip tests.");
105100
}
101+
102+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceMgr_PrintDeviceInfo(DRef));
103+
EXPECT_TRUE(DPCTLDevice_IsAccelerator(DRef));
106104
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
105+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
107106
}
108107

109108
TEST_F(TestDeviceSelectorInterface, Chk_DPCTLDefaultSelector_Create)
110109
{
111110
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
111+
DPCTLSyclDeviceRef DRef = nullptr;
112+
112113
EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLDefaultSelector_Create());
113-
if (DSRef) {
114-
DPCTLSyclDeviceRef DRef = nullptr;
115-
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
116-
ASSERT_TRUE(DRef != nullptr);
117-
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceMgr_PrintDeviceInfo(DRef));
114+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
115+
116+
if (!DRef) {
117+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
118118
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
119+
GTEST_SKIP_("Device not found. Skip tests.");
119120
}
121+
122+
ASSERT_TRUE(DRef != nullptr);
123+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceMgr_PrintDeviceInfo(DRef));
120124
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
125+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
121126
}
122127

123128
TEST_F(TestDeviceSelectorInterface, Chk_DPCTLCPUSelector_Create)
124129
{
125130
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
131+
DPCTLSyclDeviceRef DRef = nullptr;
132+
126133
EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLCPUSelector_Create());
127-
if (DSRef) {
128-
DPCTLSyclDeviceRef DRef = nullptr;
129-
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
130-
ASSERT_TRUE(DRef != nullptr);
131-
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceMgr_PrintDeviceInfo(DRef));
132-
EXPECT_TRUE(DPCTLDevice_IsCPU(DRef));
134+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
135+
136+
if (!DRef) {
137+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
133138
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
139+
GTEST_SKIP_("Device not found. Skip tests.");
134140
}
141+
142+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceMgr_PrintDeviceInfo(DRef));
143+
EXPECT_TRUE(DPCTLDevice_IsCPU(DRef));
135144
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
145+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
136146
}
137147

138148
TEST_F(TestDeviceSelectorInterface, Chk_DPCTLGPUSelector_Create)
139149
{
140150
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
151+
DPCTLSyclDeviceRef DRef = nullptr;
152+
141153
EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLGPUSelector_Create());
142-
if (DSRef) {
143-
DPCTLSyclDeviceRef DRef = nullptr;
144-
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
145-
ASSERT_TRUE(DRef != nullptr);
146-
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceMgr_PrintDeviceInfo(DRef));
147-
EXPECT_TRUE(DPCTLDevice_IsGPU(DRef));
154+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
155+
156+
if (!DRef) {
157+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
148158
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
159+
GTEST_SKIP_("Device not found. Skip tests.");
149160
}
161+
162+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceMgr_PrintDeviceInfo(DRef));
163+
EXPECT_TRUE(DPCTLDevice_IsGPU(DRef));
150164
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
165+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
151166
}
152167

153168
TEST_F(TestDeviceSelectorInterface, Chk_DPCTLHostSelector_Create)
154169
{
155170
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
171+
DPCTLSyclDeviceRef DRef = nullptr;
172+
156173
EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLHostSelector_Create());
157-
if (DSRef) {
158-
DPCTLSyclDeviceRef DRef = nullptr;
159-
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
160-
ASSERT_TRUE(DRef != nullptr);
161-
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceMgr_PrintDeviceInfo(DRef));
162-
// FIXME: DPCPP's host_selector returns a CPU device for some reason.
163-
// EXPECT_TRUE(DPCTLDevice_IsHost(DRef));
174+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
175+
176+
if (!DRef) {
177+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
164178
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
179+
GTEST_SKIP_("Device not found. Skip tests.");
165180
}
181+
182+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceMgr_PrintDeviceInfo(DRef));
183+
// FIXME: DPCPP's host_selector returns a CPU device for some reason.
184+
// EXPECT_TRUE(DPCTLDevice_IsHost(DRef));
166185
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
186+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
167187
}
168188

169189
TEST_P(TestFilterSelector, Chk_DPCTLFilterSelector_Create)
170190
{
171-
DPCTLSyclDeviceRef DRef = nullptr;
172-
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
173191
ASSERT_TRUE(DRef != nullptr);
174-
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
175192
}
176193

177194
TEST_P(TestUnsupportedFilters, Chk_DPCTLFilterSelector_Create)
@@ -186,20 +203,26 @@ TEST_F(TestDeviceSelectorInterface, Chk_DPCTLGPUSelector_Score)
186203
{
187204
DPCTLSyclDeviceSelectorRef DSRef_GPU = nullptr;
188205
DPCTLSyclDeviceSelectorRef DSRef_CPU = nullptr;
206+
DPCTLSyclDeviceRef DRef = nullptr;
207+
189208
EXPECT_NO_FATAL_FAILURE(DSRef_GPU = DPCTLGPUSelector_Create());
190209
EXPECT_NO_FATAL_FAILURE(DSRef_CPU = DPCTLCPUSelector_Create());
191-
if (DSRef_CPU && DSRef_GPU) {
192-
DPCTLSyclDeviceRef DRef = nullptr;
193-
EXPECT_NO_FATAL_FAILURE(DRef =
194-
DPCTLDevice_CreateFromSelector(DSRef_CPU));
195-
ASSERT_TRUE(DRef != nullptr);
196-
EXPECT_TRUE(DPCTLDevice_IsCPU(DRef));
197-
EXPECT_TRUE(DPCTLDeviceSelector_Score(DSRef_GPU, DRef) < 0);
198-
EXPECT_TRUE(DPCTLDeviceSelector_Score(DSRef_CPU, DRef) > 0);
210+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef_CPU));
211+
212+
if (!DRef) {
213+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef_GPU));
214+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef_CPU));
199215
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
216+
GTEST_SKIP_("Device not found. Skip tests.");
200217
}
218+
219+
ASSERT_TRUE(DRef != nullptr);
220+
EXPECT_TRUE(DPCTLDevice_IsCPU(DRef));
221+
EXPECT_TRUE(DPCTLDeviceSelector_Score(DSRef_GPU, DRef) < 0);
222+
EXPECT_TRUE(DPCTLDeviceSelector_Score(DSRef_CPU, DRef) > 0);
201223
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef_GPU));
202224
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef_CPU));
225+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
203226
}
204227

205228
INSTANTIATE_TEST_SUITE_P(FilterSelectorCreation,
@@ -216,9 +239,10 @@ INSTANTIATE_TEST_SUITE_P(FilterSelectorCreation,
216239
"level_zero:gpu:0",
217240
"gpu:0",
218241
"gpu:1",
219-
"1"));
242+
"1",
243+
"0",
244+
"host"));
220245

221-
INSTANTIATE_TEST_SUITE_P(
222-
NegativeFilterSelectorCreation,
223-
TestUnsupportedFilters,
224-
::testing::Values("abc", "-1", "opencl:gpu:1", "level_zero:cpu:0"));
246+
INSTANTIATE_TEST_SUITE_P(NegativeFilterSelectorCreation,
247+
TestUnsupportedFilters,
248+
::testing::Values("abc", "-1", "cuda:cpu:0"));
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//=== test_sycl_platform_invalid_filters.cpp - -ve tests for platform iface ==//
2+
//
3+
// Data Parallel Control (dpctl)
4+
//
5+
// Copyright 2020-2021 Intel Corporation
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
///
21+
/// \file
22+
/// Negative test cases for SYCL platform creation with invalid filter
23+
/// selectors.
24+
///
25+
//===----------------------------------------------------------------------===//
26+
27+
#include "dpctl_sycl_device_selector_interface.h"
28+
#include "dpctl_sycl_platform_interface.h"
29+
#include <CL/sycl.hpp>
30+
#include <gtest/gtest.h>
31+
32+
using namespace cl::sycl;
33+
struct TestUnsupportedFilters : public ::testing::TestWithParam<const char *>
34+
{
35+
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
36+
37+
TestUnsupportedFilters()
38+
{
39+
EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLFilterSelector_Create(GetParam()));
40+
}
41+
42+
void SetUp()
43+
{
44+
if (!DSRef) {
45+
auto message = "Skipping as no device of type " +
46+
std::string(GetParam()) + ".";
47+
GTEST_SKIP_(message.c_str());
48+
}
49+
}
50+
51+
~TestUnsupportedFilters()
52+
{
53+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
54+
}
55+
};
56+
57+
TEST_P(TestUnsupportedFilters, Chk_DPCTLPlatform_CreateFromSelector)
58+
{
59+
DPCTLSyclPlatformRef PRef = nullptr;
60+
EXPECT_NO_FATAL_FAILURE(PRef = DPCTLPlatform_CreateFromSelector(DSRef));
61+
ASSERT_TRUE(PRef == nullptr);
62+
EXPECT_NO_FATAL_FAILURE(DPCTLPlatform_Delete(PRef));
63+
}
64+
65+
INSTANTIATE_TEST_SUITE_P(
66+
NegativeDeviceCreationTests,
67+
TestUnsupportedFilters,
68+
::testing::Values("abc", "-1", "invalid_filter", "cuda:cpu:0"));

0 commit comments

Comments
 (0)