Skip to content

Commit 1653a06

Browse files
committed
Suppress OpenCL-related deprecated declarations warns
Suppress deprecated declarations warnings (for MSVC, GCC and Clang) caused by deprecated OpenCL Runtime functions.
1 parent 112537a commit 1653a06

File tree

4 files changed

+191
-0
lines changed

4 files changed

+191
-0
lines changed

example/opencl_test.cpp

+65
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,62 @@
88
// See http://boostorg.github.com/compute for more information.
99
//---------------------------------------------------------------------------//
1010

11+
// See boost/compute/detail/diagnostic.hpp
12+
// GCC
13+
#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
14+
#define BOOST_COMPUTE_GCC_DIAG_STR(s) #s
15+
#define BOOST_COMPUTE_GCC_DIAG_JOINSTR(x,y) BOOST_COMPUTE_GCC_DIAG_STR(x ## y)
16+
# define BOOST_COMPUTE_GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
17+
# define BOOST_COMPUTE_GCC_DIAG_PRAGMA(x) BOOST_COMPUTE_GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
18+
# if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
19+
# define BOOST_COMPUTE_GCC_DIAG_OFF(x) BOOST_COMPUTE_GCC_DIAG_PRAGMA(push) \
20+
BOOST_COMPUTE_GCC_DIAG_PRAGMA(ignored BOOST_COMPUTE_GCC_DIAG_JOINSTR(-W,x))
21+
# define BOOST_COMPUTE_GCC_DIAG_ON(x) BOOST_COMPUTE_GCC_DIAG_PRAGMA(pop)
22+
# else
23+
# define BOOST_COMPUTE_GCC_DIAG_OFF(x) \
24+
BOOST_COMPUTE_GCC_DIAG_PRAGMA(ignored BOOST_COMPUTE_GCC_DIAG_JOINSTR(-W,x))
25+
# define BOOST_COMPUTE_GCC_DIAG_ON(x) \
26+
BOOST_COMPUTE_GCC_DIAG_PRAGMA(warning BOOST_COMPUTE_GCC_DIAG_JOINSTR(-W,x))
27+
# endif
28+
#else // Ensure these macros do nothing for other compilers.
29+
# define BOOST_COMPUTE_GCC_DIAG_OFF(x)
30+
# define BOOST_COMPUTE_GCC_DIAG_ON(x)
31+
#endif
32+
33+
// Clang
34+
#ifdef __clang__
35+
# define BOOST_COMPUTE_CLANG_DIAG_STR(s) # s
36+
// stringize s to "no-sign-compare"
37+
# define BOOST_COMPUTE_CLANG_DIAG_JOINSTR(x,y) BOOST_COMPUTE_CLANG_DIAG_STR(x ## y)
38+
// join -W with no-unused-variable to "-Wno-sign-compare"
39+
# define BOOST_COMPUTE_CLANG_DIAG_DO_PRAGMA(x) _Pragma (#x)
40+
// _Pragma is unary operator #pragma ("")
41+
# define BOOST_COMPUTE_CLANG_DIAG_PRAGMA(x) \
42+
BOOST_COMPUTE_CLANG_DIAG_DO_PRAGMA(clang diagnostic x)
43+
# define BOOST_COMPUTE_CLANG_DIAG_OFF(x) BOOST_COMPUTE_CLANG_DIAG_PRAGMA(push) \
44+
BOOST_COMPUTE_CLANG_DIAG_PRAGMA(ignored BOOST_COMPUTE_CLANG_DIAG_JOINSTR(-W,x))
45+
// For example: #pragma clang diagnostic ignored "-Wno-sign-compare"
46+
# define BOOST_COMPUTE_CLANG_DIAG_ON(x) BOOST_COMPUTE_CLANG_DIAG_PRAGMA(pop)
47+
// For example: #pragma clang diagnostic warning "-Wno-sign-compare"
48+
#else // Ensure these macros do nothing for other compilers.
49+
# define BOOST_COMPUTE_CLANG_DIAG_OFF(x)
50+
# define BOOST_COMPUTE_CLANG_DIAG_ON(x)
51+
# define BOOST_COMPUTE_CLANG_DIAG_PRAGMA(x)
52+
#endif
53+
54+
// MSVC
55+
#if defined(_MSC_VER)
56+
# define BOOST_COMPUTE_MSVC_DIAG_DO_PRAGMA(x) __pragma(x)
57+
# define BOOST_COMPUTE_MSVC_DIAG_PRAGMA(x) \
58+
BOOST_COMPUTE_MSVC_DIAG_DO_PRAGMA(warning(x))
59+
# define BOOST_COMPUTE_MSVC_DIAG_OFF(x) BOOST_COMPUTE_MSVC_DIAG_PRAGMA(push) \
60+
BOOST_COMPUTE_MSVC_DIAG_PRAGMA(disable: x)
61+
# define BOOST_COMPUTE_MSVC_DIAG_ON(x) BOOST_COMPUTE_MSVC_DIAG_PRAGMA(pop)
62+
#else // Ensure these macros do nothing for other compilers.
63+
# define BOOST_COMPUTE_MSVC_DIAG_OFF(x)
64+
# define BOOST_COMPUTE_MSVC_DIAG_ON(x)
65+
#endif
66+
1167
#include <iostream>
1268

1369
// include the proper opencl header for the system
@@ -24,6 +80,11 @@
2480
// the boost.compute apis (which depend on a working opencl implementation).
2581
int main()
2682
{
83+
// Suppress deprecated declarations warning
84+
BOOST_COMPUTE_MSVC_DIAG_OFF(4996); // MSVC
85+
BOOST_COMPUTE_GCC_DIAG_OFF(deprecated-declarations); // GCC
86+
BOOST_COMPUTE_CLANG_DIAG_OFF(deprecated-declarations); // Clang
87+
2788
// query number of opencl platforms
2889
cl_uint num_platforms = 0;
2990
cl_int ret = clGetPlatformIDs(0, NULL, &num_platforms);
@@ -96,5 +157,9 @@ int main()
96157
}
97158
delete[] platforms;
98159

160+
BOOST_COMPUTE_CLANG_DIAG_ON(deprecated-declarations); // Clang
161+
BOOST_COMPUTE_GCC_DIAG_ON(deprecated-declarations); // GCC
162+
BOOST_COMPUTE_MSVC_DIAG_OFF(4996); // MSVC
163+
99164
return 0;
100165
}

include/boost/compute/command_queue.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <boost/compute/utility/wait_list.hpp>
3131
#include <boost/compute/detail/get_object_info.hpp>
3232
#include <boost/compute/detail/assert_cl_success.hpp>
33+
#include <boost/compute/detail/diagnostic.hpp>
3334
#include <boost/compute/utility/extents.hpp>
3435

3536
namespace boost {
@@ -135,9 +136,12 @@ class command_queue
135136
} else
136137
#endif
137138
{
139+
// Suppress deprecated declarations warning
140+
BOOST_COMPUTE_DISABLE_DEPRECATED_DECLARATIONS();
138141
m_queue = clCreateCommandQueue(
139142
context, device.id(), properties, &error
140143
);
144+
BOOST_COMPUTE_ENABLE_DEPRECATED_DECLARATIONS();
141145
}
142146

143147
if(!m_queue){
@@ -1532,7 +1536,10 @@ class command_queue
15321536
} else
15331537
#endif // CL_VERSION_1_2
15341538
{
1539+
// Suppress deprecated declarations warning
1540+
BOOST_COMPUTE_DISABLE_DEPRECATED_DECLARATIONS();
15351541
ret = clEnqueueBarrier(m_queue);
1542+
BOOST_COMPUTE_ENABLE_DEPRECATED_DECLARATIONS();
15361543
}
15371544

15381545
if(ret != CL_SUCCESS){
@@ -1576,7 +1583,10 @@ class command_queue
15761583
} else
15771584
#endif
15781585
{
1586+
// Suppress deprecated declarations warning
1587+
BOOST_COMPUTE_DISABLE_DEPRECATED_DECLARATIONS();
15791588
ret = clEnqueueMarker(m_queue, &event_.get());
1589+
BOOST_COMPUTE_ENABLE_DEPRECATED_DECLARATIONS();
15801590
}
15811591

15821592
if(ret != CL_SUCCESS){
+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//---------------------------------------------------------------------------//
2+
// Copyright (c) 2016 Jakub Szuppe <[email protected]>
3+
//
4+
// Distributed under the Boost Software License, Version 1.0
5+
// See accompanying file LICENSE_1_0.txt or copy at
6+
// http://www.boost.org/LICENSE_1_0.txt
7+
//
8+
// See http://boostorg.github.com/compute for more information.
9+
//---------------------------------------------------------------------------//
10+
11+
#ifndef BOOST_COMPUTE_DETAIL_DIAGNOSTIC_HPP
12+
#define BOOST_COMPUTE_DETAIL_DIAGNOSTIC_HPP
13+
14+
// Macros for suppressing warnings for GCC version 4.6 or later. Usage:
15+
//
16+
// BOOST_COMPUTE_BOOST_COMPUTE_GCC_DIAG_OFF(sign-compare);
17+
// if(a < b){
18+
// BOOST_COMPUTE_BOOST_COMPUTE_GCC_DIAG_ON(sign-compare);
19+
//
20+
// Source: https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines
21+
#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
22+
#define BOOST_COMPUTE_GCC_DIAG_STR(s) #s
23+
#define BOOST_COMPUTE_GCC_DIAG_JOINSTR(x,y) BOOST_COMPUTE_GCC_DIAG_STR(x ## y)
24+
# define BOOST_COMPUTE_GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
25+
# define BOOST_COMPUTE_GCC_DIAG_PRAGMA(x) BOOST_COMPUTE_GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
26+
# if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
27+
# define BOOST_COMPUTE_GCC_DIAG_OFF(x) BOOST_COMPUTE_GCC_DIAG_PRAGMA(push) \
28+
BOOST_COMPUTE_GCC_DIAG_PRAGMA(ignored BOOST_COMPUTE_GCC_DIAG_JOINSTR(-W,x))
29+
# define BOOST_COMPUTE_GCC_DIAG_ON(x) BOOST_COMPUTE_GCC_DIAG_PRAGMA(pop)
30+
# else
31+
# define BOOST_COMPUTE_GCC_DIAG_OFF(x) \
32+
BOOST_COMPUTE_GCC_DIAG_PRAGMA(ignored BOOST_COMPUTE_GCC_DIAG_JOINSTR(-W,x))
33+
# define BOOST_COMPUTE_GCC_DIAG_ON(x) \
34+
BOOST_COMPUTE_GCC_DIAG_PRAGMA(warning BOOST_COMPUTE_GCC_DIAG_JOINSTR(-W,x))
35+
# endif
36+
#else // Ensure these macros do nothing for other compilers.
37+
# define BOOST_COMPUTE_GCC_DIAG_OFF(x)
38+
# define BOOST_COMPUTE_GCC_DIAG_ON(x)
39+
#endif
40+
41+
// Macros for suppressing warnings for Clang.
42+
//
43+
// BOOST_COMPUTE_BOOST_COMPUTE_CLANG_DIAG_OFF(sign-compare);
44+
// if(a < b){
45+
// BOOST_COMPUTE_BOOST_COMPUTE_CLANG_DIAG_ON(sign-compare);
46+
//
47+
// Source: https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines
48+
#ifdef __clang__
49+
# define BOOST_COMPUTE_CLANG_DIAG_STR(s) # s
50+
// stringize s to "no-sign-compare"
51+
# define BOOST_COMPUTE_CLANG_DIAG_JOINSTR(x,y) BOOST_COMPUTE_CLANG_DIAG_STR(x ## y)
52+
// join -W with no-unused-variable to "-Wno-sign-compare"
53+
# define BOOST_COMPUTE_CLANG_DIAG_DO_PRAGMA(x) _Pragma (#x)
54+
// _Pragma is unary operator #pragma ("")
55+
# define BOOST_COMPUTE_CLANG_DIAG_PRAGMA(x) \
56+
BOOST_COMPUTE_CLANG_DIAG_DO_PRAGMA(clang diagnostic x)
57+
# define BOOST_COMPUTE_CLANG_DIAG_OFF(x) BOOST_COMPUTE_CLANG_DIAG_PRAGMA(push) \
58+
BOOST_COMPUTE_CLANG_DIAG_PRAGMA(ignored BOOST_COMPUTE_CLANG_DIAG_JOINSTR(-W,x))
59+
// For example: #pragma clang diagnostic ignored "-Wno-sign-compare"
60+
# define BOOST_COMPUTE_CLANG_DIAG_ON(x) BOOST_COMPUTE_CLANG_DIAG_PRAGMA(pop)
61+
// For example: #pragma clang diagnostic warning "-Wno-sign-compare"
62+
#else // Ensure these macros do nothing for other compilers.
63+
# define BOOST_COMPUTE_CLANG_DIAG_OFF(x)
64+
# define BOOST_COMPUTE_CLANG_DIAG_ON(x)
65+
# define BOOST_COMPUTE_CLANG_DIAG_PRAGMA(x)
66+
#endif
67+
68+
// Macros for suppressing warnings for MSVC. Usage:
69+
//
70+
// BOOST_COMPUTE_BOOST_COMPUTE_MSVC_DIAG_OFF(4018); //sign-compare
71+
// if(a < b){
72+
// BOOST_COMPUTE_BOOST_COMPUTE_MSVC_DIAG_ON(4018);
73+
//
74+
#if defined(_MSC_VER)
75+
# define BOOST_COMPUTE_MSVC_DIAG_DO_PRAGMA(x) __pragma(x)
76+
# define BOOST_COMPUTE_MSVC_DIAG_PRAGMA(x) \
77+
BOOST_COMPUTE_MSVC_DIAG_DO_PRAGMA(warning(x))
78+
# define BOOST_COMPUTE_MSVC_DIAG_OFF(x) BOOST_COMPUTE_MSVC_DIAG_PRAGMA(push) \
79+
BOOST_COMPUTE_MSVC_DIAG_PRAGMA(disable: x)
80+
# define BOOST_COMPUTE_MSVC_DIAG_ON(x) BOOST_COMPUTE_MSVC_DIAG_PRAGMA(pop)
81+
#else // Ensure these macros do nothing for other compilers.
82+
# define BOOST_COMPUTE_MSVC_DIAG_OFF(x)
83+
# define BOOST_COMPUTE_MSVC_DIAG_ON(x)
84+
#endif
85+
86+
// Macros for suppressing warnings for GCC, Clang and MSVC. Usage:
87+
//
88+
// BOOST_COMPUTE_DIAG_OFF(sign-compare, sign-compare, 4018);
89+
// if(a < b){
90+
// BOOST_COMPUTE_DIAG_ON(sign-compare, sign-compare, 4018);
91+
//
92+
#if defined(_MSC_VER) // MSVC
93+
# define BOOST_COMPUTE_DIAG_OFF(gcc, clang, msvc) BOOST_COMPUTE_MSVC_DIAG_OFF(msvc)
94+
# define BOOST_COMPUTE_DIAG_ON(gcc, clang, msvc) BOOST_COMPUTE_MSVC_DIAG_ON(msvc)
95+
#elif defined(__clang__) // Clang
96+
# define BOOST_COMPUTE_DIAG_OFF(gcc, clang, msvc) BOOST_COMPUTE_CLANG_DIAG_OFF(clang)
97+
# define BOOST_COMPUTE_DIAG_ON(gcc, clang, msvc) BOOST_COMPUTE_CLANG_DIAG_ON(clang)
98+
#elif defined(__GNUC__) // GCC/G++
99+
# define BOOST_COMPUTE_DIAG_OFF(gcc, clang, msvc) BOOST_COMPUTE_GCC_DIAG_OFF(gcc)
100+
# define BOOST_COMPUTE_DIAG_ON(gcc, clang, msvc) BOOST_COMPUTE_GCC_DIAG_ON(gcc)
101+
#else // Ensure these macros do nothing for other compilers.
102+
# define BOOST_COMPUTE_DIAG_OFF(gcc, clang, msvc)
103+
# define BOOST_COMPUTE_DIAG_ON(gcc, clang, msvc)
104+
#endif
105+
106+
#define BOOST_COMPUTE_DISABLE_DEPRECATED_DECLARATIONS() \
107+
BOOST_COMPUTE_DIAG_OFF(deprecated-declarations, deprecated-declarations, 4996)
108+
#define BOOST_COMPUTE_ENABLE_DEPRECATED_DECLARATIONS() \
109+
BOOST_COMPUTE_DIAG_ON(deprecated-declarations, deprecated-declarations, 4996);
110+
111+
112+
#endif /* BOOST_COMPUTE_DETAIL_DIAGNOSTIC_HPP */

test/test_command_queue.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <boost/compute/container/vector.hpp>
2222
#include <boost/compute/utility/dim.hpp>
2323
#include <boost/compute/utility/source.hpp>
24+
#include <boost/compute/detail/diagnostic.hpp>
2425

2526
#include "check_macros.hpp"
2627
#include "context_setup.hpp"
@@ -145,8 +146,11 @@ BOOST_AUTO_TEST_CASE(construct_from_cl_command_queue)
145146
} else
146147
#endif // CL_VERSION_2_0
147148
{
149+
// Suppress deprecated declarations warning
150+
BOOST_COMPUTE_DISABLE_DEPRECATED_DECLARATIONS();
148151
cl_queue =
149152
clCreateCommandQueue(context, device.id(), 0, 0);
153+
BOOST_COMPUTE_ENABLE_DEPRECATED_DECLARATIONS();
150154
}
151155
BOOST_VERIFY(cl_queue);
152156

0 commit comments

Comments
 (0)