diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f57941c65..24813e479d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ All notable changes to this project will be documented in this file. - 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. - 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. +### Fixed +- Compiler warnings when building libDPPLSyclInterface and the Cython extensions. + ### Removed - The Legacy OpenCL interface. diff --git a/backends/CMakeLists.txt b/backends/CMakeLists.txt index a8d02185f2..263a6d96c3 100644 --- a/backends/CMakeLists.txt +++ b/backends/CMakeLists.txt @@ -68,18 +68,18 @@ if(WIN32) message(STATUS "Resetting CXX compiler to: " ${CMAKE_CXX_COMPILER}) message(STATUS "Resetting C compiler to: " ${CMAKE_C_COMPILER}) message(STATUS "Resetting Linker to: " ${CMAKE_LINK}) - - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \ - -Wall -Wextra -Winit-self -Wuninitialized -Wmissing-declarations \ - -fdiagnostics-color=auto -O3 \ - ") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qstd=c++17") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb3 -DDEBUG ") + set(WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} -Qstd=c++17") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -Qstd=c++17") elseif(UNIX) 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") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SDL_FLAGS} -Wall -Wextra -Winit-self -Wuninitialized -Wmissing-declarations -fdiagnostics-color=auto") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb3 -DDEBUG ") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SDL_FLAGS} -std=c++17 -fsycl") + set(WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations -fdiagnostics-color=auto") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS} -std=c++17 -fsycl") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -std=c++17 -fsycl") else() message(FATAL_ERROR "Unsupported system.") endif() diff --git a/backends/include/Support/CBindingWrapping.h b/backends/include/Support/CBindingWrapping.h index 4c77612269..4570176992 100644 --- a/backends/include/Support/CBindingWrapping.h +++ b/backends/include/Support/CBindingWrapping.h @@ -23,23 +23,26 @@ /// //===----------------------------------------------------------------------===// - #pragma once +#pragma once - #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ - inline ty *unwrap(ref P) { \ - return reinterpret_cast(P); \ - } \ - \ - inline ref wrap(const ty *P) { \ - return reinterpret_cast(const_cast(P)); \ - } +#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ + __attribute__((unused)) inline ty *unwrap(ref P) \ + { \ + return reinterpret_cast(P); \ + } \ + \ + __attribute__((unused)) inline ref wrap(const ty *P) \ + { \ + return reinterpret_cast(const_cast(P)); \ + } - #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \ - DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ - \ - template \ - inline T *unwrap(ref P) { \ - T *Q = (T*)unwrap(P); \ - assert(Q && "Invalid cast!"); \ - return Q; \ - } + #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \ + DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ + \ + template \ + __attribute__((unused)) inline T *unwrap(ref P) \ + { \ + T *Q = (T*)unwrap(P); \ + assert(Q && "Invalid cast!"); \ + return Q; \ + } diff --git a/backends/source/dppl_sycl_device_interface.cpp b/backends/source/dppl_sycl_device_interface.cpp index 8c14bfd38e..5aca623418 100644 --- a/backends/source/dppl_sycl_device_interface.cpp +++ b/backends/source/dppl_sycl_device_interface.cpp @@ -28,6 +28,7 @@ #include "Support/CBindingWrapping.h" #include #include +#include #include /* SYCL headers */ using namespace cl::sycl; @@ -220,8 +221,13 @@ DPPLDevice_GetName (__dppl_keep const DPPLSyclDeviceRef DRef) auto D = unwrap(DRef); if (D) { auto name = D->get_info(); - auto cstr_name = new char [name.length()+1]; - std::strcpy (cstr_name, name.c_str()); + auto cstr_len = name.length()+1; + auto cstr_name = new char[cstr_len]; +#ifdef _WIN32 + strncpy_s(cstr_name, cstr_len, name.c_str(), cstr_len); +#else + std::strncpy(cstr_name, name.c_str(), cstr_len); +#endif return cstr_name; } return nullptr; @@ -233,8 +239,13 @@ DPPLDevice_GetVendorName (__dppl_keep const DPPLSyclDeviceRef DRef) auto D = unwrap(DRef); if (D) { auto vendor = D->get_info(); - auto cstr_vendor = new char [vendor.length()+1]; - std::strcpy (cstr_vendor, vendor.c_str()); + auto cstr_len = vendor.length()+1; + auto cstr_vendor = new char[cstr_len]; +#ifdef _WIN32 + strncpy_s(cstr_vendor, cstr_len, vendor.c_str(), cstr_len); +#else + std::strncpy(cstr_vendor, vendor.c_str(), cstr_len); +#endif return cstr_vendor; } return nullptr; @@ -246,8 +257,13 @@ DPPLDevice_GetDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef) auto D = unwrap(DRef); if (D) { auto driver = D->get_info(); - auto cstr_driver = new char [driver.length()+1]; - std::strcpy (cstr_driver, driver.c_str()); + auto cstr_len = driver.length()+1; + auto cstr_driver = new char[cstr_len]; +#ifdef _WIN32 + strncpy_s(cstr_driver, cstr_len, driver.c_str(), cstr_len); +#else + std::strncpy(cstr_driver, driver.c_str(), cstr_len); +#endif return cstr_driver; } return nullptr; diff --git a/backends/source/dppl_sycl_kernel_interface.cpp b/backends/source/dppl_sycl_kernel_interface.cpp index e030974bc3..152cf59197 100644 --- a/backends/source/dppl_sycl_kernel_interface.cpp +++ b/backends/source/dppl_sycl_kernel_interface.cpp @@ -50,8 +50,13 @@ DPPLKernel_GetFunctionName (__dppl_keep const DPPLSyclKernelRef Kernel) auto kernel_name = SyclKernel->get_info(); if(kernel_name.empty()) return nullptr; - auto cstr_name = new char [kernel_name.length()+1]; - std::strcpy (cstr_name, kernel_name.c_str()); + auto cstr_len = kernel_name.length()+1; + auto cstr_name = new char[cstr_len]; +#ifdef _WIN32 + strncpy_s(cstr_name, cstr_len, kernel_name.c_str(), cstr_len); +#else + std::strncpy (cstr_name, kernel_name.c_str(), cstr_len); +#endif return cstr_name; } diff --git a/backends/source/dppl_sycl_program_interface.cpp b/backends/source/dppl_sycl_program_interface.cpp index edb8429c3f..e076d4080e 100644 --- a/backends/source/dppl_sycl_program_interface.cpp +++ b/backends/source/dppl_sycl_program_interface.cpp @@ -96,7 +96,6 @@ DPPLProgram_CreateFromOCLSource (__dppl_keep const DPPLSyclContextRef Ctx, __dppl_keep const char *Source, __dppl_keep const char *CompileOpts) { - cl_int err; std::string compileOpts; context *SyclCtx = nullptr; program *SyclProgram = nullptr; diff --git a/backends/tests/test_sycl_kernel_interface.cpp b/backends/tests/test_sycl_kernel_interface.cpp index 8ef4d8d951..d841b0c430 100644 --- a/backends/tests/test_sycl_kernel_interface.cpp +++ b/backends/tests/test_sycl_kernel_interface.cpp @@ -99,8 +99,8 @@ TEST_F (TestDPPLSyclKernelInterface, CheckGetNumArgs) auto AddKernel = DPPLProgram_GetKernel(PRef, "add"); auto AxpyKernel = DPPLProgram_GetKernel(PRef, "axpy"); - ASSERT_EQ(DPPLKernel_GetNumArgs(AddKernel), 3); - ASSERT_EQ(DPPLKernel_GetNumArgs(AxpyKernel), 4); + ASSERT_EQ(DPPLKernel_GetNumArgs(AddKernel), 3ul); + ASSERT_EQ(DPPLKernel_GetNumArgs(AxpyKernel), 4ul); DPPLQueue_Delete(QueueRef); DPPLContext_Delete(CtxRef); diff --git a/backends/tests/test_sycl_platform_interface.cpp b/backends/tests/test_sycl_platform_interface.cpp index fed815e9bf..645e883b40 100644 --- a/backends/tests/test_sycl_platform_interface.cpp +++ b/backends/tests/test_sycl_platform_interface.cpp @@ -32,13 +32,13 @@ struct TestDPPLSyclPlatformInterface : public ::testing::Test TEST_F (TestDPPLSyclPlatformInterface, CheckGetNumPlatforms) { auto nplatforms = DPPLPlatform_GetNumNonHostPlatforms(); - EXPECT_GE(nplatforms, 0); + EXPECT_GE(nplatforms, 0ul); } TEST_F (TestDPPLSyclPlatformInterface, GetNumBackends) { auto nbackends = DPPLPlatform_GetNumNonHostBackends(); - EXPECT_GE(nbackends, 0); + EXPECT_GE(nbackends, 0ul); } TEST_F (TestDPPLSyclPlatformInterface, GetListOfBackends) diff --git a/backends/tests/test_sycl_program_interface.cpp b/backends/tests/test_sycl_program_interface.cpp index b32f7b7ab5..b2f22c0aca 100644 --- a/backends/tests/test_sycl_program_interface.cpp +++ b/backends/tests/test_sycl_program_interface.cpp @@ -40,74 +40,75 @@ using namespace cl::sycl; namespace { - const size_t SIZE = 1024; +const int SIZE = 1024; - void add_kernel_checker (queue *syclQueue, DPPLSyclKernelRef AddKernel) - { - range<1> a_size{SIZE}; - std::array a, b, c; +void add_kernel_checker (queue *syclQueue, DPPLSyclKernelRef AddKernel) +{ + range<1> a_size{SIZE}; + std::array a, b, c; - for (int i = 0; i a_device(a.data(), a_size); - buffer b_device(b.data(), a_size); - buffer c_device(c.data(), a_size); - buffer buffs[3] = {a_device, b_device, c_device}; - syclQueue->submit([&](handler& cgh) { - for (auto buff : buffs) { - auto arg = buff.get_access(cgh); - cgh.set_args(arg); - } - auto syclKernel = reinterpret_cast(AddKernel); - cgh.parallel_for(range<1>{SIZE}, *syclKernel); - }); - } + { + buffer a_device(a.data(), a_size); + buffer b_device(b.data(), a_size); + buffer c_device(c.data(), a_size); + buffer buffs[3] = {a_device, b_device, c_device}; + syclQueue->submit([&](handler& cgh) { + for (auto buff : buffs) { + auto arg = buff.get_access(cgh); + cgh.set_args(arg); + } + auto syclKernel = reinterpret_cast(AddKernel); + cgh.parallel_for(range<1>{SIZE}, *syclKernel); + }); + } - // Validate the data - for(auto i = 0ul; i < SIZE; ++i) { - EXPECT_EQ(c[i], i + i); - } + // Validate the data + for(int i = 0; i < SIZE; ++i) { + EXPECT_EQ(c[i], i + i); } +} - void axpy_kernel_checker (queue *syclQueue, DPPLSyclKernelRef AxpyKernel) - { - range<1> a_size{SIZE}; - std::array a, b, c; +void axpy_kernel_checker (queue *syclQueue, DPPLSyclKernelRef AxpyKernel) +{ + range<1> a_size{SIZE}; + std::array a, b, c; - for (int i = 0; i a_device(a.data(), a_size); - buffer b_device(b.data(), a_size); - buffer c_device(c.data(), a_size); - buffer buffs[3] = {a_device, b_device, c_device}; - syclQueue->submit([&](handler& cgh) { - for (auto i = 0ul; i < 3; ++i) { - auto arg = buffs[i].get_access(cgh); - cgh.set_arg(i, arg); - } - cgh.set_arg(3, d); - auto syclKernel = reinterpret_cast(AxpyKernel); - cgh.parallel_for(range<1>{SIZE}, *syclKernel); - }); - } + for (int i = 0; i < SIZE; ++i) { + a[i] = i; + b[i] = i; + c[i] = 0; + } + int d = 10; + { + buffer a_device(a.data(), a_size); + buffer b_device(b.data(), a_size); + buffer c_device(c.data(), a_size); + buffer buffs[3] = {a_device, b_device, c_device}; + syclQueue->submit([&](handler& cgh) { + for (auto i = 0ul; i < 3; ++i) { + auto arg = buffs[i].get_access(cgh); + cgh.set_arg(i, arg); + } + cgh.set_arg(3, d); + auto syclKernel = reinterpret_cast(AxpyKernel); + cgh.parallel_for(range<1>{SIZE}, *syclKernel); + }); + } - // Validate the data - for(auto i = 0ul; i < SIZE; ++i) { - EXPECT_EQ(c[i], i + d*i); - } + // Validate the data + for(int i = 0; i < SIZE; ++i) { + EXPECT_EQ(c[i], i + d*i); } } +} /* end of anonymous namespace */ + struct TestDPPLSyclProgramInterface : public ::testing::Test { const char *CLProgramStr = R"CLC( @@ -128,10 +129,10 @@ struct TestDPPLSyclProgramInterface : public ::testing::Test size_t nOpenCLGpuQ = 0; TestDPPLSyclProgramInterface () : - nOpenCLGpuQ(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU)), spirvFile{"./multi_kernel.spv", std::ios::binary | std::ios::ate}, spirvFileSize(std::filesystem::file_size("./multi_kernel.spv")), - spirvBuffer(spirvFileSize) + spirvBuffer(spirvFileSize), + nOpenCLGpuQ(DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU)) { spirvFile.seekg(0, std::ios::beg); spirvFile.read(spirvBuffer.data(), spirvFileSize); diff --git a/backends/tests/test_sycl_queue_manager.cpp b/backends/tests/test_sycl_queue_manager.cpp index 600c78e8e7..44be69d7fc 100644 --- a/backends/tests/test_sycl_queue_manager.cpp +++ b/backends/tests/test_sycl_queue_manager.cpp @@ -83,7 +83,7 @@ TEST_F (TestDPPLSyclQueueManager, CheckDPPLGetCurrentQueue) if(!has_devices()) GTEST_SKIP_("Skipping: No Sycl devices.\n"); - DPPLSyclQueueRef q; + DPPLSyclQueueRef q = nullptr; ASSERT_NO_THROW(q = DPPLQueueMgr_GetCurrentQueue()); ASSERT_TRUE(q != nullptr); } @@ -170,7 +170,6 @@ TEST_F (TestDPPLSyclQueueManager, CheckGetNumActivatedQueues) auto nOpenCLCpuQ = DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_CPU); auto nOpenCLGpuQ = DPPLQueueMgr_GetNumQueues(DPPL_OPENCL, DPPL_GPU); - auto nL0GpuQ = DPPLQueueMgr_GetNumQueues(DPPL_LEVEL_ZERO, DPPL_GPU); // Add a queue to main thread if(!nOpenCLCpuQ || !nOpenCLGpuQ) @@ -192,10 +191,10 @@ TEST_F (TestDPPLSyclQueueManager, CheckGetNumActivatedQueues) // Verify what the expected number of activated queues each time a thread // called getNumActivatedQueues. - EXPECT_EQ(num0, 1); - EXPECT_EQ(num1, 2); - EXPECT_EQ(num2, 1); - EXPECT_EQ(num4, 0); + EXPECT_EQ(num0, 1ul); + EXPECT_EQ(num1, 2ul); + EXPECT_EQ(num2, 1ul); + EXPECT_EQ(num4, 0ul); DPPLQueue_Delete(q); } diff --git a/backends/tests/test_sycl_usm_interface.cpp b/backends/tests/test_sycl_usm_interface.cpp index d07157029f..b28eb2ac75 100644 --- a/backends/tests/test_sycl_usm_interface.cpp +++ b/backends/tests/test_sycl_usm_interface.cpp @@ -75,7 +75,7 @@ common_test_body (size_t nbytes, const DPPLSyclUSMRef Ptr, DPPLDevice_Delete(Dev); DPPLContext_Delete(Ctx); } - + } // end of namespace struct TestDPPLSyclUSMInterface : public ::testing::Test @@ -94,7 +94,7 @@ TEST_F (TestDPPLSyclUSMInterface, MallocShared) GTEST_SKIP_("Skipping: No Sycl Devices.\n"); auto Q = DPPLQueueMgr_GetCurrentQueue(); - const size_t nbytes = 1024; + const size_t nbytes = SIZE; auto Ptr = DPPLmalloc_shared(nbytes, Q); EXPECT_TRUE(bool(Ptr)); @@ -110,12 +110,12 @@ TEST_F (TestDPPLSyclUSMInterface, MallocDevice) GTEST_SKIP_("Skipping: No Sycl Devices.\n"); auto Q = DPPLQueueMgr_GetCurrentQueue(); - const size_t nbytes = 1024; + const size_t nbytes = SIZE; auto Ptr = DPPLmalloc_device(nbytes, Q); EXPECT_TRUE(bool(Ptr)); - common_test_body(nbytes, Ptr, Q, "device"); + common_test_body(nbytes, Ptr, Q, "device"); DPPLfree_with_queue(Ptr, Q); DPPLQueue_Delete(Q); } @@ -126,7 +126,7 @@ TEST_F (TestDPPLSyclUSMInterface, MallocHost) GTEST_SKIP_("Skipping: No Sycl Devices.\n"); auto Q = DPPLQueueMgr_GetCurrentQueue(); - const size_t nbytes = 1024; + const size_t nbytes = SIZE; auto Ptr = DPPLmalloc_host(nbytes, Q); EXPECT_TRUE(bool(Ptr)); @@ -142,7 +142,7 @@ TEST_F (TestDPPLSyclUSMInterface, AlignedAllocShared) GTEST_SKIP_("Skipping: No Sycl Devices.\n"); auto Q = DPPLQueueMgr_GetCurrentQueue(); - const size_t nbytes = 1024; + const size_t nbytes = SIZE; auto Ptr = DPPLaligned_alloc_shared(64, nbytes, Q); EXPECT_TRUE(bool(Ptr)); @@ -158,7 +158,7 @@ TEST_F (TestDPPLSyclUSMInterface, AlignedAllocDevice) GTEST_SKIP_("Skipping: No Sycl Devices.\n"); auto Q = DPPLQueueMgr_GetCurrentQueue(); - const size_t nbytes = 1024; + const size_t nbytes = SIZE; auto Ptr = DPPLaligned_alloc_device(64, nbytes, Q); EXPECT_TRUE(bool(Ptr)); @@ -174,7 +174,7 @@ TEST_F (TestDPPLSyclUSMInterface, AlignedAllocHost) GTEST_SKIP_("Skipping: No Sycl Devices.\n"); auto Q = DPPLQueueMgr_GetCurrentQueue(); - const size_t nbytes = 1024; + const size_t nbytes = SIZE; auto Ptr = DPPLaligned_alloc_host(64, nbytes, Q); EXPECT_TRUE(bool(Ptr)); diff --git a/setup.py b/setup.py index 52d17cfc9c..ba9fbd0f21 100644 --- a/setup.py +++ b/setup.py @@ -88,6 +88,17 @@ def get_other_cxxflags(): return ["/Ox", "/std:c++17"] +def get_suppressed_warning_flags(): + if IS_LIN: + # PEP 590 renamed "tp_print" to "tp_vectorcall" and this causes a flood + # of deprecation warnings in the Cython generated module. This flag + # temporarily suppresses the warnings. The flag should not be needed + # once we move to Python 3.9 and/or Cython 0.30. + return ["-Wno-deprecated-declarations"] + elif IS_WIN: + return [] + + def extensions(): # Security flags eca = get_sdl_cflags() @@ -119,7 +130,9 @@ def extensions(): dppl_sycl_interface_include, ], "include_dirs": [np.get_include(), dppl_sycl_interface_include], - "extra_compile_args": eca + get_other_cxxflags(), + "extra_compile_args": eca + + get_other_cxxflags() + + get_suppressed_warning_flags(), "extra_link_args": ela, "libraries": libs, "library_dirs": librarys,