Skip to content

Commit 2010cbb

Browse files
authored
Fix warnings in building libDPPLSyclInterface (#155)
This PR fixes all the currently reported warnings for the libDPPLSyclInterface and suppresses tp_print related warnings when building the Cython module. * Enable warning flags to CXX_FLAGS. * Add __attribute__((unused)) to wrap/unwrap functions. -- Wrap/unwrap functions are imported using the same macro and both versions are not necessarily used in the same file. Adding this attribute prevents a flood of warning. * Remove unused variables. * Initialize before use. * Fix signed comparison warnings. * Some formatting changes. * fix warnings about comparing signed with unsigned * Remove option not known to MSVC. * Silence strncpy deprecation warning on Windows. * Suppress tp_print deprecation warning flood on Linux. * Update changelog.
1 parent 94268cb commit 2010cbb

12 files changed

+154
-115
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ All notable changes to this project will be documented in this file.
66
- Device descriptors "max_compute_units", "max_work_item_dimensions", "max_work_item_sizes", "max_work_group_size", "max_num_sub_groups" and "aspects" for int64 atomics inside dpctl C API and inside the dpctl.SyclDevice class.
77
- MemoryUSM* classes moved to `dpctl.memory` module, added support for aligned allocation, added support for `prefetch` and `mem_advise` (sychronous) methods, implemented `copy_to_host`, `copy_from_host` and `copy_from_device` methods, pickling support, and zero-copy interoperability with Python objects which implement `__sycl_usm_array_inerface__` protocol.
88

9+
### Fixed
10+
- Compiler warnings when building libDPPLSyclInterface and the Cython extensions.
11+
912
### Removed
1013
- The Legacy OpenCL interface.
1114

backends/CMakeLists.txt

+10-10
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ if(WIN32)
6868
message(STATUS "Resetting CXX compiler to: " ${CMAKE_CXX_COMPILER})
6969
message(STATUS "Resetting C compiler to: " ${CMAKE_C_COMPILER})
7070
message(STATUS "Resetting Linker to: " ${CMAKE_LINK})
71-
72-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
73-
-Wall -Wextra -Winit-self -Wuninitialized -Wmissing-declarations \
74-
-fdiagnostics-color=auto -O3 \
75-
")
76-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qstd=c++17")
77-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb3 -DDEBUG ")
71+
set(WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations")
72+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
73+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} -Qstd=c++17")
74+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG")
75+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -Qstd=c++17")
7876
elseif(UNIX)
7977
set(SDL_FLAGS "-fstack-protector -fstack-protector-all -fpic -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -fno-strict-overflow -fno-delete-null-pointer-checks")
80-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SDL_FLAGS} -Wall -Wextra -Winit-self -Wuninitialized -Wmissing-declarations -fdiagnostics-color=auto")
81-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb3 -DDEBUG ")
82-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SDL_FLAGS} -std=c++17 -fsycl")
78+
set(WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations -fdiagnostics-color=auto")
79+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS}")
80+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS} -std=c++17 -fsycl")
81+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG")
82+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -std=c++17 -fsycl")
8383
else()
8484
message(FATAL_ERROR "Unsupported system.")
8585
endif()

backends/include/Support/CBindingWrapping.h

+21-18
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,26 @@
2323
///
2424
//===----------------------------------------------------------------------===//
2525

26-
#pragma once
26+
#pragma once
2727

28-
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
29-
inline ty *unwrap(ref P) { \
30-
return reinterpret_cast<ty*>(P); \
31-
} \
32-
\
33-
inline ref wrap(const ty *P) { \
34-
return reinterpret_cast<ref>(const_cast<ty*>(P)); \
35-
}
28+
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
29+
__attribute__((unused)) inline ty *unwrap(ref P) \
30+
{ \
31+
return reinterpret_cast<ty*>(P); \
32+
} \
33+
\
34+
__attribute__((unused)) inline ref wrap(const ty *P) \
35+
{ \
36+
return reinterpret_cast<ref>(const_cast<ty*>(P)); \
37+
}
3638

37-
#define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
38-
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
39-
\
40-
template<typename T> \
41-
inline T *unwrap(ref P) { \
42-
T *Q = (T*)unwrap(P); \
43-
assert(Q && "Invalid cast!"); \
44-
return Q; \
45-
}
39+
#define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
40+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
41+
\
42+
template<typename T> \
43+
__attribute__((unused)) inline T *unwrap(ref P) \
44+
{ \
45+
T *Q = (T*)unwrap(P); \
46+
assert(Q && "Invalid cast!"); \
47+
return Q; \
48+
}

backends/source/dppl_sycl_device_interface.cpp

+22-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "Support/CBindingWrapping.h"
2929
#include <iomanip>
3030
#include <iostream>
31+
#include <cstring>
3132
#include <CL/sycl.hpp> /* SYCL headers */
3233

3334
using namespace cl::sycl;
@@ -220,8 +221,13 @@ DPPLDevice_GetName (__dppl_keep const DPPLSyclDeviceRef DRef)
220221
auto D = unwrap(DRef);
221222
if (D) {
222223
auto name = D->get_info<info::device::name>();
223-
auto cstr_name = new char [name.length()+1];
224-
std::strcpy (cstr_name, name.c_str());
224+
auto cstr_len = name.length()+1;
225+
auto cstr_name = new char[cstr_len];
226+
#ifdef _WIN32
227+
strncpy_s(cstr_name, cstr_len, name.c_str(), cstr_len);
228+
#else
229+
std::strncpy(cstr_name, name.c_str(), cstr_len);
230+
#endif
225231
return cstr_name;
226232
}
227233
return nullptr;
@@ -233,8 +239,13 @@ DPPLDevice_GetVendorName (__dppl_keep const DPPLSyclDeviceRef DRef)
233239
auto D = unwrap(DRef);
234240
if (D) {
235241
auto vendor = D->get_info<info::device::vendor>();
236-
auto cstr_vendor = new char [vendor.length()+1];
237-
std::strcpy (cstr_vendor, vendor.c_str());
242+
auto cstr_len = vendor.length()+1;
243+
auto cstr_vendor = new char[cstr_len];
244+
#ifdef _WIN32
245+
strncpy_s(cstr_vendor, cstr_len, vendor.c_str(), cstr_len);
246+
#else
247+
std::strncpy(cstr_vendor, vendor.c_str(), cstr_len);
248+
#endif
238249
return cstr_vendor;
239250
}
240251
return nullptr;
@@ -246,8 +257,13 @@ DPPLDevice_GetDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef)
246257
auto D = unwrap(DRef);
247258
if (D) {
248259
auto driver = D->get_info<info::device::driver_version>();
249-
auto cstr_driver = new char [driver.length()+1];
250-
std::strcpy (cstr_driver, driver.c_str());
260+
auto cstr_len = driver.length()+1;
261+
auto cstr_driver = new char[cstr_len];
262+
#ifdef _WIN32
263+
strncpy_s(cstr_driver, cstr_len, driver.c_str(), cstr_len);
264+
#else
265+
std::strncpy(cstr_driver, driver.c_str(), cstr_len);
266+
#endif
251267
return cstr_driver;
252268
}
253269
return nullptr;

backends/source/dppl_sycl_kernel_interface.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ DPPLKernel_GetFunctionName (__dppl_keep const DPPLSyclKernelRef Kernel)
5050
auto kernel_name = SyclKernel->get_info<info::kernel::function_name>();
5151
if(kernel_name.empty())
5252
return nullptr;
53-
auto cstr_name = new char [kernel_name.length()+1];
54-
std::strcpy (cstr_name, kernel_name.c_str());
53+
auto cstr_len = kernel_name.length()+1;
54+
auto cstr_name = new char[cstr_len];
55+
#ifdef _WIN32
56+
strncpy_s(cstr_name, cstr_len, kernel_name.c_str(), cstr_len);
57+
#else
58+
std::strncpy (cstr_name, kernel_name.c_str(), cstr_len);
59+
#endif
5560
return cstr_name;
5661
}
5762

backends/source/dppl_sycl_program_interface.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ DPPLProgram_CreateFromOCLSource (__dppl_keep const DPPLSyclContextRef Ctx,
9696
__dppl_keep const char *Source,
9797
__dppl_keep const char *CompileOpts)
9898
{
99-
cl_int err;
10099
std::string compileOpts;
101100
context *SyclCtx = nullptr;
102101
program *SyclProgram = nullptr;

backends/tests/test_sycl_kernel_interface.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ TEST_F (TestDPPLSyclKernelInterface, CheckGetNumArgs)
9999
auto AddKernel = DPPLProgram_GetKernel(PRef, "add");
100100
auto AxpyKernel = DPPLProgram_GetKernel(PRef, "axpy");
101101

102-
ASSERT_EQ(DPPLKernel_GetNumArgs(AddKernel), 3);
103-
ASSERT_EQ(DPPLKernel_GetNumArgs(AxpyKernel), 4);
102+
ASSERT_EQ(DPPLKernel_GetNumArgs(AddKernel), 3ul);
103+
ASSERT_EQ(DPPLKernel_GetNumArgs(AxpyKernel), 4ul);
104104

105105
DPPLQueue_Delete(QueueRef);
106106
DPPLContext_Delete(CtxRef);

backends/tests/test_sycl_platform_interface.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ struct TestDPPLSyclPlatformInterface : public ::testing::Test
3232
TEST_F (TestDPPLSyclPlatformInterface, CheckGetNumPlatforms)
3333
{
3434
auto nplatforms = DPPLPlatform_GetNumNonHostPlatforms();
35-
EXPECT_GE(nplatforms, 0);
35+
EXPECT_GE(nplatforms, 0ul);
3636
}
3737

3838
TEST_F (TestDPPLSyclPlatformInterface, GetNumBackends)
3939
{
4040
auto nbackends = DPPLPlatform_GetNumNonHostBackends();
41-
EXPECT_GE(nbackends, 0);
41+
EXPECT_GE(nbackends, 0ul);
4242
}
4343

4444
TEST_F (TestDPPLSyclPlatformInterface, GetListOfBackends)

backends/tests/test_sycl_program_interface.cpp

+60-59
Original file line numberDiff line numberDiff line change
@@ -40,74 +40,75 @@ using namespace cl::sycl;
4040

4141
namespace
4242
{
43-
const size_t SIZE = 1024;
43+
const int SIZE = 1024;
4444

45-
void add_kernel_checker (queue *syclQueue, DPPLSyclKernelRef AddKernel)
46-
{
47-
range<1> a_size{SIZE};
48-
std::array<int, SIZE> a, b, c;
45+
void add_kernel_checker (queue *syclQueue, DPPLSyclKernelRef AddKernel)
46+
{
47+
range<1> a_size{SIZE};
48+
std::array<int, SIZE> a, b, c;
4949

50-
for (int i = 0; i<SIZE; ++i) {
51-
a[i] = i;
52-
b[i] = i;
53-
c[i] = 0;
54-
}
50+
for (int i = 0; i < SIZE; ++i) {
51+
a[i] = i;
52+
b[i] = i;
53+
c[i] = 0;
54+
}
5555

56-
{
57-
buffer<int, 1> a_device(a.data(), a_size);
58-
buffer<int, 1> b_device(b.data(), a_size);
59-
buffer<int, 1> c_device(c.data(), a_size);
60-
buffer<int, 1> buffs[3] = {a_device, b_device, c_device};
61-
syclQueue->submit([&](handler& cgh) {
62-
for (auto buff : buffs) {
63-
auto arg = buff.get_access<access::mode::read_write>(cgh);
64-
cgh.set_args(arg);
65-
}
66-
auto syclKernel = reinterpret_cast<kernel*>(AddKernel);
67-
cgh.parallel_for(range<1>{SIZE}, *syclKernel);
68-
});
69-
}
56+
{
57+
buffer<int, 1> a_device(a.data(), a_size);
58+
buffer<int, 1> b_device(b.data(), a_size);
59+
buffer<int, 1> c_device(c.data(), a_size);
60+
buffer<int, 1> buffs[3] = {a_device, b_device, c_device};
61+
syclQueue->submit([&](handler& cgh) {
62+
for (auto buff : buffs) {
63+
auto arg = buff.get_access<access::mode::read_write>(cgh);
64+
cgh.set_args(arg);
65+
}
66+
auto syclKernel = reinterpret_cast<kernel*>(AddKernel);
67+
cgh.parallel_for(range<1>{SIZE}, *syclKernel);
68+
});
69+
}
7070

71-
// Validate the data
72-
for(auto i = 0ul; i < SIZE; ++i) {
73-
EXPECT_EQ(c[i], i + i);
74-
}
71+
// Validate the data
72+
for(int i = 0; i < SIZE; ++i) {
73+
EXPECT_EQ(c[i], i + i);
7574
}
75+
}
7676

77-
void axpy_kernel_checker (queue *syclQueue, DPPLSyclKernelRef AxpyKernel)
78-
{
79-
range<1> a_size{SIZE};
80-
std::array<int, SIZE> a, b, c;
77+
void axpy_kernel_checker (queue *syclQueue, DPPLSyclKernelRef AxpyKernel)
78+
{
79+
range<1> a_size{SIZE};
80+
std::array<int, SIZE> a, b, c;
8181

82-
for (int i = 0; i<SIZE; ++i) {
83-
a[i] = i;
84-
b[i] = i;
85-
c[i] = 0;
86-
}
87-
int d = 10;
88-
{
89-
buffer<int, 1> a_device(a.data(), a_size);
90-
buffer<int, 1> b_device(b.data(), a_size);
91-
buffer<int, 1> c_device(c.data(), a_size);
92-
buffer<int, 1> buffs[3] = {a_device, b_device, c_device};
93-
syclQueue->submit([&](handler& cgh) {
94-
for (auto i = 0ul; i < 3; ++i) {
95-
auto arg = buffs[i].get_access<access::mode::read_write>(cgh);
96-
cgh.set_arg(i, arg);
97-
}
98-
cgh.set_arg(3, d);
99-
auto syclKernel = reinterpret_cast<kernel*>(AxpyKernel);
100-
cgh.parallel_for(range<1>{SIZE}, *syclKernel);
101-
});
102-
}
82+
for (int i = 0; i < SIZE; ++i) {
83+
a[i] = i;
84+
b[i] = i;
85+
c[i] = 0;
86+
}
87+
int d = 10;
88+
{
89+
buffer<int, 1> a_device(a.data(), a_size);
90+
buffer<int, 1> b_device(b.data(), a_size);
91+
buffer<int, 1> c_device(c.data(), a_size);
92+
buffer<int, 1> buffs[3] = {a_device, b_device, c_device};
93+
syclQueue->submit([&](handler& cgh) {
94+
for (auto i = 0ul; i < 3; ++i) {
95+
auto arg = buffs[i].get_access<access::mode::read_write>(cgh);
96+
cgh.set_arg(i, arg);
97+
}
98+
cgh.set_arg(3, d);
99+
auto syclKernel = reinterpret_cast<kernel*>(AxpyKernel);
100+
cgh.parallel_for(range<1>{SIZE}, *syclKernel);
101+
});
102+
}
103103

104-
// Validate the data
105-
for(auto i = 0ul; i < SIZE; ++i) {
106-
EXPECT_EQ(c[i], i + d*i);
107-
}
104+
// Validate the data
105+
for(int i = 0; i < SIZE; ++i) {
106+
EXPECT_EQ(c[i], i + d*i);
108107
}
109108
}
110109

110+
} /* end of anonymous namespace */
111+
111112
struct TestDPPLSyclProgramInterface : public ::testing::Test
112113
{
113114
const char *CLProgramStr = R"CLC(
@@ -128,10 +129,10 @@ struct TestDPPLSyclProgramInterface : public ::testing::Test
128129
size_t nOpenCLGpuQ = 0;
129130

130131
TestDPPLSyclProgramInterface () :
131-
nOpenCLGpuQ(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU)),
132132
spirvFile{"./multi_kernel.spv", std::ios::binary | std::ios::ate},
133133
spirvFileSize(std::filesystem::file_size("./multi_kernel.spv")),
134-
spirvBuffer(spirvFileSize)
134+
spirvBuffer(spirvFileSize),
135+
nOpenCLGpuQ(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU))
135136
{
136137
spirvFile.seekg(0, std::ios::beg);
137138
spirvFile.read(spirvBuffer.data(), spirvFileSize);

backends/tests/test_sycl_queue_manager.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ TEST_F (TestDPPLSyclQueueManager, CheckDPPLGetCurrentQueue)
8383
if(!has_devices())
8484
GTEST_SKIP_("Skipping: No Sycl devices.\n");
8585

86-
DPPLSyclQueueRef q;
86+
DPPLSyclQueueRef q = nullptr;
8787
ASSERT_NO_THROW(q = DPPLQueueMgr_GetCurrentQueue());
8888
ASSERT_TRUE(q != nullptr);
8989
}
@@ -170,7 +170,6 @@ TEST_F (TestDPPLSyclQueueManager, CheckGetNumActivatedQueues)
170170

171171
auto nOpenCLCpuQ = DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_CPU);
172172
auto nOpenCLGpuQ = DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU);
173-
auto nL0GpuQ = DPPLQueueMgr_GetNumQueues(DPPL_LEVEL_ZERO, DPPL_GPU);
174173

175174
// Add a queue to main thread
176175
if(!nOpenCLCpuQ || !nOpenCLGpuQ)
@@ -192,10 +191,10 @@ TEST_F (TestDPPLSyclQueueManager, CheckGetNumActivatedQueues)
192191

193192
// Verify what the expected number of activated queues each time a thread
194193
// called getNumActivatedQueues.
195-
EXPECT_EQ(num0, 1);
196-
EXPECT_EQ(num1, 2);
197-
EXPECT_EQ(num2, 1);
198-
EXPECT_EQ(num4, 0);
194+
EXPECT_EQ(num0, 1ul);
195+
EXPECT_EQ(num1, 2ul);
196+
EXPECT_EQ(num2, 1ul);
197+
EXPECT_EQ(num4, 0ul);
199198

200199
DPPLQueue_Delete(q);
201200
}

0 commit comments

Comments
 (0)