Blender V4.3
util/types.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifndef __UTIL_TYPES_H__
6#define __UTIL_TYPES_H__
7
8#if !defined(__KERNEL_METAL__)
9# include <stdlib.h>
10#endif
11
12/* Standard Integer Types */
13
14#if !defined(__KERNEL_GPU__)
15# include <stdint.h>
16# include <stdio.h>
17#endif
18
19#include "util/defines.h"
20
21#ifndef __KERNEL_GPU__
22# include "util/optimization.h"
23# include "util/simd.h"
24#endif
25
27
28/* Types
29 *
30 * Define simpler unsigned type names, and integer with defined number of bits.
31 * Also vector types, named to be compatible with OpenCL builtin types, while
32 * working for CUDA and C++ too. */
33
34/* Shorter Unsigned Names */
35
36typedef unsigned char uchar;
37typedef unsigned int uint;
38typedef unsigned short ushort;
39
40/* Fixed Bits Types */
41
42#ifndef __KERNEL_GPU__
43/* Generic Memory Pointer */
44
46#endif /* __KERNEL_GPU__ */
47
48ccl_device_inline size_t align_up(size_t offset, size_t alignment)
49{
50 return (offset + alignment - 1) & ~(alignment - 1);
51}
52
53ccl_device_inline size_t divide_up(size_t x, size_t y)
54{
55 return (x + y - 1) / y;
56}
57
58ccl_device_inline size_t round_up(size_t x, size_t multiple)
59{
60 return ((x + multiple - 1) / multiple) * multiple;
61}
62
63ccl_device_inline size_t round_down(size_t x, size_t multiple)
64{
65 return (x / multiple) * multiple;
66}
67
69{
70 return (x & (x - 1)) == 0;
71}
72
74
75/* Device side printf only tested on CUDA, may work on more GPU devices. */
76#if !defined(__KERNEL_GPU__) || defined(__KERNEL_CUDA__)
77# define __KERNEL_PRINTF__
78#endif
79
80ccl_device_inline void print_float(ccl_private const char *label, const float a)
81{
82#ifdef __KERNEL_PRINTF__
83 printf("%s: %.8f\n", label, (double)a);
84#endif
85}
86
87/* Most GPU APIs matching native vector types, so we only need to implement them for
88 * CPU and oneAPI. */
89#if defined(__KERNEL_GPU__) && !defined(__KERNEL_ONEAPI__)
90# define __KERNEL_NATIVE_VECTOR_TYPES__
91#endif
92
93/* Vectorized types declaration. */
94#include "util/types_uchar2.h"
95#include "util/types_uchar3.h"
96#include "util/types_uchar4.h"
97
98#include "util/types_int2.h"
99#include "util/types_int3.h"
100#include "util/types_int4.h"
101#include "util/types_int8.h"
102
103#include "util/types_uint2.h"
104#include "util/types_uint3.h"
105#include "util/types_uint4.h"
106
107#include "util/types_ushort4.h"
108
109#include "util/types_float2.h"
110#include "util/types_float3.h"
111#include "util/types_float4.h"
112#include "util/types_float8.h"
113
114#include "util/types_spectrum.h"
115
116/* Vectorized types implementation. */
120
121#include "util/types_int2_impl.h"
122#include "util/types_int3_impl.h"
123#include "util/types_int4_impl.h"
124#include "util/types_int8_impl.h"
125
129
134
135#endif /* __UTIL_TYPES_H__ */
#define printf
const char * label
#define ccl_private
#define ccl_device_inline
#define CCL_NAMESPACE_END
unsigned __int64 uint64_t
Definition stdint.h:90
ccl_device_inline size_t align_up(size_t offset, size_t alignment)
Definition util/types.h:48
ccl_device_inline size_t round_down(size_t x, size_t multiple)
Definition util/types.h:63
ccl_device_inline size_t round_up(size_t x, size_t multiple)
Definition util/types.h:58
unsigned int uint
Definition util/types.h:37
CCL_NAMESPACE_BEGIN typedef unsigned char uchar
Definition util/types.h:36
ccl_device_inline bool is_power_of_two(size_t x)
Definition util/types.h:68
ccl_device_inline size_t divide_up(size_t x, size_t y)
Definition util/types.h:53
unsigned short ushort
Definition util/types.h:38
uint64_t device_ptr
Definition util/types.h:45
ccl_device_inline void print_float(ccl_private const char *label, const float a)
Definition util/types.h:80