Blender V4.3
oneapi/device_impl.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021-2022 Intel Corporation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifdef WITH_ONEAPI
6# include "device/device.h"
8# include "device/oneapi/queue.h"
10
11# include "util/map.h"
12
14
15class DeviceQueue;
16
17typedef void (*OneAPIDeviceIteratorCallback)(const char *id,
18 const char *name,
19 int num,
20 bool hwrt_support,
21 bool oidn_support,
22 void *user_ptr);
23
24class OneapiDevice : public GPUDevice {
25 private:
26 SyclQueue *device_queue_;
27# ifdef WITH_EMBREE_GPU
28 RTCDevice embree_device;
29 RTCScene embree_scene;
30# if RTC_VERSION >= 40302
31 thread_mutex scene_data_mutex;
32 vector<RTCScene> all_embree_scenes;
33# endif
34# endif
35 using ConstMemMap = map<string, device_vector<uchar> *>;
36 ConstMemMap const_mem_map_;
37 void *kg_memory_;
38 void *kg_memory_device_;
39 size_t kg_memory_size_ = (size_t)0;
40 size_t max_memory_on_device_ = (size_t)0;
41 std::string oneapi_error_string_;
42 bool use_hardware_raytracing = false;
43 unsigned int kernel_features = 0;
44 int scene_max_shaders_ = 0;
45
46 size_t get_free_mem() const;
47
48 public:
49 virtual BVHLayoutMask get_bvh_layout_mask(uint kernel_features) const override;
50
51 OneapiDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler, bool headless);
52
53 virtual ~OneapiDevice();
54# ifdef WITH_EMBREE_GPU
55 void build_bvh(BVH *bvh, Progress &progress, bool refit) override;
56# endif
57 bool check_peer_access(Device *peer_device) override;
58
59 bool load_kernels(const uint kernel_features) override;
60
61 void reserve_private_memory(const uint kernel_features);
62
63 virtual void get_device_memory_info(size_t &total, size_t &free) override;
64 virtual bool alloc_device(void *&device_pointer, size_t size) override;
65 virtual void free_device(void *device_pointer) override;
66 virtual bool alloc_host(void *&shared_pointer, size_t size) override;
67 virtual void free_host(void *shared_pointer) override;
68 virtual void transform_host_pointer(void *&device_pointer, void *&shared_pointer) override;
69 virtual void copy_host_to_device(void *device_pointer, void *host_pointer, size_t size) override;
70
71 string oneapi_error_message();
72
73 int scene_max_shaders();
74
75 void *kernel_globals_device_pointer();
76
77 void mem_alloc(device_memory &mem) override;
78
79 void mem_copy_to(device_memory &mem) override;
80
81 void mem_copy_from(device_memory &mem, size_t y, size_t w, size_t h, size_t elem) override;
82
83 void mem_copy_from(device_memory &mem)
84 {
85 mem_copy_from(mem, 0, 0, 0, 0);
86 }
87
88 void mem_zero(device_memory &mem) override;
89
90 void mem_free(device_memory &mem) override;
91
92 device_ptr mem_alloc_sub_ptr(device_memory &mem, size_t offset, size_t /*size*/) override;
93
94 virtual void const_copy_to(const char *name, void *host, size_t size) override;
95
96 void global_alloc(device_memory &mem);
97
98 void global_free(device_memory &mem);
99
100 void tex_alloc(device_texture &mem);
101
102 void tex_free(device_texture &mem);
103
104 /* Graphics resources interoperability. */
105 virtual bool should_use_graphics_interop() override;
106
107 virtual unique_ptr<DeviceQueue> gpu_queue_create() override;
108
109 /* NOTE(@nsirgien): Create this methods to avoid some compilation problems on Windows with host
110 * side compilation (MSVC). */
111 void *usm_aligned_alloc_host(size_t memory_size, size_t alignment);
112 void usm_free(void *usm_ptr);
113
114 static char *device_capabilities();
115 static void iterate_devices(OneAPIDeviceIteratorCallback cb, void *user_ptr);
116
117 size_t get_memcapacity();
118 int get_num_multiprocessors();
119 int get_max_num_threads_per_multiprocessor();
120 bool queue_synchronize(SyclQueue *queue);
121 bool kernel_globals_size(size_t &kernel_global_size);
122 void set_global_memory(SyclQueue *queue,
123 void *kernel_globals,
124 const char *memory_name,
125 void *memory_device_pointer);
126 bool enqueue_kernel(KernelContext *kernel_context,
127 int kernel,
128 size_t global_size,
129 size_t local_size,
130 void **args);
131 void get_adjusted_global_and_local_sizes(SyclQueue *queue,
132 const DeviceKernel kernel,
133 size_t &kernel_global_size,
134 size_t &kernel_local_size);
135 SyclQueue *sycl_queue();
136
137 protected:
138 bool can_use_hardware_raytracing_for_features(uint kernel_features) const;
139 void check_usm(SyclQueue *queue, const void *usm_ptr, bool allow_host);
140 bool create_queue(SyclQueue *&external_queue, int device_index, void *embree_device);
141 void free_queue(SyclQueue *queue);
142 void *usm_aligned_alloc_host(SyclQueue *queue, size_t memory_size, size_t alignment);
143 void *usm_alloc_device(SyclQueue *queue, size_t memory_size);
144 void usm_free(SyclQueue *queue, void *usm_ptr);
145 bool usm_memcpy(SyclQueue *queue, void *dest, void *src, size_t num_bytes);
146 bool usm_memset(SyclQueue *queue, void *usm_ptr, unsigned char value, size_t num_bytes);
147};
148
150
151#endif
void BLI_kdtree_nd_ free(KDTree *tree)
unsigned int uint
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a vector
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void refit(btStridingMeshInterface *triangles, const btVector3 &aabbMin, const btVector3 &aabbMax)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
virtual void const_copy_to(const char *name, void *host, size_t size)=0
virtual void mem_zero(device_memory &mem)=0
virtual void mem_copy_from(device_memory &mem, size_t y, size_t w, size_t h, size_t elem)=0
virtual unique_ptr< DeviceQueue > gpu_queue_create()
virtual void build_bvh(BVH *bvh, Progress &progress, bool refit)
virtual bool load_kernels(uint)
virtual bool check_peer_access(Device *)
virtual void mem_free(device_memory &mem)=0
virtual BVHLayoutMask get_bvh_layout_mask(uint kernel_features) const =0
virtual void mem_copy_to(device_memory &mem)=0
virtual device_ptr mem_alloc_sub_ptr(device_memory &, size_t, size_t)
static string device_capabilities(uint device_type_mask=DEVICE_MASK_ALL)
virtual void mem_alloc(device_memory &mem)=0
virtual bool should_use_graphics_interop()
#define CCL_NAMESPACE_END
DeviceKernel
ccl_device bool BVH_FUNCTION_FULL_NAME BVH(KernelGlobals kg, ccl_private const Ray *ray, ccl_private LocalIntersection *local_isect, int local_object, ccl_private uint *lcg_state, int max_hits)
Definition local.h:28
int BVHLayoutMask
Definition params.h:51
virtual void get_device_memory_info(size_t &total, size_t &free)=0
virtual bool alloc_host(void *&shared_pointer, size_t size)=0
virtual void transform_host_pointer(void *&device_pointer, void *&shared_pointer)=0
virtual void copy_host_to_device(void *device_pointer, void *host_pointer, size_t size)=0
virtual void free_host(void *shared_pointer)=0
virtual void free_device(void *device_pointer)=0
virtual bool alloc_device(void *&device_pointer, size_t size)=0
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
Definition thread.h:29
uint64_t device_ptr
Definition util/types.h:45