Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Kai Karius
Fitter
Commits
c30883dc
Commit
c30883dc
authored
Oct 31, 2020
by
karius
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added util.h
parent
f6e356b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
0 deletions
+109
-0
util.h
util.h
+109
-0
No files found.
util.h
0 → 100644
View file @
c30883dc
/*
* CParticles.h
*
* Created on: Feb 25, 2019
* Author: kkarius
*/
#ifndef UTIL_H_
#define UTIL_H_
#include <cuda_util_include/cutil_math.h>
#include <functional>
#include <thrust/functional.h>
//cuda helper function stolen from the interwebs
#define CUDA_ERROR_CHECK
#define CudaSafeCall( err ) __cudaSafeCall( err, __FILE__, __LINE__ )
#define CudaCheckError() __cudaCheckError( __FILE__, __LINE__ )
inline
void
__cudaSafeCall
(
cudaError
err
,
const
char
*
file
,
const
int
line
)
{
#ifdef CUDA_ERROR_CHECK
if
(
cudaSuccess
!=
err
)
{
fprintf
(
stderr
,
"cudaSafeCall() failed at %s:%i : %s
\n
"
,
file
,
line
,
cudaGetErrorString
(
err
));
exit
(
-
1
);
}
#endif
return
;
}
inline
void
__cudaCheckError
(
const
char
*
file
,
const
int
line
)
{
#ifdef CUDA_ERROR_CHECK
cudaError
err
=
cudaGetLastError
();
if
(
cudaSuccess
!=
err
)
{
fprintf
(
stderr
,
"cudaCheckError() failed at %s:%i : %s
\n
"
,
file
,
line
,
cudaGetErrorString
(
err
));
exit
(
-
1
);
}
// More careful checking. However, this will affect performance.
// Comment away if needed.
err
=
cudaDeviceSynchronize
();
if
(
cudaSuccess
!=
err
)
{
fprintf
(
stderr
,
"cudaCheckError() with sync failed at %s:%i : %s
\n
"
,
file
,
line
,
cudaGetErrorString
(
err
));
exit
(
-
1
);
}
#endif
return
;
}
const
size_t
one_gb
=
1073741824
;
static
const
int
MAXTHREADS
=
1024
;
struct
compare_float4_x
{
__host__
__device__
bool
operator
()(
float4
lhs
,
float4
rhs
)
{
return
lhs
.
x
<
rhs
.
x
;
}
};
struct
compare_float4_y
{
__host__
__device__
bool
operator
()(
float4
lhs
,
float4
rhs
)
{
return
lhs
.
y
<
rhs
.
y
;
}
};
struct
compare_float4_z
{
__host__
__device__
bool
operator
()(
float4
lhs
,
float4
rhs
)
{
return
lhs
.
z
<
rhs
.
z
;
}
};
struct
min_float4
:
public
thrust
::
binary_function
<
float4
,
float4
,
float4
>
{
__host__
__device__
float4
operator
()(
float4
x
,
float4
y
)
{
return
fminf
(
x
,
y
);
}
};
struct
max_float4
:
public
thrust
::
binary_function
<
float4
,
float4
,
float4
>
{
__host__
__device__
float4
operator
()(
float4
x
,
float4
y
)
{
return
fmaxf
(
x
,
y
);
}
};
inline
int
ipow
(
int
base
,
int
exp
)
{
int
result
=
1
;
for
(;;)
{
if
(
exp
&
1
)
result
*=
base
;
exp
>>=
1
;
if
(
!
exp
)
break
;
base
*=
base
;
}
return
result
;
}
#endif
/* UTIL_H_ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment