Skip to content

Commit 9af7e79

Browse files
committed
dbk: fix circular dependency
1 parent 93c5b5c commit 9af7e79

File tree

9 files changed

+101
-29
lines changed

9 files changed

+101
-29
lines changed

lib/CL/devices/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ if(ENABLE_HOST_CPU_DEVICES)
202202
endif()
203203
endif()
204204
add_subdirectory(cpu_dbk)
205-
list(APPEND POCL_DEVICES_SOURCES common_utils.h common_utils.c)
205+
list(APPEND POCL_DEVICES_SOURCES common_utils.h common_utils.c dbk_utils.h
206+
dbk_utils.c)
206207
endif()
207208

208209
if(ENABLE_SIGNAL_HANDLERS)
@@ -224,7 +225,9 @@ if(HAVE_ONNXRT)
224225
endif ()
225226
if(HAVE_OPENCV)
226227
add_dependencies("pocl-devices" pocl_dbk_khr_dnn_utils)
227-
target_link_libraries("pocl-devices" PRIVATE $<TARGET_OBJECTS:pocl_dbk_khr_dnn_utils> opencv_dnn)
228+
target_link_libraries("pocl-devices" PRIVATE
229+
$<TARGET_OBJECTS:pocl_dbk_khr_dnn_utils>
230+
opencv_dnn)
228231
endif ()
229232

230233
set(POCL_DEVICES_OBJS "${POCL_DEVICES_OBJS}"

lib/CL/devices/common_utils.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "common.h"
2929
#include "common_utils.h"
3030
#include "cpuinfo.h"
31+
#include "dbk_utils.h"
3132
#include "pocl_builtin_kernels.h"
3233
#ifdef ENABLE_LLVM
3334
#include "pocl_llvm.h"
@@ -891,27 +892,6 @@ pocl_cpu_build_defined_builtin (cl_program program, cl_uint device_i)
891892
"The CPU driver has not been compiled with support for DBKs\n");
892893
}
893894

894-
/**
895-
* Get the device memory pointer of the supplied pocl argument.
896-
*
897-
* \param global_mem_id [in] This is needed to get the device specific pointer.
898-
* \return NULL if arg->value is NULL and otherwise the requested pointer.
899-
*/
900-
void *
901-
pocl_cpu_get_ptr (struct pocl_argument *arg, unsigned global_mem_id)
902-
{
903-
if (arg->value == NULL)
904-
return NULL;
905-
906-
if (arg->is_raw_ptr)
907-
return *(void **)arg->value;
908-
909-
cl_mem mem = *(cl_mem *)(arg->value);
910-
char *ptr = (char *)(mem->device_ptrs[global_mem_id].mem_ptr);
911-
ptr += arg->offset;
912-
return (void *)ptr;
913-
}
914-
915895
#ifdef HAVE_LIBXSMM
916896

917897
static cl_bool

lib/CL/devices/common_utils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ POCL_EXPORT
128128
void pocl_free_kernel_arg_array_with_locals (void **arguments, void **arguments2,
129129
kernel_run_command *k);
130130

131-
void *pocl_cpu_get_ptr (struct pocl_argument *arg, unsigned global_mem_id);
132-
133131
POCL_EXPORT
134132
void pocl_cpu_save_rm_and_ftz (unsigned *rm, unsigned *ftz);
135133

lib/CL/devices/cpu_dbk/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ if(HAVE_OPENCV)
1919
add_library(pocl_dbk_khr_dnn_utils OBJECT
2020
pocl_dbk_khr_dnn_utils.cpp
2121
pocl_dbk_khr_dnn_utils.hh)
22-
target_link_libraries(pocl_dbk_khr_dnn_utils PRIVATE opencv_dnn)
22+
23+
add_library(dbk_utils STATIC
24+
../dbk_utils.h ../dbk_utils.c
25+
)
26+
target_link_libraries(pocl_dbk_khr_dnn_utils PRIVATE opencv_dnn dbk_utils)
2327

2428
list(APPEND POCL_DEVICES_LINK_LIST pocl_dbk_khr_dnn_utils)
2529

lib/CL/devices/cpu_dbk/pocl_dbk_khr_dnn_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
#include "pocl_dbk_khr_dnn_utils.hh"
25-
#include "common_utils.h"
25+
#include "dbk_utils.h"
2626
#include <opencv2/dnn.hpp>
2727
#include <string>
2828

lib/CL/devices/cpu_dbk/pocl_dbk_khr_img_cpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
#include "pocl_dbk_khr_img_cpu.h"
25-
#include "common_utils.h"
25+
#include "dbk_utils.h"
2626

2727
int
2828
pocl_cpu_execute_dbk_exp_img_yuv2rgb (cl_program program,

lib/CL/devices/cpu_dbk/pocl_dbk_khr_jpeg_cpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
#include "pocl_dbk_khr_jpeg_cpu.h"
26-
#include "common_utils.h"
26+
#include "dbk_utils.h"
2727

2828
#ifdef HAVE_LIBJPEG_TURBO
2929

lib/CL/devices/dbk_utils.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* dbk_utils.c - utils used by DBKs
2+
3+
Copyright (c) 2024 Robin Bijl / Tampere University
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to
7+
deal in the Software without restriction, including without limitation the
8+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9+
sell copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21+
IN THE SOFTWARE.
22+
*/
23+
24+
#include "dbk_utils.h"
25+
26+
/**
27+
* Get the device memory pointer of the supplied pocl argument.
28+
*
29+
* \param global_mem_id [in] This is needed to get the device specific pointer.
30+
* \return NULL if arg->value is NULL and otherwise the requested pointer.
31+
*/
32+
void *
33+
pocl_cpu_get_ptr (struct pocl_argument *arg, unsigned global_mem_id)
34+
{
35+
if (arg->value == NULL)
36+
return NULL;
37+
38+
if (arg->is_raw_ptr)
39+
return *(void **)arg->value;
40+
41+
cl_mem mem = *(cl_mem *)(arg->value);
42+
char *ptr = (char *)(mem->device_ptrs[global_mem_id].mem_ptr);
43+
ptr += arg->offset;
44+
return (void *)ptr;
45+
}

lib/CL/devices/dbk_utils.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* dbk_utils.h - utils used by DBKs
2+
3+
Copyright (c) 2024 Robin Bijl / Tampere University
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to
7+
deal in the Software without restriction, including without limitation the
8+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9+
sell copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21+
IN THE SOFTWARE.
22+
*/
23+
24+
#ifndef POCL_LIB_CL_DEVICES_DBK_UTILS_H
25+
#define POCL_LIB_CL_DEVICES_DBK_UTILS_H
26+
27+
#include "pocl_cl.h"
28+
29+
#ifdef __cplusplus
30+
extern "C"
31+
{
32+
#endif
33+
34+
POCL_EXPORT
35+
void *
36+
pocl_cpu_get_ptr(struct pocl_argument *arg, unsigned global_mem_id);
37+
38+
#endif //POCL_LIB_CL_DEVICES_DBK_UTILS_H
39+
40+
#ifdef __cplusplus
41+
}
42+
#endif

0 commit comments

Comments
 (0)