StarPU Internal Handbook
driver_opencl.h
Go to the documentation of this file.
1 /* StarPU --- Runtime system for heterogeneous multicore architectures.
2  *
3  * Copyright (C) 2010-2023 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
4  *
5  * StarPU is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation; either version 2.1 of the License, or (at
8  * your option) any later version.
9  *
10  * StarPU is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  *
14  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
15  */
16 
17 #ifndef __DRIVER_OPENCL_H__
18 #define __DRIVER_OPENCL_H__
19 
22 #ifndef _GNU_SOURCE
23 #define _GNU_SOURCE 1
24 #endif
25 
26 #ifdef STARPU_USE_OPENCL
27 
28 #define CL_TARGET_OPENCL_VERSION 100
29 #ifdef __APPLE__
30 #include <OpenCL/cl.h>
31 #else
32 #include <CL/cl.h>
33 #endif
34 #endif
35 
36 #include <core/workers.h>
37 #include <datawizard/node_ops.h>
38 
39 #pragma GCC visibility push(hidden)
40 
41 void _starpu_opencl_preinit(void);
42 
43 #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
45 void _starpu_opencl_discover_devices(struct _starpu_machine_config *config);
46 
47 void _starpu_opencl_init(void);
48 unsigned _starpu_opencl_get_device_count(void);
49 #ifdef STARPU_HAVE_HWLOC
51 hwloc_obj_t _starpu_opencl_get_hwloc_obj(hwloc_topology_t topology, int devid);
52 #endif
53 void _starpu_init_opencl_config(struct _starpu_machine_topology *topology, struct _starpu_machine_config *);
54 void _starpu_opencl_init_worker_binding(struct _starpu_machine_config *config, int no_mp_config STARPU_ATTRIBUTE_UNUSED, struct _starpu_worker *workerarg);
55 void _starpu_opencl_init_worker_memory(struct _starpu_machine_config *config, int no_mp_config STARPU_ATTRIBUTE_UNUSED, struct _starpu_worker *workerarg);
56 void *_starpu_opencl_worker(void *);
57 extern struct _starpu_node_ops _starpu_driver_opencl_node_ops;
58 #else
59 #define _starpu_opencl_discover_devices(config) ((void) (config))
60 #endif
61 
62 #if defined(STARPU_USE_OPENCL) || defined(STARPU_SIMGRID)
63 extern struct _starpu_driver_ops _starpu_driver_opencl_ops;
64 #endif
65 
66 #ifdef STARPU_USE_OPENCL
67 extern char *_starpu_opencl_program_dir;
68 
69 int _starpu_run_opencl(struct _starpu_worker *);
70 int _starpu_opencl_driver_init(struct _starpu_worker *);
71 int _starpu_opencl_driver_run_once(struct _starpu_worker *);
72 int _starpu_opencl_driver_deinit(struct _starpu_worker *);
73 
74 int _starpu_opencl_init_context(int devid);
75 int _starpu_opencl_deinit_context(int devid);
76 cl_device_type _starpu_opencl_get_device_type(int devid);
77 
78 uintptr_t _starpu_opencl_map_ram(uintptr_t src_ptr, size_t src_offset, unsigned src_node, unsigned dst_node, size_t size, int *ret);
79 int _starpu_opencl_unmap_ram(uintptr_t src_ptr, size_t src_offset, unsigned src_node, uintptr_t dst_ptr, unsigned dst_node, size_t size);
80 int _starpu_opencl_update_opencl_map(uintptr_t src, size_t src_offset, unsigned src_node, uintptr_t dst, size_t dst_offset, unsigned dst_node, size_t size);
81 int _starpu_opencl_update_cpu_map(uintptr_t src, size_t src_offset, unsigned src_node, uintptr_t dst, size_t dst_offset, unsigned dst_node, size_t size);
82 #endif
83 
84 #if 0
85 cl_int _starpu_opencl_copy_rect_opencl_to_ram(cl_mem buffer, unsigned src_node, void *ptr, unsigned dst_node, const size_t buffer_origin[3], const size_t host_origin[3],
86  const size_t region[3], size_t buffer_row_pitch, size_t buffer_slice_pitch,
87  size_t host_row_pitch, size_t host_slice_pitch, cl_event *event);
88 
89 cl_int _starpu_opencl_copy_rect_ram_to_opencl(void *ptr, unsigned src_node, cl_mem buffer, unsigned dst_node, const size_t buffer_origin[3], const size_t host_origin[3],
90  const size_t region[3], size_t buffer_row_pitch, size_t buffer_slice_pitch,
91  size_t host_row_pitch, size_t host_slice_pitch, cl_event *event);
92 #endif
93 
94 unsigned _starpu_opencl_test_request_completion(struct _starpu_async_channel *async_channel);
95 void _starpu_opencl_wait_request_completion(struct _starpu_async_channel *async_channel);
96 
97 int _starpu_opencl_copy_interface_from_opencl_to_opencl(starpu_data_handle_t handle, void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, struct _starpu_data_request *req);
98 int _starpu_opencl_copy_interface_from_opencl_to_cpu(starpu_data_handle_t handle, void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, struct _starpu_data_request *req);
99 int _starpu_opencl_copy_interface_from_cpu_to_opencl(starpu_data_handle_t handle, void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, struct _starpu_data_request *req);
100 
101 int _starpu_opencl_copy_data_from_opencl_to_cpu(uintptr_t src, size_t src_offset, unsigned src_node, uintptr_t dst, size_t dst_offset, unsigned dst_node, size_t size, struct _starpu_async_channel *async_channel);
102 int _starpu_opencl_copy_data_from_opencl_to_opencl(uintptr_t src, size_t src_offset, unsigned src_node, uintptr_t dst, size_t dst_offset, unsigned dst_node, size_t size, struct _starpu_async_channel *async_channel);
103 int _starpu_opencl_copy_data_from_cpu_to_opencl(uintptr_t src, size_t src_offset, unsigned src_node, uintptr_t dst, size_t dst_offset, unsigned dst_node, size_t size, struct _starpu_async_channel *async_channel);
104 
105 int _starpu_opencl_is_direct_access_supported(unsigned node, unsigned handling_node);
106 uintptr_t _starpu_opencl_malloc_on_node(unsigned dst_node, size_t size, int flags);
107 void _starpu_opencl_free_on_node(unsigned dst_node, uintptr_t addr, size_t size, int flags);
108 
109 #pragma GCC visibility pop
110 
111 #endif // __DRIVER_OPENCL_H__
Definition: copy_driver.h:71
Definition: drivers.h:26
Definition: workers.h:441
Definition: workers.h:352
int devid[STARPU_NARCH][STARPU_NMAXDEVS]
Definition: workers.h:404
Definition: node_ops.h:92
Definition: workers.h:155