Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
2a44eee1
Commit
2a44eee1
authored
Jan 15, 2015
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move OpenCL error handling to specific header
parent
88ccfff7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
60 deletions
+131
-60
libcaf_opencl/CMakeLists.txt
libcaf_opencl/CMakeLists.txt
+3
-1
libcaf_opencl/caf/opencl/opencl_err.hpp
libcaf_opencl/caf/opencl/opencl_err.hpp
+80
-0
libcaf_opencl/src/opencl_err.cpp
libcaf_opencl/src/opencl_err.cpp
+43
-0
libcaf_opencl/src/opencl_metainfo.cpp
libcaf_opencl/src/opencl_metainfo.cpp
+5
-59
No files found.
libcaf_opencl/CMakeLists.txt
View file @
2a44eee1
...
...
@@ -10,7 +10,9 @@ if (OPENCL_LIBRARIES)
set
(
LIBCAF_OPENCL_SRCS
src/global.cpp
src/opencl_metainfo.cpp
src/program.cpp
)
src/program.cpp
src/opencl_err.cpp
)
# build shared library if not compiling static only
if
(
NOT
"
${
CAF_BUILD_STATIC_ONLY
}
"
STREQUAL
"yes"
)
add_library
(
libcaf_opencl SHARED
${
LIBCAF_OPENCL_SRCS
}
...
...
libcaf_opencl/caf/opencl/opencl_err.hpp
0 → 100644
View file @
2a44eee1
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* Raphael Hiesgen <raphael.hiesgen (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_OPENCL_OPENCL_ERR_HPP
#define CAF_OPENCL_OPENCL_ERR_HPP
#include "caf/opencl/global.hpp"
#include "caf/detail/logging.hpp"
#define CAF_CLF(funname) #funname , funname
namespace
caf
{
namespace
opencl
{
void
throwcl
(
const
char
*
fname
,
cl_int
err
);
void
pfn_notify
(
const
char
*
errinfo
,
const
void
*
,
size_t
,
void
*
);
// call convention for simply calling a function
template
<
class
F
,
class
...
Ts
>
void
v1callcl
(
const
char
*
fname
,
F
f
,
Ts
&&
...
vs
)
{
throwcl
(
fname
,
f
(
std
::
forward
<
Ts
>
(
vs
)...));
}
// call convention for simply calling a function, not using the last argument
template
<
class
F
,
class
...
Ts
>
void
v2callcl
(
const
char
*
fname
,
F
f
,
Ts
&&
...
vs
)
{
throwcl
(
fname
,
f
(
std
::
forward
<
Ts
>
(
vs
)...,
nullptr
));
}
// call convention with `result` argument at the end returning `err`, not
// using the second last argument (set to nullptr) nor the one before (set to 0)
template
<
class
R
,
class
F
,
class
...
Ts
>
R
v1get
(
const
char
*
fname
,
F
f
,
Ts
&&
...
vs
)
{
R
result
;
throwcl
(
fname
,
f
(
std
::
forward
<
Ts
>
(
vs
)...,
cl_uint
{
0
},
nullptr
,
&
result
));
return
result
;
}
// call convention with `err` argument at the end returning `result`
template
<
class
F
,
class
...
Ts
>
auto
v2get
(
const
char
*
fname
,
F
f
,
Ts
&&
...
vs
)
->
decltype
(
f
(
std
::
forward
<
Ts
>
(
vs
)...,
nullptr
))
{
cl_int
err
;
auto
result
=
f
(
std
::
forward
<
Ts
>
(
vs
)...,
&
err
);
throwcl
(
fname
,
err
);
return
result
;
}
// call convention with `result` argument at second last position (preceeded by
// its size) followed by an ingored void* argument (nullptr) returning `err`
template
<
class
R
,
class
F
,
class
...
Ts
>
R
v3get
(
const
char
*
fname
,
F
f
,
Ts
&&
...
vs
)
{
R
result
;
throwcl
(
fname
,
f
(
std
::
forward
<
Ts
>
(
vs
)...,
sizeof
(
R
),
&
result
,
nullptr
));
return
result
;
}
}
// namespace opencl
}
// namespace caf
#endif // CAF_OPENCL_OPENCL_ERR_HPP
libcaf_opencl/src/opencl_err.cpp
0 → 100644
View file @
2a44eee1
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* Raphael Hiesgen <raphael.hiesgen (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/opencl/opencl_err.hpp"
namespace
caf
{
namespace
opencl
{
void
throwcl
(
const
char
*
fname
,
cl_int
err
)
{
if
(
err
!=
CL_SUCCESS
)
{
std
::
string
errstr
=
fname
;
errstr
+=
": "
;
errstr
+=
get_opencl_error
(
err
);
throw
std
::
runtime_error
(
std
::
move
(
errstr
));
}
}
void
pfn_notify
(
const
char
*
errinfo
,
const
void
*
,
size_t
,
void
*
)
{
CAF_LOGC_ERROR
(
"caf::opencl::opencl_metainfo"
,
"initialize"
,
"
\n
##### Error message via pfn_notify #####
\n
"
<<
errinfo
<<
"
\n
########################################"
);
}
}
// namespace opencl
}
// namespace caf
libcaf_opencl/src/opencl_metainfo.cpp
View file @
2a44eee1
...
...
@@ -7,6 +7,7 @@
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* Raphael Hiesgen <raphael.hiesgen (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
...
...
@@ -17,67 +18,12 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/opencl/opencl_err.hpp"
#include "caf/opencl/opencl_metainfo.hpp"
#define CAF_CLF(funname) #funname , funname
namespace
caf
{
namespace
opencl
{
namespace
{
void
throwcl
(
const
char
*
fname
,
cl_int
err
)
{
if
(
err
!=
CL_SUCCESS
)
{
std
::
string
errstr
=
fname
;
errstr
+=
": "
;
errstr
+=
get_opencl_error
(
err
);
throw
std
::
runtime_error
(
std
::
move
(
errstr
));
}
}
// call convention for simply calling a function, not using the last argument
template
<
class
F
,
class
...
Ts
>
void
callcl
(
const
char
*
fname
,
F
f
,
Ts
&&
...
vs
)
{
throwcl
(
fname
,
f
(
std
::
forward
<
Ts
>
(
vs
)...,
nullptr
));
}
// call convention with `result` argument at the end returning `err`, not
// using the second last argument (set to nullptr) nor the one before (set to 0)
template
<
class
R
,
class
F
,
class
...
Ts
>
R
v1get
(
const
char
*
fname
,
F
f
,
Ts
&&
...
vs
)
{
R
result
;
throwcl
(
fname
,
f
(
std
::
forward
<
Ts
>
(
vs
)...,
cl_uint
{
0
},
nullptr
,
&
result
));
return
result
;
}
// call convention with `err` argument at the end returning `result`
template
<
class
F
,
class
...
Ts
>
auto
v2get
(
const
char
*
fname
,
F
f
,
Ts
&&
...
vs
)
->
decltype
(
f
(
std
::
forward
<
Ts
>
(
vs
)...,
nullptr
))
{
cl_int
err
;
auto
result
=
f
(
std
::
forward
<
Ts
>
(
vs
)...,
&
err
);
throwcl
(
fname
,
err
);
return
result
;
}
// call convention with `result` argument at second last position (preceeded by
// its size) followed by an ingored void* argument (nullptr) returning `err`
template
<
class
R
,
class
F
,
class
...
Ts
>
R
v3get
(
const
char
*
fname
,
F
f
,
Ts
&&
...
vs
)
{
R
result
;
throwcl
(
fname
,
f
(
std
::
forward
<
Ts
>
(
vs
)...,
sizeof
(
R
),
&
result
,
nullptr
));
return
result
;
}
void
pfn_notify
(
const
char
*
errinfo
,
const
void
*
,
size_t
,
void
*
)
{
CAF_LOGC_ERROR
(
"caf::opencl::opencl_metainfo"
,
"initialize"
,
"
\n
##### Error message via pfn_notify #####
\n
"
<<
errinfo
<<
"
\n
########################################"
);
}
}
// namespace <anonymous>
opencl_metainfo
*
opencl_metainfo
::
instance
()
{
auto
sid
=
detail
::
singletons
::
opencl_plugin_id
;
auto
fac
=
[]
{
return
new
opencl_metainfo
;
};
...
...
@@ -94,7 +40,7 @@ void opencl_metainfo::initialize() {
auto
num_platforms
=
v1get
<
cl_uint
>
(
CAF_CLF
(
clGetPlatformIDs
));
// get platform ids
std
::
vector
<
cl_platform_id
>
platforms
(
num_platforms
);
callcl
(
CAF_CLF
(
clGetPlatformIDs
),
num_platforms
,
platforms
.
data
());
v2
callcl
(
CAF_CLF
(
clGetPlatformIDs
),
num_platforms
,
platforms
.
data
());
if
(
platforms
.
empty
())
{
throw
std
::
runtime_error
(
"no OpenCL platform found"
);
}
...
...
@@ -113,7 +59,7 @@ void opencl_metainfo::initialize() {
}
// get available devices
std
::
vector
<
cl_device_id
>
ds
(
num_devs
);
callcl
(
CAF_CLF
(
clGetDeviceIDs
),
platform
,
dev_type
,
num_devs
,
ds
.
data
());
v2
callcl
(
CAF_CLF
(
clGetDeviceIDs
),
platform
,
dev_type
,
num_devs
,
ds
.
data
());
std
::
vector
<
device_ptr
>
devices
(
num_devs
);
// lift raw pointer as returned by OpenCL to C++ smart pointers
auto
lift
=
[](
cl_device_id
ptr
)
{
return
device_ptr
{
ptr
,
false
};
};
...
...
@@ -138,7 +84,7 @@ void opencl_metainfo::initialize() {
auto
max_wid
=
v3get
<
cl_uint
>
(
CAF_CLF
(
clGetDeviceInfo
),
device
.
get
(),
static_cast
<
unsigned
>
(
CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
));
dim_vec
max_wi_per_dim
(
max_wid
);
callcl
(
CAF_CLF
(
clGetDeviceInfo
),
device
.
get
(),
v2
callcl
(
CAF_CLF
(
clGetDeviceInfo
),
device
.
get
(),
static_cast
<
unsigned
>
(
CL_DEVICE_MAX_WORK_ITEM_SIZES
),
sizeof
(
size_t
)
*
max_wid
,
max_wi_per_dim
.
data
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment