NVIDIA IndeX API nvidia_logo_transpbg.gif Up
cuda_shared_types.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright 2023 NVIDIA Corporation. All rights reserved.
3 *****************************************************************************/
6
7#ifndef NVIDIA_INDEX_CUDA_SHARED_TYPES_H
8#define NVIDIA_INDEX_CUDA_SHARED_TYPES_H
9
10#ifndef __CUDACC__
11#include "base/numeric_types.h"
12#endif
13
14#include "base_math/constants.h"
15
16// Type definitions ///////////////////////////////////////////////////////////////////////////////
17typedef unsigned int uint;
18typedef unsigned short ushort;
19
20// Matrix math
21template<typename T>
22struct matrix2x2
23{
24 T xx;
25 T xy;
26 T yx;
27 T yy;
28};
29
30template<typename T>
31struct matrix3x3
32{
33 T xx;
34 T xy;
35 T xz;
36 T yx;
37 T yy;
38 T yz;
39 T zx;
40 T zy;
41 T zz;
42};
43
44template<typename T>
45struct matrix4x4
46{
47 T xx;
48 T xy;
49 T xz;
50 T xw;
51 T yx;
52 T yy;
53 T yz;
54 T yw;
55 T zx;
56 T zy;
57 T zz;
58 T zw;
59 T wx;
60 T wy;
61 T wz;
62 T ww;
63};
64
65template<typename T>
66struct bbox {
67 T min;
68 T max;
69};
70
71#ifdef __CUDACC__
72
73namespace nv {
74namespace index {
75namespace cuda {
76
77typedef int2 Vec2i;
78typedef int3 Vec3i;
79typedef int4 Vec4i;
80
81typedef uint2 Vec2ui;
82typedef uint3 Vec3ui;
83typedef uint4 Vec4ui;
84
85typedef float2 Vec2f;
86typedef float3 Vec3f;
87typedef float4 Vec4f;
88
89typedef matrix2x2<float> Mat2x2f;
90typedef matrix3x3<float> Mat3x3f;
91typedef matrix4x4<float> Mat4x4f;
92typedef matrix2x2<float> Mat2f;
93typedef matrix3x3<float> Mat3f;
94typedef matrix4x4<float> Mat4f;
95
96typedef bbox<float2> Bbox2f;
97typedef bbox<float3> Bbox3f;
98
99} // namespace cuda
100} // namespace index
101} // namespace nv
102
103// Define basic mi types, so that we don't need the complex include file when using the CUDA
104// compiler
105
106namespace mi {
107
108// The integer sizes are valid for both LP64 (Linux) and Windows (LLP64)
109typedef short Sint16;
110typedef unsigned short Uint16;
111typedef int Sint32;
112typedef unsigned int Uint32;
113typedef long long Sint64;
114typedef unsigned long long Uint64;
115typedef float Float32;
116typedef double Float64;
117
118}
119
120#else // __CUDACC__
121
122namespace nv {
123namespace index {
124namespace cuda {
125
126typedef nv::index::Vector2s Vec2i;
127typedef nv::index::Vector3s Vec3i;
128typedef nv::index::Vector4s Vec4i;
129
130typedef nv::index::Vector2u Vec2ui;
131typedef nv::index::Vector3u Vec3ui;
132typedef nv::index::Vector4u Vec4ui;
133
134typedef nv::index::Vector2f Vec2f;
135typedef nv::index::Vector3f Vec3f;
136typedef nv::index::Vector4f Vec4f;
137
138typedef nv::index::Matrix2x2f Mat2x2f;
139typedef nv::index::Matrix3x3f Mat3x3f;
140typedef nv::index::Matrix4x4f Mat4x4f;
141typedef nv::index::Matrix2x2f Mat2f;
142typedef nv::index::Matrix3x3f Mat3f;
143typedef nv::index::Matrix4x4f Mat4f;
144
145typedef bbox<Vec2f> Bbox2f;
146typedef bbox<Vec3f> Bbox3f;
147
148} // namespace cuda
149} // namespace index
150} // namespace nv
151
152#endif // __CUDACC__
153
154// Function definitions ///////////////////////////////////////////////////////////////////////////
155
156namespace nv {
157namespace index {
158namespace cuda {
159
160#ifdef __CUDACC__
161
162static __inline__ __host__ __device__
163Vec3f make_vec3f(float x, float y, float z)
164{
165 return make_float3(x, y, z);
166}
167
168static __inline__ __host__ __device__
169Vec4f make_vec4f(float x, float y, float z, float w)
170{
171 return make_float4(x, y, z, w);
172}
173
174static __inline__ __host__ __device__
175Mat2x2f make_mat2x2f(float xx, float xy, float yx, float yy)
176{
177 matrix2x2<float> m;
178
179 m.xx = xx;
180 m.xy = xy;
181 m.yx = yx;
182 m.yy = yy;
183
184 return m;
185}
186
187#else // __CUDACC__
188
189// define missing math functions
190static inline Vec2f make_vec2f(float x, float y)
191{
192 return Vec2f(x, y);
193}
194
195static inline Vec3f make_vec3f(float x, float y, float z)
196{
197 return Vec3f(x, y, z);
198}
199
200static inline Vec4f make_vec4f(float x, float y, float z, float w)
201{
202 return Vec4f(x, y, z, w);
203}
204
205static inline Mat2x2f make_mat2x2f(float xx, float xy, float yx, float yy)
206{
207 return Mat2x2f(xx, xy, yx, yy);
208}
209
210template <typename T, mi::Size DIM>
211inline
212mi::math::Vector<T,DIM> normalize(const mi::math::Vector<T, DIM>& v)
213{
214 mi::math::Vector<T, DIM> r(v);
215 r.normalize();
216 return r;
217}
218
219#endif // __CUDACC__
220
221} // namespace cuda
222} // namespace index
223} // namespace nv
224
225#endif // NVIDIA_INDEX_CUDA_SHARED_TYPES_H
Common namespace for all NVIDIA APIs.
Definition: iindex.h:349