Apply consistent code formatting across the repo. Add clang-format and pre-commit hooks.

This commit is contained in:
Rob Armstrong
2025-03-27 10:30:07 -07:00
parent 2cd58fbc9a
commit ceab6e8bcc
782 changed files with 107230 additions and 106548 deletions

View File

@@ -61,163 +61,208 @@ namespace cg = cooperative_groups;
//! @param g_pos index of eigenvalue (in ascending order)
//! @param precision desired precision of eigenvalues
////////////////////////////////////////////////////////////////////////////////
__global__ void bisectKernelLarge_MultIntervals(
float *g_d, float *g_s, const unsigned int n, unsigned int *blocks_mult,
unsigned int *blocks_mult_sum, float *g_left, float *g_right,
unsigned int *g_left_count, unsigned int *g_right_count, float *g_lambda,
unsigned int *g_pos, float precision) {
// Handle to thread block group
cg::thread_block cta = cg::this_thread_block();
const unsigned int tid = threadIdx.x;
__global__ void bisectKernelLarge_MultIntervals(float *g_d,
float *g_s,
const unsigned int n,
unsigned int *blocks_mult,
unsigned int *blocks_mult_sum,
float *g_left,
float *g_right,
unsigned int *g_left_count,
unsigned int *g_right_count,
float *g_lambda,
unsigned int *g_pos,
float precision)
{
// Handle to thread block group
cg::thread_block cta = cg::this_thread_block();
const unsigned int tid = threadIdx.x;
// left and right limits of interval
__shared__ float s_left[2 * MAX_THREADS_BLOCK];
__shared__ float s_right[2 * MAX_THREADS_BLOCK];
// left and right limits of interval
__shared__ float s_left[2 * MAX_THREADS_BLOCK];
__shared__ float s_right[2 * MAX_THREADS_BLOCK];
// number of eigenvalues smaller than interval limits
__shared__ unsigned int s_left_count[2 * MAX_THREADS_BLOCK];
__shared__ unsigned int s_right_count[2 * MAX_THREADS_BLOCK];
// number of eigenvalues smaller than interval limits
__shared__ unsigned int s_left_count[2 * MAX_THREADS_BLOCK];
__shared__ unsigned int s_right_count[2 * MAX_THREADS_BLOCK];
// helper array for chunk compaction of second chunk
__shared__ unsigned int s_compaction_list[2 * MAX_THREADS_BLOCK + 1];
// compaction list helper for exclusive scan
unsigned int *s_compaction_list_exc = s_compaction_list + 1;
// helper array for chunk compaction of second chunk
__shared__ unsigned int s_compaction_list[2 * MAX_THREADS_BLOCK + 1];
// compaction list helper for exclusive scan
unsigned int *s_compaction_list_exc = s_compaction_list + 1;
// flag if all threads are converged
__shared__ unsigned int all_threads_converged;
// number of active threads
__shared__ unsigned int num_threads_active;
// number of threads to employ for compaction
__shared__ unsigned int num_threads_compaction;
// flag if second chunk has to be compacted
__shared__ unsigned int compact_second_chunk;
// flag if all threads are converged
__shared__ unsigned int all_threads_converged;
// number of active threads
__shared__ unsigned int num_threads_active;
// number of threads to employ for compaction
__shared__ unsigned int num_threads_compaction;
// flag if second chunk has to be compacted
__shared__ unsigned int compact_second_chunk;
// parameters of block of intervals processed by this block of threads
__shared__ unsigned int c_block_start;
__shared__ unsigned int c_block_end;
__shared__ unsigned int c_block_offset_output;
// parameters of block of intervals processed by this block of threads
__shared__ unsigned int c_block_start;
__shared__ unsigned int c_block_end;
__shared__ unsigned int c_block_offset_output;
// midpoint of currently active interval of the thread
float mid = 0.0f;
// number of eigenvalues smaller than \a mid
unsigned int mid_count = 0;
// current interval parameter
float left;
float right;
unsigned int left_count;
unsigned int right_count;
// helper for compaction, keep track which threads have a second child
unsigned int is_active_second = 0;
// midpoint of currently active interval of the thread
float mid = 0.0f;
// number of eigenvalues smaller than \a mid
unsigned int mid_count = 0;
// current interval parameter
float left;
float right;
unsigned int left_count;
unsigned int right_count;
// helper for compaction, keep track which threads have a second child
unsigned int is_active_second = 0;
// initialize common start conditions
if (0 == tid) {
c_block_start = blocks_mult[blockIdx.x];
c_block_end = blocks_mult[blockIdx.x + 1];
c_block_offset_output = blocks_mult_sum[blockIdx.x];
num_threads_active = c_block_end - c_block_start;
s_compaction_list[0] = 0;
num_threads_compaction = ceilPow2(num_threads_active);
all_threads_converged = 1;
compact_second_chunk = 0;
}
cg::sync(cta);
// read data into shared memory
if (tid < num_threads_active) {
s_left[tid] = g_left[c_block_start + tid];
s_right[tid] = g_right[c_block_start + tid];
s_left_count[tid] = g_left_count[c_block_start + tid];
s_right_count[tid] = g_right_count[c_block_start + tid];
}
cg::sync(cta);
// do until all threads converged
while (true) {
// for (int iter=0; iter < 0; iter++) {
// subdivide interval if currently active and not already converged
subdivideActiveInterval(tid, s_left, s_right, s_left_count, s_right_count,
num_threads_active, left, right, left_count,
right_count, mid, all_threads_converged);
cg::sync(cta);
// stop if all eigenvalues have been found
if (1 == all_threads_converged) {
break;
}
// compute number of eigenvalues smaller than mid for active and not
// converged intervals, use all threads for loading data from gmem and
// s_left and s_right as scratch space to store the data load from gmem
// in shared memory
mid_count = computeNumSmallerEigenvalsLarge(g_d, g_s, n, mid, tid,
num_threads_active, s_left,
s_right, (left == right), cta);
cg::sync(cta);
if (tid < num_threads_active) {
// store intervals
if (left != right) {
storeNonEmptyIntervals(tid, num_threads_active, s_left, s_right,
s_left_count, s_right_count, left, mid, right,
left_count, mid_count, right_count, precision,
compact_second_chunk, s_compaction_list_exc,
is_active_second);
} else {
storeIntervalConverged(
s_left, s_right, s_left_count, s_right_count, left, mid, right,
left_count, mid_count, right_count, s_compaction_list_exc,
compact_second_chunk, num_threads_active, is_active_second);
}
}
cg::sync(cta);
// compact second chunk of intervals if any of the threads generated
// two child intervals
if (1 == compact_second_chunk) {
createIndicesCompaction(s_compaction_list_exc, num_threads_compaction,
cta);
compactIntervals(s_left, s_right, s_left_count, s_right_count, mid, right,
mid_count, right_count, s_compaction_list,
num_threads_active, is_active_second);
}
cg::sync(cta);
// update state variables
// initialize common start conditions
if (0 == tid) {
num_threads_active += s_compaction_list[num_threads_active];
num_threads_compaction = ceilPow2(num_threads_active);
c_block_start = blocks_mult[blockIdx.x];
c_block_end = blocks_mult[blockIdx.x + 1];
c_block_offset_output = blocks_mult_sum[blockIdx.x];
compact_second_chunk = 0;
all_threads_converged = 1;
num_threads_active = c_block_end - c_block_start;
s_compaction_list[0] = 0;
num_threads_compaction = ceilPow2(num_threads_active);
all_threads_converged = 1;
compact_second_chunk = 0;
}
cg::sync(cta);
// clear
s_compaction_list_exc[threadIdx.x] = 0;
s_compaction_list_exc[threadIdx.x + blockDim.x] = 0;
// read data into shared memory
if (tid < num_threads_active) {
s_left[tid] = g_left[c_block_start + tid];
s_right[tid] = g_right[c_block_start + tid];
s_left_count[tid] = g_left_count[c_block_start + tid];
s_right_count[tid] = g_right_count[c_block_start + tid];
}
cg::sync(cta);
} // end until all threads converged
// do until all threads converged
while (true) {
// for (int iter=0; iter < 0; iter++) {
// write data back to global memory
if (tid < num_threads_active) {
unsigned int addr = c_block_offset_output + tid;
// subdivide interval if currently active and not already converged
subdivideActiveInterval(tid,
s_left,
s_right,
s_left_count,
s_right_count,
num_threads_active,
left,
right,
left_count,
right_count,
mid,
all_threads_converged);
g_lambda[addr] = s_left[tid];
g_pos[addr] = s_right_count[tid];
}
cg::sync(cta);
// stop if all eigenvalues have been found
if (1 == all_threads_converged) {
break;
}
// compute number of eigenvalues smaller than mid for active and not
// converged intervals, use all threads for loading data from gmem and
// s_left and s_right as scratch space to store the data load from gmem
// in shared memory
mid_count = computeNumSmallerEigenvalsLarge(
g_d, g_s, n, mid, tid, num_threads_active, s_left, s_right, (left == right), cta);
cg::sync(cta);
if (tid < num_threads_active) {
// store intervals
if (left != right) {
storeNonEmptyIntervals(tid,
num_threads_active,
s_left,
s_right,
s_left_count,
s_right_count,
left,
mid,
right,
left_count,
mid_count,
right_count,
precision,
compact_second_chunk,
s_compaction_list_exc,
is_active_second);
}
else {
storeIntervalConverged(s_left,
s_right,
s_left_count,
s_right_count,
left,
mid,
right,
left_count,
mid_count,
right_count,
s_compaction_list_exc,
compact_second_chunk,
num_threads_active,
is_active_second);
}
}
cg::sync(cta);
// compact second chunk of intervals if any of the threads generated
// two child intervals
if (1 == compact_second_chunk) {
createIndicesCompaction(s_compaction_list_exc, num_threads_compaction, cta);
compactIntervals(s_left,
s_right,
s_left_count,
s_right_count,
mid,
right,
mid_count,
right_count,
s_compaction_list,
num_threads_active,
is_active_second);
}
cg::sync(cta);
// update state variables
if (0 == tid) {
num_threads_active += s_compaction_list[num_threads_active];
num_threads_compaction = ceilPow2(num_threads_active);
compact_second_chunk = 0;
all_threads_converged = 1;
}
cg::sync(cta);
// clear
s_compaction_list_exc[threadIdx.x] = 0;
s_compaction_list_exc[threadIdx.x + blockDim.x] = 0;
cg::sync(cta);
} // end until all threads converged
// write data back to global memory
if (tid < num_threads_active) {
unsigned int addr = c_block_offset_output + tid;
g_lambda[addr] = s_left[tid];
g_pos[addr] = s_right_count[tid];
}
}
#endif // #ifndef _BISECT_KERNEL_LARGE_MULTI_H_
#endif // #ifndef _BISECT_KERNEL_LARGE_MULTI_H_

View File

@@ -57,104 +57,111 @@ namespace cg = cooperative_groups;
//! right interval limit
//! @param precision desired precision of eigenvalues
////////////////////////////////////////////////////////////////////////////////
__global__ void bisectKernelLarge_OneIntervals(
float *g_d, float *g_s, const unsigned int n, unsigned int num_intervals,
float *g_left, float *g_right, unsigned int *g_pos, float precision) {
// Handle to thread block group
cg::thread_block cta = cg::this_thread_block();
const unsigned int gtid = (blockDim.x * blockIdx.x) + threadIdx.x;
__global__ void bisectKernelLarge_OneIntervals(float *g_d,
float *g_s,
const unsigned int n,
unsigned int num_intervals,
float *g_left,
float *g_right,
unsigned int *g_pos,
float precision)
{
// Handle to thread block group
cg::thread_block cta = cg::this_thread_block();
const unsigned int gtid = (blockDim.x * blockIdx.x) + threadIdx.x;
__shared__ float s_left_scratch[MAX_THREADS_BLOCK];
__shared__ float s_right_scratch[MAX_THREADS_BLOCK];
__shared__ float s_left_scratch[MAX_THREADS_BLOCK];
__shared__ float s_right_scratch[MAX_THREADS_BLOCK];
// active interval of thread
// left and right limit of current interval
float left, right;
// number of threads smaller than the right limit (also corresponds to the
// global index of the eigenvalues contained in the active interval)
unsigned int right_count;
// flag if current thread converged
unsigned int converged = 0;
// midpoint when current interval is subdivided
float mid = 0.0f;
// number of eigenvalues less than mid
unsigned int mid_count = 0;
// active interval of thread
// left and right limit of current interval
float left, right;
// number of threads smaller than the right limit (also corresponds to the
// global index of the eigenvalues contained in the active interval)
unsigned int right_count;
// flag if current thread converged
unsigned int converged = 0;
// midpoint when current interval is subdivided
float mid = 0.0f;
// number of eigenvalues less than mid
unsigned int mid_count = 0;
// read data from global memory
if (gtid < num_intervals) {
left = g_left[gtid];
right = g_right[gtid];
right_count = g_pos[gtid];
}
// flag to determine if all threads converged to eigenvalue
__shared__ unsigned int converged_all_threads;
// initialized shared flag
if (0 == threadIdx.x) {
converged_all_threads = 0;
}
cg::sync(cta);
// process until all threads converged to an eigenvalue
// while( 0 == converged_all_threads) {
while (true) {
atomicExch(&converged_all_threads, 1);
// update midpoint for all active threads
if ((gtid < num_intervals) && (0 == converged)) {
mid = computeMidpoint(left, right);
// read data from global memory
if (gtid < num_intervals) {
left = g_left[gtid];
right = g_right[gtid];
right_count = g_pos[gtid];
}
// find number of eigenvalues that are smaller than midpoint
mid_count = computeNumSmallerEigenvalsLarge(
g_d, g_s, n, mid, gtid, num_intervals, s_left_scratch, s_right_scratch,
converged, cta);
// flag to determine if all threads converged to eigenvalue
__shared__ unsigned int converged_all_threads;
cg::sync(cta);
// for all active threads
if ((gtid < num_intervals) && (0 == converged)) {
// udpate intervals -- always one child interval survives
if (right_count == mid_count) {
right = mid;
} else {
left = mid;
}
// check for convergence
float t0 = right - left;
float t1 = max(abs(right), abs(left)) * precision;
if (t0 < min(precision, t1)) {
float lambda = computeMidpoint(left, right);
left = lambda;
right = lambda;
converged = 1;
} else {
atomicExch(&converged_all_threads, 0);
}
// initialized shared flag
if (0 == threadIdx.x) {
converged_all_threads = 0;
}
cg::sync(cta);
if (1 == converged_all_threads) {
break;
// process until all threads converged to an eigenvalue
// while( 0 == converged_all_threads) {
while (true) {
atomicExch(&converged_all_threads, 1);
// update midpoint for all active threads
if ((gtid < num_intervals) && (0 == converged)) {
mid = computeMidpoint(left, right);
}
// find number of eigenvalues that are smaller than midpoint
mid_count = computeNumSmallerEigenvalsLarge(
g_d, g_s, n, mid, gtid, num_intervals, s_left_scratch, s_right_scratch, converged, cta);
cg::sync(cta);
// for all active threads
if ((gtid < num_intervals) && (0 == converged)) {
// udpate intervals -- always one child interval survives
if (right_count == mid_count) {
right = mid;
}
else {
left = mid;
}
// check for convergence
float t0 = right - left;
float t1 = max(abs(right), abs(left)) * precision;
if (t0 < min(precision, t1)) {
float lambda = computeMidpoint(left, right);
left = lambda;
right = lambda;
converged = 1;
}
else {
atomicExch(&converged_all_threads, 0);
}
}
cg::sync(cta);
if (1 == converged_all_threads) {
break;
}
cg::sync(cta);
}
// write data back to global memory
cg::sync(cta);
}
// write data back to global memory
cg::sync(cta);
if (gtid < num_intervals) {
// intervals converged so left and right interval limit are both identical
// and identical to the eigenvalue
g_left[gtid] = left;
}
if (gtid < num_intervals) {
// intervals converged so left and right interval limit are both identical
// and identical to the eigenvalue
g_left[gtid] = left;
}
}
#endif // #ifndef _BISECT_KERNEL_LARGE_ONEI_H_
#endif // #ifndef _BISECT_KERNEL_LARGE_ONEI_H_

View File

@@ -53,176 +53,219 @@ namespace cg = cooperative_groups;
//! @param lu_eig_count number of eigenvalues that are smaller than \a lu
//! @param epsilon desired accuracy of eigenvalues to compute
////////////////////////////////////////////////////////////////////////////////
__global__ void bisectKernel(float *g_d, float *g_s, const unsigned int n,
float *g_left, float *g_right,
unsigned int *g_left_count,
unsigned int *g_right_count, const float lg,
const float ug, const unsigned int lg_eig_count,
const unsigned int ug_eig_count, float epsilon) {
// Handle to thread block group
cg::thread_block cta = cg::this_thread_block();
// intervals (store left and right because the subdivision tree is in general
// not dense
__shared__ float s_left[MAX_THREADS_BLOCK_SMALL_MATRIX];
__shared__ float s_right[MAX_THREADS_BLOCK_SMALL_MATRIX];
__global__ void bisectKernel(float *g_d,
float *g_s,
const unsigned int n,
float *g_left,
float *g_right,
unsigned int *g_left_count,
unsigned int *g_right_count,
const float lg,
const float ug,
const unsigned int lg_eig_count,
const unsigned int ug_eig_count,
float epsilon)
{
// Handle to thread block group
cg::thread_block cta = cg::this_thread_block();
// intervals (store left and right because the subdivision tree is in general
// not dense
__shared__ float s_left[MAX_THREADS_BLOCK_SMALL_MATRIX];
__shared__ float s_right[MAX_THREADS_BLOCK_SMALL_MATRIX];
// number of eigenvalues that are smaller than s_left / s_right
// (correspondence is realized via indices)
__shared__ unsigned int s_left_count[MAX_THREADS_BLOCK_SMALL_MATRIX];
__shared__ unsigned int s_right_count[MAX_THREADS_BLOCK_SMALL_MATRIX];
// number of eigenvalues that are smaller than s_left / s_right
// (correspondence is realized via indices)
__shared__ unsigned int s_left_count[MAX_THREADS_BLOCK_SMALL_MATRIX];
__shared__ unsigned int s_right_count[MAX_THREADS_BLOCK_SMALL_MATRIX];
// helper for stream compaction
__shared__ unsigned int s_compaction_list[MAX_THREADS_BLOCK_SMALL_MATRIX + 1];
// helper for stream compaction
__shared__ unsigned int s_compaction_list[MAX_THREADS_BLOCK_SMALL_MATRIX + 1];
// state variables for whole block
// if 0 then compaction of second chunk of child intervals is not necessary
// (because all intervals had exactly one non-dead child)
__shared__ unsigned int compact_second_chunk;
__shared__ unsigned int all_threads_converged;
// state variables for whole block
// if 0 then compaction of second chunk of child intervals is not necessary
// (because all intervals had exactly one non-dead child)
__shared__ unsigned int compact_second_chunk;
__shared__ unsigned int all_threads_converged;
// number of currently active threads
__shared__ unsigned int num_threads_active;
// number of currently active threads
__shared__ unsigned int num_threads_active;
// number of threads to use for stream compaction
__shared__ unsigned int num_threads_compaction;
// number of threads to use for stream compaction
__shared__ unsigned int num_threads_compaction;
// helper for exclusive scan
unsigned int *s_compaction_list_exc = s_compaction_list + 1;
// helper for exclusive scan
unsigned int *s_compaction_list_exc = s_compaction_list + 1;
// variables for currently processed interval
// left and right limit of active interval
float left = 0.0f;
float right = 0.0f;
unsigned int left_count = 0;
unsigned int right_count = 0;
// midpoint of active interval
float mid = 0.0f;
// number of eigenvalues smaller then mid
unsigned int mid_count = 0;
// affected from compaction
unsigned int is_active_second = 0;
// variables for currently processed interval
// left and right limit of active interval
float left = 0.0f;
float right = 0.0f;
unsigned int left_count = 0;
unsigned int right_count = 0;
// midpoint of active interval
float mid = 0.0f;
// number of eigenvalues smaller then mid
unsigned int mid_count = 0;
// affected from compaction
unsigned int is_active_second = 0;
s_compaction_list[threadIdx.x] = 0;
s_left[threadIdx.x] = 0;
s_right[threadIdx.x] = 0;
s_left_count[threadIdx.x] = 0;
s_right_count[threadIdx.x] = 0;
cg::sync(cta);
// set up initial configuration
if (0 == threadIdx.x) {
s_left[0] = lg;
s_right[0] = ug;
s_left_count[0] = lg_eig_count;
s_right_count[0] = ug_eig_count;
compact_second_chunk = 0;
num_threads_active = 1;
num_threads_compaction = 1;
}
// for all active threads read intervals from the last level
// the number of (worst case) active threads per level l is 2^l
while (true) {
all_threads_converged = 1;
cg::sync(cta);
is_active_second = 0;
subdivideActiveInterval(threadIdx.x, s_left, s_right, s_left_count,
s_right_count, num_threads_active, left, right,
left_count, right_count, mid,
all_threads_converged);
cg::sync(cta);
// check if done
if (1 == all_threads_converged) {
break;
}
cg::sync(cta);
// compute number of eigenvalues smaller than mid
// use all threads for reading the necessary matrix data from global
// memory
// use s_left and s_right as scratch space for diagonal and
// superdiagonal of matrix
mid_count = computeNumSmallerEigenvals(g_d, g_s, n, mid, threadIdx.x,
num_threads_active, s_left, s_right,
(left == right), cta);
cg::sync(cta);
// store intervals
// for all threads store the first child interval in a continuous chunk of
// memory, and the second child interval -- if it exists -- in a second
// chunk; it is likely that all threads reach convergence up to
// \a epsilon at the same level; furthermore, for higher level most / all
// threads will have only one child, storing the first child compactly will
// (first) avoid to perform a compaction step on the first chunk, (second)
// make it for higher levels (when all threads / intervals have
// exactly one child) unnecessary to perform a compaction of the second
// chunk
if (threadIdx.x < num_threads_active) {
if (left != right) {
// store intervals
storeNonEmptyIntervals(threadIdx.x, num_threads_active, s_left, s_right,
s_left_count, s_right_count, left, mid, right,
left_count, mid_count, right_count, epsilon,
compact_second_chunk, s_compaction_list_exc,
is_active_second);
} else {
storeIntervalConverged(
s_left, s_right, s_left_count, s_right_count, left, mid, right,
left_count, mid_count, right_count, s_compaction_list_exc,
compact_second_chunk, num_threads_active, is_active_second);
}
}
// necessary so that compact_second_chunk is up-to-date
cg::sync(cta);
// perform compaction of chunk where second children are stored
// scan of (num_threads_active / 2) elements, thus at most
// (num_threads_active / 4) threads are needed
if (compact_second_chunk > 0) {
createIndicesCompaction(s_compaction_list_exc, num_threads_compaction,
cta);
compactIntervals(s_left, s_right, s_left_count, s_right_count, mid, right,
mid_count, right_count, s_compaction_list,
num_threads_active, is_active_second);
}
s_compaction_list[threadIdx.x] = 0;
s_left[threadIdx.x] = 0;
s_right[threadIdx.x] = 0;
s_left_count[threadIdx.x] = 0;
s_right_count[threadIdx.x] = 0;
cg::sync(cta);
// set up initial configuration
if (0 == threadIdx.x) {
// update number of active threads with result of reduction
num_threads_active += s_compaction_list[num_threads_active];
s_left[0] = lg;
s_right[0] = ug;
s_left_count[0] = lg_eig_count;
s_right_count[0] = ug_eig_count;
num_threads_compaction = ceilPow2(num_threads_active);
compact_second_chunk = 0;
num_threads_active = 1;
compact_second_chunk = 0;
num_threads_compaction = 1;
}
// for all active threads read intervals from the last level
// the number of (worst case) active threads per level l is 2^l
while (true) {
all_threads_converged = 1;
cg::sync(cta);
is_active_second = 0;
subdivideActiveInterval(threadIdx.x,
s_left,
s_right,
s_left_count,
s_right_count,
num_threads_active,
left,
right,
left_count,
right_count,
mid,
all_threads_converged);
cg::sync(cta);
// check if done
if (1 == all_threads_converged) {
break;
}
cg::sync(cta);
// compute number of eigenvalues smaller than mid
// use all threads for reading the necessary matrix data from global
// memory
// use s_left and s_right as scratch space for diagonal and
// superdiagonal of matrix
mid_count = computeNumSmallerEigenvals(
g_d, g_s, n, mid, threadIdx.x, num_threads_active, s_left, s_right, (left == right), cta);
cg::sync(cta);
// store intervals
// for all threads store the first child interval in a continuous chunk of
// memory, and the second child interval -- if it exists -- in a second
// chunk; it is likely that all threads reach convergence up to
// \a epsilon at the same level; furthermore, for higher level most / all
// threads will have only one child, storing the first child compactly will
// (first) avoid to perform a compaction step on the first chunk, (second)
// make it for higher levels (when all threads / intervals have
// exactly one child) unnecessary to perform a compaction of the second
// chunk
if (threadIdx.x < num_threads_active) {
if (left != right) {
// store intervals
storeNonEmptyIntervals(threadIdx.x,
num_threads_active,
s_left,
s_right,
s_left_count,
s_right_count,
left,
mid,
right,
left_count,
mid_count,
right_count,
epsilon,
compact_second_chunk,
s_compaction_list_exc,
is_active_second);
}
else {
storeIntervalConverged(s_left,
s_right,
s_left_count,
s_right_count,
left,
mid,
right,
left_count,
mid_count,
right_count,
s_compaction_list_exc,
compact_second_chunk,
num_threads_active,
is_active_second);
}
}
// necessary so that compact_second_chunk is up-to-date
cg::sync(cta);
// perform compaction of chunk where second children are stored
// scan of (num_threads_active / 2) elements, thus at most
// (num_threads_active / 4) threads are needed
if (compact_second_chunk > 0) {
createIndicesCompaction(s_compaction_list_exc, num_threads_compaction, cta);
compactIntervals(s_left,
s_right,
s_left_count,
s_right_count,
mid,
right,
mid_count,
right_count,
s_compaction_list,
num_threads_active,
is_active_second);
}
cg::sync(cta);
if (0 == threadIdx.x) {
// update number of active threads with result of reduction
num_threads_active += s_compaction_list[num_threads_active];
num_threads_compaction = ceilPow2(num_threads_active);
compact_second_chunk = 0;
}
cg::sync(cta);
}
cg::sync(cta);
}
cg::sync(cta);
// write resulting intervals to global mem
// for all threads write if they have been converged to an eigenvalue to
// a separate array
// write resulting intervals to global mem
// for all threads write if they have been converged to an eigenvalue to
// a separate array
// at most n valid intervals
if (threadIdx.x < n) {
// intervals converged so left and right limit are identical
g_left[threadIdx.x] = s_left[threadIdx.x];
// left count is sufficient to have global order
g_left_count[threadIdx.x] = s_left_count[threadIdx.x];
}
// at most n valid intervals
if (threadIdx.x < n) {
// intervals converged so left and right limit are identical
g_left[threadIdx.x] = s_left[threadIdx.x];
// left count is sufficient to have global order
g_left_count[threadIdx.x] = s_left_count[threadIdx.x];
}
}
#endif // #ifndef _BISECT_KERNEL_SMALL_H_
#endif // #ifndef _BISECT_KERNEL_SMALL_H_

View File

@@ -28,117 +28,103 @@
/* Computation of eigenvalues of a large symmetric, tridiagonal matrix */
// includes, system
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// includes, project
#include "helper_functions.h"
#include "helper_cuda.h"
#include "bisect_large.cuh"
#include "config.h"
#include "helper_cuda.h"
#include "helper_functions.h"
#include "matlab.h"
#include "structs.h"
#include "util.h"
#include "matlab.h"
#include "bisect_large.cuh"
// includes, kernels
#include "bisect_kernel_large.cuh"
#include "bisect_kernel_large_onei.cuh"
#include "bisect_kernel_large_multi.cuh"
#include "bisect_kernel_large_onei.cuh"
////////////////////////////////////////////////////////////////////////////////
//! Initialize variables and memory for result
//! @param result handles to memory
//! @param matrix_size size of the matrix
////////////////////////////////////////////////////////////////////////////////
void initResultDataLargeMatrix(ResultDataLarge &result,
const unsigned int mat_size) {
// helper variables to initialize memory
unsigned int zero = 0;
unsigned int mat_size_f = sizeof(float) * mat_size;
unsigned int mat_size_ui = sizeof(unsigned int) * mat_size;
void initResultDataLargeMatrix(ResultDataLarge &result, const unsigned int mat_size)
{
// helper variables to initialize memory
unsigned int zero = 0;
unsigned int mat_size_f = sizeof(float) * mat_size;
unsigned int mat_size_ui = sizeof(unsigned int) * mat_size;
float *tempf = (float *)malloc(mat_size_f);
unsigned int *tempui = (unsigned int *)malloc(mat_size_ui);
float *tempf = (float *)malloc(mat_size_f);
unsigned int *tempui = (unsigned int *)malloc(mat_size_ui);
for (unsigned int i = 0; i < mat_size; ++i) {
tempf[i] = 0.0f;
tempui[i] = 0;
}
for (unsigned int i = 0; i < mat_size; ++i) {
tempf[i] = 0.0f;
tempui[i] = 0;
}
// number of intervals containing only one eigenvalue after the first step
checkCudaErrors(cudaMalloc((void **)&result.g_num_one, sizeof(unsigned int)));
checkCudaErrors(cudaMemcpy(result.g_num_one, &zero, sizeof(unsigned int),
cudaMemcpyHostToDevice));
// number of intervals containing only one eigenvalue after the first step
checkCudaErrors(cudaMalloc((void **)&result.g_num_one, sizeof(unsigned int)));
checkCudaErrors(cudaMemcpy(result.g_num_one, &zero, sizeof(unsigned int), cudaMemcpyHostToDevice));
// number of (thread) blocks of intervals with multiple eigenvalues after
// the first iteration
checkCudaErrors(
cudaMalloc((void **)&result.g_num_blocks_mult, sizeof(unsigned int)));
checkCudaErrors(cudaMemcpy(result.g_num_blocks_mult, &zero,
sizeof(unsigned int), cudaMemcpyHostToDevice));
// number of (thread) blocks of intervals with multiple eigenvalues after
// the first iteration
checkCudaErrors(cudaMalloc((void **)&result.g_num_blocks_mult, sizeof(unsigned int)));
checkCudaErrors(cudaMemcpy(result.g_num_blocks_mult, &zero, sizeof(unsigned int), cudaMemcpyHostToDevice));
checkCudaErrors(cudaMalloc((void **)&result.g_left_one, mat_size_f));
checkCudaErrors(cudaMalloc((void **)&result.g_right_one, mat_size_f));
checkCudaErrors(cudaMalloc((void **)&result.g_pos_one, mat_size_ui));
checkCudaErrors(cudaMalloc((void **)&result.g_left_one, mat_size_f));
checkCudaErrors(cudaMalloc((void **)&result.g_right_one, mat_size_f));
checkCudaErrors(cudaMalloc((void **)&result.g_pos_one, mat_size_ui));
checkCudaErrors(cudaMalloc((void **)&result.g_left_mult, mat_size_f));
checkCudaErrors(cudaMalloc((void **)&result.g_right_mult, mat_size_f));
checkCudaErrors(cudaMalloc((void **)&result.g_left_count_mult, mat_size_ui));
checkCudaErrors(cudaMalloc((void **)&result.g_right_count_mult, mat_size_ui));
checkCudaErrors(cudaMalloc((void **)&result.g_left_mult, mat_size_f));
checkCudaErrors(cudaMalloc((void **)&result.g_right_mult, mat_size_f));
checkCudaErrors(cudaMalloc((void **)&result.g_left_count_mult, mat_size_ui));
checkCudaErrors(cudaMalloc((void **)&result.g_right_count_mult, mat_size_ui));
checkCudaErrors(
cudaMemcpy(result.g_left_one, tempf, mat_size_f, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_right_one, tempf, mat_size_f,
cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_pos_one, tempui, mat_size_ui,
cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_left_one, tempf, mat_size_f, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_right_one, tempf, mat_size_f, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_pos_one, tempui, mat_size_ui, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_left_mult, tempf, mat_size_f,
cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_right_mult, tempf, mat_size_f,
cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_left_count_mult, tempui, mat_size_ui,
cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_right_count_mult, tempui, mat_size_ui,
cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_left_mult, tempf, mat_size_f, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_right_mult, tempf, mat_size_f, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_left_count_mult, tempui, mat_size_ui, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_right_count_mult, tempui, mat_size_ui, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMalloc((void **)&result.g_blocks_mult, mat_size_ui));
checkCudaErrors(cudaMemcpy(result.g_blocks_mult, tempui, mat_size_ui,
cudaMemcpyHostToDevice));
checkCudaErrors(cudaMalloc((void **)&result.g_blocks_mult_sum, mat_size_ui));
checkCudaErrors(cudaMemcpy(result.g_blocks_mult_sum, tempui, mat_size_ui,
cudaMemcpyHostToDevice));
checkCudaErrors(cudaMalloc((void **)&result.g_blocks_mult, mat_size_ui));
checkCudaErrors(cudaMemcpy(result.g_blocks_mult, tempui, mat_size_ui, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMalloc((void **)&result.g_blocks_mult_sum, mat_size_ui));
checkCudaErrors(cudaMemcpy(result.g_blocks_mult_sum, tempui, mat_size_ui, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMalloc((void **)&result.g_lambda_mult, mat_size_f));
checkCudaErrors(cudaMemcpy(result.g_lambda_mult, tempf, mat_size_f,
cudaMemcpyHostToDevice));
checkCudaErrors(cudaMalloc((void **)&result.g_pos_mult, mat_size_ui));
checkCudaErrors(cudaMemcpy(result.g_pos_mult, tempf, mat_size_ui,
cudaMemcpyHostToDevice));
checkCudaErrors(cudaMalloc((void **)&result.g_lambda_mult, mat_size_f));
checkCudaErrors(cudaMemcpy(result.g_lambda_mult, tempf, mat_size_f, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMalloc((void **)&result.g_pos_mult, mat_size_ui));
checkCudaErrors(cudaMemcpy(result.g_pos_mult, tempf, mat_size_ui, cudaMemcpyHostToDevice));
}
////////////////////////////////////////////////////////////////////////////////
//! Cleanup result memory
//! @param result handles to memory
////////////////////////////////////////////////////////////////////////////////
void cleanupResultDataLargeMatrix(ResultDataLarge &result) {
checkCudaErrors(cudaFree(result.g_num_one));
checkCudaErrors(cudaFree(result.g_num_blocks_mult));
checkCudaErrors(cudaFree(result.g_left_one));
checkCudaErrors(cudaFree(result.g_right_one));
checkCudaErrors(cudaFree(result.g_pos_one));
checkCudaErrors(cudaFree(result.g_left_mult));
checkCudaErrors(cudaFree(result.g_right_mult));
checkCudaErrors(cudaFree(result.g_left_count_mult));
checkCudaErrors(cudaFree(result.g_right_count_mult));
checkCudaErrors(cudaFree(result.g_blocks_mult));
checkCudaErrors(cudaFree(result.g_blocks_mult_sum));
checkCudaErrors(cudaFree(result.g_lambda_mult));
checkCudaErrors(cudaFree(result.g_pos_mult));
void cleanupResultDataLargeMatrix(ResultDataLarge &result)
{
checkCudaErrors(cudaFree(result.g_num_one));
checkCudaErrors(cudaFree(result.g_num_blocks_mult));
checkCudaErrors(cudaFree(result.g_left_one));
checkCudaErrors(cudaFree(result.g_right_one));
checkCudaErrors(cudaFree(result.g_pos_one));
checkCudaErrors(cudaFree(result.g_left_mult));
checkCudaErrors(cudaFree(result.g_right_mult));
checkCudaErrors(cudaFree(result.g_left_count_mult));
checkCudaErrors(cudaFree(result.g_right_count_mult));
checkCudaErrors(cudaFree(result.g_blocks_mult));
checkCudaErrors(cudaFree(result.g_blocks_mult_sum));
checkCudaErrors(cudaFree(result.g_lambda_mult));
checkCudaErrors(cudaFree(result.g_pos_mult));
}
////////////////////////////////////////////////////////////////////////////////
@@ -151,109 +137,130 @@ void cleanupResultDataLargeMatrix(ResultDataLarge &result) {
//! @param ug upper limit of Gerschgorin interval
//! @param iterations number of iterations (for timing)
////////////////////////////////////////////////////////////////////////////////
void computeEigenvaluesLargeMatrix(const InputData &input,
void computeEigenvaluesLargeMatrix(const InputData &input,
const ResultDataLarge &result,
const unsigned int mat_size,
const float precision, const float lg,
const float ug,
const unsigned int iterations) {
dim3 blocks(1, 1, 1);
dim3 threads(MAX_THREADS_BLOCK, 1, 1);
const unsigned int mat_size,
const float precision,
const float lg,
const float ug,
const unsigned int iterations)
{
dim3 blocks(1, 1, 1);
dim3 threads(MAX_THREADS_BLOCK, 1, 1);
StopWatchInterface *timer_step1 = NULL;
StopWatchInterface *timer_step2_one = NULL;
StopWatchInterface *timer_step2_mult = NULL;
StopWatchInterface *timer_total = NULL;
sdkCreateTimer(&timer_step1);
sdkCreateTimer(&timer_step2_one);
sdkCreateTimer(&timer_step2_mult);
sdkCreateTimer(&timer_total);
StopWatchInterface *timer_step1 = NULL;
StopWatchInterface *timer_step2_one = NULL;
StopWatchInterface *timer_step2_mult = NULL;
StopWatchInterface *timer_total = NULL;
sdkCreateTimer(&timer_step1);
sdkCreateTimer(&timer_step2_one);
sdkCreateTimer(&timer_step2_mult);
sdkCreateTimer(&timer_total);
sdkStartTimer(&timer_total);
sdkStartTimer(&timer_total);
// do for multiple iterations to improve timing accuracy
for (unsigned int iter = 0; iter < iterations; ++iter) {
sdkStartTimer(&timer_step1);
bisectKernelLarge<<<blocks, threads>>>(
input.g_a, input.g_b, mat_size, lg, ug, 0, mat_size, precision,
result.g_num_one, result.g_num_blocks_mult, result.g_left_one,
result.g_right_one, result.g_pos_one, result.g_left_mult,
result.g_right_mult, result.g_left_count_mult,
result.g_right_count_mult, result.g_blocks_mult,
result.g_blocks_mult_sum);
// do for multiple iterations to improve timing accuracy
for (unsigned int iter = 0; iter < iterations; ++iter) {
sdkStartTimer(&timer_step1);
bisectKernelLarge<<<blocks, threads>>>(input.g_a,
input.g_b,
mat_size,
lg,
ug,
0,
mat_size,
precision,
result.g_num_one,
result.g_num_blocks_mult,
result.g_left_one,
result.g_right_one,
result.g_pos_one,
result.g_left_mult,
result.g_right_mult,
result.g_left_count_mult,
result.g_right_count_mult,
result.g_blocks_mult,
result.g_blocks_mult_sum);
getLastCudaError("Kernel launch failed.");
checkCudaErrors(cudaDeviceSynchronize());
sdkStopTimer(&timer_step1);
getLastCudaError("Kernel launch failed.");
checkCudaErrors(cudaDeviceSynchronize());
sdkStopTimer(&timer_step1);
// get the number of intervals containing one eigenvalue after the first
// processing step
unsigned int num_one_intervals;
checkCudaErrors(cudaMemcpy(&num_one_intervals, result.g_num_one,
sizeof(unsigned int), cudaMemcpyDeviceToHost));
// get the number of intervals containing one eigenvalue after the first
// processing step
unsigned int num_one_intervals;
checkCudaErrors(cudaMemcpy(&num_one_intervals, result.g_num_one, sizeof(unsigned int), cudaMemcpyDeviceToHost));
dim3 grid_onei;
grid_onei.x = getNumBlocksLinear(num_one_intervals, MAX_THREADS_BLOCK);
dim3 threads_onei;
// use always max number of available threads to better balance load times
// for matrix data
threads_onei.x = MAX_THREADS_BLOCK;
dim3 grid_onei;
grid_onei.x = getNumBlocksLinear(num_one_intervals, MAX_THREADS_BLOCK);
dim3 threads_onei;
// use always max number of available threads to better balance load times
// for matrix data
threads_onei.x = MAX_THREADS_BLOCK;
// compute eigenvalues for intervals that contained only one eigenvalue
// after the first processing step
sdkStartTimer(&timer_step2_one);
// compute eigenvalues for intervals that contained only one eigenvalue
// after the first processing step
sdkStartTimer(&timer_step2_one);
bisectKernelLarge_OneIntervals<<<grid_onei, threads_onei>>>(
input.g_a, input.g_b, mat_size, num_one_intervals, result.g_left_one,
result.g_right_one, result.g_pos_one, precision);
bisectKernelLarge_OneIntervals<<<grid_onei, threads_onei>>>(input.g_a,
input.g_b,
mat_size,
num_one_intervals,
result.g_left_one,
result.g_right_one,
result.g_pos_one,
precision);
getLastCudaError("bisectKernelLarge_OneIntervals() FAILED.");
checkCudaErrors(cudaDeviceSynchronize());
sdkStopTimer(&timer_step2_one);
getLastCudaError("bisectKernelLarge_OneIntervals() FAILED.");
checkCudaErrors(cudaDeviceSynchronize());
sdkStopTimer(&timer_step2_one);
// process intervals that contained more than one eigenvalue after
// the first processing step
// process intervals that contained more than one eigenvalue after
// the first processing step
// get the number of blocks of intervals that contain, in total when
// each interval contains only one eigenvalue, not more than
// MAX_THREADS_BLOCK threads
unsigned int num_blocks_mult = 0;
checkCudaErrors(cudaMemcpy(&num_blocks_mult, result.g_num_blocks_mult,
sizeof(unsigned int), cudaMemcpyDeviceToHost));
// get the number of blocks of intervals that contain, in total when
// each interval contains only one eigenvalue, not more than
// MAX_THREADS_BLOCK threads
unsigned int num_blocks_mult = 0;
checkCudaErrors(
cudaMemcpy(&num_blocks_mult, result.g_num_blocks_mult, sizeof(unsigned int), cudaMemcpyDeviceToHost));
// setup the execution environment
dim3 grid_mult(num_blocks_mult, 1, 1);
dim3 threads_mult(MAX_THREADS_BLOCK, 1, 1);
// setup the execution environment
dim3 grid_mult(num_blocks_mult, 1, 1);
dim3 threads_mult(MAX_THREADS_BLOCK, 1, 1);
sdkStartTimer(&timer_step2_mult);
sdkStartTimer(&timer_step2_mult);
bisectKernelLarge_MultIntervals<<<grid_mult, threads_mult>>>(
input.g_a, input.g_b, mat_size, result.g_blocks_mult,
result.g_blocks_mult_sum, result.g_left_mult, result.g_right_mult,
result.g_left_count_mult, result.g_right_count_mult,
result.g_lambda_mult, result.g_pos_mult, precision);
bisectKernelLarge_MultIntervals<<<grid_mult, threads_mult>>>(input.g_a,
input.g_b,
mat_size,
result.g_blocks_mult,
result.g_blocks_mult_sum,
result.g_left_mult,
result.g_right_mult,
result.g_left_count_mult,
result.g_right_count_mult,
result.g_lambda_mult,
result.g_pos_mult,
precision);
getLastCudaError("bisectKernelLarge_MultIntervals() FAILED.");
checkCudaErrors(cudaDeviceSynchronize());
sdkStopTimer(&timer_step2_mult);
}
getLastCudaError("bisectKernelLarge_MultIntervals() FAILED.");
checkCudaErrors(cudaDeviceSynchronize());
sdkStopTimer(&timer_step2_mult);
}
sdkStopTimer(&timer_total);
sdkStopTimer(&timer_total);
printf("Average time step 1: %f ms\n",
sdkGetTimerValue(&timer_step1) / (float)iterations);
printf("Average time step 2, one intervals: %f ms\n",
sdkGetTimerValue(&timer_step2_one) / (float)iterations);
printf("Average time step 2, mult intervals: %f ms\n",
sdkGetTimerValue(&timer_step2_mult) / (float)iterations);
printf("Average time step 1: %f ms\n", sdkGetTimerValue(&timer_step1) / (float)iterations);
printf("Average time step 2, one intervals: %f ms\n", sdkGetTimerValue(&timer_step2_one) / (float)iterations);
printf("Average time step 2, mult intervals: %f ms\n", sdkGetTimerValue(&timer_step2_mult) / (float)iterations);
printf("Average time TOTAL: %f ms\n",
sdkGetTimerValue(&timer_total) / (float)iterations);
printf("Average time TOTAL: %f ms\n", sdkGetTimerValue(&timer_total) / (float)iterations);
sdkDeleteTimer(&timer_step1);
sdkDeleteTimer(&timer_step2_one);
sdkDeleteTimer(&timer_step2_mult);
sdkDeleteTimer(&timer_total);
sdkDeleteTimer(&timer_step1);
sdkDeleteTimer(&timer_step2_one);
sdkDeleteTimer(&timer_step2_mult);
sdkDeleteTimer(&timer_total);
}
////////////////////////////////////////////////////////////////////////////////
@@ -264,105 +271,98 @@ void computeEigenvaluesLargeMatrix(const InputData &input,
//! @param mat_size matrix size
//! @param filename output filename
////////////////////////////////////////////////////////////////////////////////
bool processResultDataLargeMatrix(const InputData &input,
bool processResultDataLargeMatrix(const InputData &input,
const ResultDataLarge &result,
const unsigned int mat_size,
const char *filename,
const unsigned int user_defined,
char *exec_path) {
bool bCompareResult = false;
const unsigned int mat_size_ui = sizeof(unsigned int) * mat_size;
const unsigned int mat_size_f = sizeof(float) * mat_size;
const unsigned int mat_size,
const char *filename,
const unsigned int user_defined,
char *exec_path)
{
bool bCompareResult = false;
const unsigned int mat_size_ui = sizeof(unsigned int) * mat_size;
const unsigned int mat_size_f = sizeof(float) * mat_size;
// copy data from intervals that contained more than one eigenvalue after
// the first processing step
float *lambda_mult = (float *)malloc(sizeof(float) * mat_size);
checkCudaErrors(cudaMemcpy(lambda_mult, result.g_lambda_mult,
sizeof(float) * mat_size, cudaMemcpyDeviceToHost));
unsigned int *pos_mult =
(unsigned int *)malloc(sizeof(unsigned int) * mat_size);
checkCudaErrors(cudaMemcpy(pos_mult, result.g_pos_mult,
sizeof(unsigned int) * mat_size,
cudaMemcpyDeviceToHost));
// copy data from intervals that contained more than one eigenvalue after
// the first processing step
float *lambda_mult = (float *)malloc(sizeof(float) * mat_size);
checkCudaErrors(cudaMemcpy(lambda_mult, result.g_lambda_mult, sizeof(float) * mat_size, cudaMemcpyDeviceToHost));
unsigned int *pos_mult = (unsigned int *)malloc(sizeof(unsigned int) * mat_size);
checkCudaErrors(cudaMemcpy(pos_mult, result.g_pos_mult, sizeof(unsigned int) * mat_size, cudaMemcpyDeviceToHost));
unsigned int *blocks_mult_sum =
(unsigned int *)malloc(sizeof(unsigned int) * mat_size);
checkCudaErrors(cudaMemcpy(blocks_mult_sum, result.g_blocks_mult_sum,
sizeof(unsigned int) * mat_size,
cudaMemcpyDeviceToHost));
unsigned int *blocks_mult_sum = (unsigned int *)malloc(sizeof(unsigned int) * mat_size);
checkCudaErrors(
cudaMemcpy(blocks_mult_sum, result.g_blocks_mult_sum, sizeof(unsigned int) * mat_size, cudaMemcpyDeviceToHost));
unsigned int num_one_intervals;
checkCudaErrors(cudaMemcpy(&num_one_intervals, result.g_num_one,
sizeof(unsigned int), cudaMemcpyDeviceToHost));
unsigned int num_one_intervals;
checkCudaErrors(cudaMemcpy(&num_one_intervals, result.g_num_one, sizeof(unsigned int), cudaMemcpyDeviceToHost));
unsigned int sum_blocks_mult = mat_size - num_one_intervals;
unsigned int sum_blocks_mult = mat_size - num_one_intervals;
// copy data for intervals that contained one eigenvalue after the first
// processing step
float *left_one = (float *)malloc(mat_size_f);
float *right_one = (float *)malloc(mat_size_f);
unsigned int *pos_one = (unsigned int *)malloc(mat_size_ui);
checkCudaErrors(cudaMemcpy(left_one, result.g_left_one, mat_size_f,
cudaMemcpyDeviceToHost));
checkCudaErrors(cudaMemcpy(right_one, result.g_right_one, mat_size_f,
cudaMemcpyDeviceToHost));
checkCudaErrors(cudaMemcpy(pos_one, result.g_pos_one, mat_size_ui,
cudaMemcpyDeviceToHost));
// copy data for intervals that contained one eigenvalue after the first
// processing step
float *left_one = (float *)malloc(mat_size_f);
float *right_one = (float *)malloc(mat_size_f);
unsigned int *pos_one = (unsigned int *)malloc(mat_size_ui);
checkCudaErrors(cudaMemcpy(left_one, result.g_left_one, mat_size_f, cudaMemcpyDeviceToHost));
checkCudaErrors(cudaMemcpy(right_one, result.g_right_one, mat_size_f, cudaMemcpyDeviceToHost));
checkCudaErrors(cudaMemcpy(pos_one, result.g_pos_one, mat_size_ui, cudaMemcpyDeviceToHost));
// extract eigenvalues
float *eigenvals = (float *)malloc(mat_size_f);
// extract eigenvalues
float *eigenvals = (float *)malloc(mat_size_f);
// singleton intervals generated in the second step
for (unsigned int i = 0; i < sum_blocks_mult; ++i) {
eigenvals[pos_mult[i] - 1] = lambda_mult[i];
}
// singleton intervals generated in the first step
unsigned int index = 0;
for (unsigned int i = 0; i < num_one_intervals; ++i, ++index) {
eigenvals[pos_one[i] - 1] = left_one[i];
}
if (1 == user_defined) {
// store result
writeTridiagSymMatlab(filename, input.a, input.b + 1, eigenvals, mat_size);
// getLastCudaError( sdkWriteFilef( filename, eigenvals, mat_size, 0.0f));
printf("User requests non-default argument(s), skipping self-check!\n");
bCompareResult = true;
} else {
// compare with reference solution
float *reference = NULL;
unsigned int input_data_size = 0;
char *ref_path = sdkFindFilePath("reference.dat", exec_path);
assert(NULL != ref_path);
sdkReadFile(ref_path, &reference, &input_data_size, false);
assert(input_data_size == mat_size);
// there's an imprecision of Sturm count computation which makes an
// additional offset necessary
float tolerance = 1.0e-5f + 5.0e-6f;
if (sdkCompareL2fe(reference, eigenvals, mat_size, tolerance) == true) {
bCompareResult = true;
} else {
bCompareResult = false;
// singleton intervals generated in the second step
for (unsigned int i = 0; i < sum_blocks_mult; ++i) {
eigenvals[pos_mult[i] - 1] = lambda_mult[i];
}
free(ref_path);
free(reference);
}
// singleton intervals generated in the first step
unsigned int index = 0;
freePtr(eigenvals);
freePtr(lambda_mult);
freePtr(pos_mult);
freePtr(blocks_mult_sum);
freePtr(left_one);
freePtr(right_one);
freePtr(pos_one);
for (unsigned int i = 0; i < num_one_intervals; ++i, ++index) {
eigenvals[pos_one[i] - 1] = left_one[i];
}
return bCompareResult;
if (1 == user_defined) {
// store result
writeTridiagSymMatlab(filename, input.a, input.b + 1, eigenvals, mat_size);
// getLastCudaError( sdkWriteFilef( filename, eigenvals, mat_size, 0.0f));
printf("User requests non-default argument(s), skipping self-check!\n");
bCompareResult = true;
}
else {
// compare with reference solution
float *reference = NULL;
unsigned int input_data_size = 0;
char *ref_path = sdkFindFilePath("reference.dat", exec_path);
assert(NULL != ref_path);
sdkReadFile(ref_path, &reference, &input_data_size, false);
assert(input_data_size == mat_size);
// there's an imprecision of Sturm count computation which makes an
// additional offset necessary
float tolerance = 1.0e-5f + 5.0e-6f;
if (sdkCompareL2fe(reference, eigenvals, mat_size, tolerance) == true) {
bCompareResult = true;
}
else {
bCompareResult = false;
}
free(ref_path);
free(reference);
}
freePtr(eigenvals);
freePtr(lambda_mult);
freePtr(pos_mult);
freePtr(blocks_mult_sum);
freePtr(left_one);
freePtr(right_one);
freePtr(pos_one);
return bCompareResult;
}

View File

@@ -30,53 +30,56 @@
#ifndef _BISECT_LARGE_CUH_
#define _BISECT_LARGE_CUH_
extern "C" {
#include "structs.h"
////////////////////////////////////////////////////////////////////////////////
//! Run the kernels to compute the eigenvalues for large matrices
//! @param input handles to input data
//! @param result handles to result data
//! @param mat_size matrix size
//! @param precision desired precision of eigenvalues
//! @param lg lower limit of Gerschgorin interval
//! @param ug upper limit of Gerschgorin interval
//! @param iterations number of iterations (for timing)
////////////////////////////////////////////////////////////////////////////////
void computeEigenvaluesLargeMatrix(const InputData &input,
const ResultDataLarge &result,
const unsigned int mat_size,
const float precision, const float lg,
const float ug,
const unsigned int iterations);
extern "C"
{
////////////////////////////////////////////////////////////////////////////////
//! Initialize variables and memory for result
//! @param result handles to memory
//! @param matr_size size of the matrix
////////////////////////////////////////////////////////////////////////////////
void initResultDataLargeMatrix(ResultDataLarge &result,
const unsigned int mat_size);
////////////////////////////////////////////////////////////////////////////////
//! Run the kernels to compute the eigenvalues for large matrices
//! @param input handles to input data
//! @param result handles to result data
//! @param mat_size matrix size
//! @param precision desired precision of eigenvalues
//! @param lg lower limit of Gerschgorin interval
//! @param ug upper limit of Gerschgorin interval
//! @param iterations number of iterations (for timing)
////////////////////////////////////////////////////////////////////////////////
void computeEigenvaluesLargeMatrix(const InputData &input,
const ResultDataLarge &result,
const unsigned int mat_size,
const float precision,
const float lg,
const float ug,
const unsigned int iterations);
////////////////////////////////////////////////////////////////////////////////
//! Cleanup result memory
//! @param result handles to memory
////////////////////////////////////////////////////////////////////////////////
void cleanupResultDataLargeMatrix(ResultDataLarge &result);
////////////////////////////////////////////////////////////////////////////////
//! Initialize variables and memory for result
//! @param result handles to memory
//! @param matr_size size of the matrix
////////////////////////////////////////////////////////////////////////////////
void initResultDataLargeMatrix(ResultDataLarge &result, const unsigned int mat_size);
////////////////////////////////////////////////////////////////////////////////
//! Process the result, that is obtain result from device and do simple sanity
//! checking
//! @param input handles to input data
//! @param result handles to result data
//! @param mat_size matrix size
//! @param filename output filename
////////////////////////////////////////////////////////////////////////////////
bool processResultDataLargeMatrix(const InputData &input,
const ResultDataLarge &result,
const unsigned int mat_size,
const char *filename,
const unsigned int user_defined,
char *exec_path);
////////////////////////////////////////////////////////////////////////////////
//! Cleanup result memory
//! @param result handles to memory
////////////////////////////////////////////////////////////////////////////////
void cleanupResultDataLargeMatrix(ResultDataLarge &result);
////////////////////////////////////////////////////////////////////////////////
//! Process the result, that is obtain result from device and do simple sanity
//! checking
//! @param input handles to input data
//! @param result handles to result data
//! @param mat_size matrix size
//! @param filename output filename
////////////////////////////////////////////////////////////////////////////////
bool processResultDataLargeMatrix(const InputData &input,
const ResultDataLarge &result,
const unsigned int mat_size,
const char *filename,
const unsigned int user_defined,
char *exec_path);
};
#endif // #ifndef _BISECT_LARGE_CUH_
#endif // #ifndef _BISECT_LARGE_CUH_

View File

@@ -28,18 +28,18 @@
/* Computation of eigenvalues of a small symmetric, tridiagonal matrix */
// includes, system
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// includes, project
#include "helper_functions.h"
#include "helper_cuda.h"
#include "config.h"
#include "structs.h"
#include "helper_cuda.h"
#include "helper_functions.h"
#include "matlab.h"
#include "structs.h"
// includes, kernels
#include "bisect_kernel_small.cuh"
@@ -58,32 +58,42 @@
//! @param precision desired precision of eigenvalues
//! @param iterations number of iterations for timing
////////////////////////////////////////////////////////////////////////////////
void computeEigenvaluesSmallMatrix(const InputData &input,
ResultDataSmall &result,
const unsigned int mat_size, const float lg,
const float ug, const float precision,
const unsigned int iterations) {
StopWatchInterface *timer = NULL;
sdkCreateTimer(&timer);
sdkStartTimer(&timer);
void computeEigenvaluesSmallMatrix(const InputData &input,
ResultDataSmall &result,
const unsigned int mat_size,
const float lg,
const float ug,
const float precision,
const unsigned int iterations)
{
StopWatchInterface *timer = NULL;
sdkCreateTimer(&timer);
sdkStartTimer(&timer);
for (unsigned int i = 0; i < iterations; ++i) {
dim3 blocks(1, 1, 1);
dim3 threads(MAX_THREADS_BLOCK_SMALL_MATRIX, 1, 1);
for (unsigned int i = 0; i < iterations; ++i) {
dim3 blocks(1, 1, 1);
dim3 threads(MAX_THREADS_BLOCK_SMALL_MATRIX, 1, 1);
bisectKernel<<<blocks, threads>>>(input.g_a, input.g_b, mat_size,
result.g_left, result.g_right,
result.g_left_count, result.g_right_count,
lg, ug, 0, mat_size, precision);
}
bisectKernel<<<blocks, threads>>>(input.g_a,
input.g_b,
mat_size,
result.g_left,
result.g_right,
result.g_left_count,
result.g_right_count,
lg,
ug,
0,
mat_size,
precision);
}
checkCudaErrors(cudaDeviceSynchronize());
sdkStopTimer(&timer);
getLastCudaError("Kernel launch failed");
printf("Average time: %f ms (%i iterations)\n",
sdkGetTimerValue(&timer) / (float)iterations, iterations);
checkCudaErrors(cudaDeviceSynchronize());
sdkStopTimer(&timer);
getLastCudaError("Kernel launch failed");
printf("Average time: %f ms (%i iterations)\n", sdkGetTimerValue(&timer) / (float)iterations, iterations);
sdkDeleteTimer(&timer);
sdkDeleteTimer(&timer);
}
////////////////////////////////////////////////////////////////////////////////
@@ -91,56 +101,51 @@ void computeEigenvaluesSmallMatrix(const InputData &input,
//! @param result handles to the necessary memory
//! @param mat_size matrix_size
////////////////////////////////////////////////////////////////////////////////
void initResultSmallMatrix(ResultDataSmall &result,
const unsigned int mat_size) {
result.mat_size_f = sizeof(float) * mat_size;
result.mat_size_ui = sizeof(unsigned int) * mat_size;
void initResultSmallMatrix(ResultDataSmall &result, const unsigned int mat_size)
{
result.mat_size_f = sizeof(float) * mat_size;
result.mat_size_ui = sizeof(unsigned int) * mat_size;
result.eigenvalues = (float *)malloc(result.mat_size_f);
result.eigenvalues = (float *)malloc(result.mat_size_f);
// helper variables
result.zero_f = (float *)malloc(result.mat_size_f);
result.zero_ui = (unsigned int *)malloc(result.mat_size_ui);
// helper variables
result.zero_f = (float *)malloc(result.mat_size_f);
result.zero_ui = (unsigned int *)malloc(result.mat_size_ui);
for (unsigned int i = 0; i < mat_size; ++i) {
result.zero_f[i] = 0.0f;
result.zero_ui[i] = 0;
for (unsigned int i = 0; i < mat_size; ++i) {
result.zero_f[i] = 0.0f;
result.zero_ui[i] = 0;
result.eigenvalues[i] = 0.0f;
}
result.eigenvalues[i] = 0.0f;
}
checkCudaErrors(cudaMalloc((void **)&result.g_left, result.mat_size_f));
checkCudaErrors(cudaMalloc((void **)&result.g_right, result.mat_size_f));
checkCudaErrors(cudaMalloc((void **)&result.g_left, result.mat_size_f));
checkCudaErrors(cudaMalloc((void **)&result.g_right, result.mat_size_f));
checkCudaErrors(
cudaMalloc((void **)&result.g_left_count, result.mat_size_ui));
checkCudaErrors(
cudaMalloc((void **)&result.g_right_count, result.mat_size_ui));
checkCudaErrors(cudaMalloc((void **)&result.g_left_count, result.mat_size_ui));
checkCudaErrors(cudaMalloc((void **)&result.g_right_count, result.mat_size_ui));
// initialize result memory
checkCudaErrors(cudaMemcpy(result.g_left, result.zero_f, result.mat_size_f,
cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_right, result.zero_f, result.mat_size_f,
cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_right_count, result.zero_ui,
result.mat_size_ui, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_left_count, result.zero_ui,
result.mat_size_ui, cudaMemcpyHostToDevice));
// initialize result memory
checkCudaErrors(cudaMemcpy(result.g_left, result.zero_f, result.mat_size_f, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_right, result.zero_f, result.mat_size_f, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_right_count, result.zero_ui, result.mat_size_ui, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(result.g_left_count, result.zero_ui, result.mat_size_ui, cudaMemcpyHostToDevice));
}
////////////////////////////////////////////////////////////////////////////////
//! Cleanup memory and variables for result for small matrices
//! @param result handle to variables
////////////////////////////////////////////////////////////////////////////////
void cleanupResultSmallMatrix(ResultDataSmall &result) {
freePtr(result.eigenvalues);
freePtr(result.zero_f);
freePtr(result.zero_ui);
void cleanupResultSmallMatrix(ResultDataSmall &result)
{
freePtr(result.eigenvalues);
freePtr(result.zero_f);
freePtr(result.zero_ui);
checkCudaErrors(cudaFree(result.g_left));
checkCudaErrors(cudaFree(result.g_right));
checkCudaErrors(cudaFree(result.g_left_count));
checkCudaErrors(cudaFree(result.g_right_count));
checkCudaErrors(cudaFree(result.g_left));
checkCudaErrors(cudaFree(result.g_right));
checkCudaErrors(cudaFree(result.g_left_count));
checkCudaErrors(cudaFree(result.g_right_count));
}
////////////////////////////////////////////////////////////////////////////////
@@ -151,32 +156,31 @@ void cleanupResultSmallMatrix(ResultDataSmall &result) {
//! @param mat_size matrix size
//! @param filename output filename
////////////////////////////////////////////////////////////////////////////////
void processResultSmallMatrix(const InputData &input,
void processResultSmallMatrix(const InputData &input,
const ResultDataSmall &result,
const unsigned int mat_size,
const char *filename) {
const unsigned int mat_size_f = sizeof(float) * mat_size;
const unsigned int mat_size_ui = sizeof(unsigned int) * mat_size;
const unsigned int mat_size,
const char *filename)
{
const unsigned int mat_size_f = sizeof(float) * mat_size;
const unsigned int mat_size_ui = sizeof(unsigned int) * mat_size;
// copy data back to host
float *left = (float *)malloc(mat_size_f);
unsigned int *left_count = (unsigned int *)malloc(mat_size_ui);
// copy data back to host
float *left = (float *)malloc(mat_size_f);
unsigned int *left_count = (unsigned int *)malloc(mat_size_ui);
checkCudaErrors(
cudaMemcpy(left, result.g_left, mat_size_f, cudaMemcpyDeviceToHost));
checkCudaErrors(cudaMemcpy(left_count, result.g_left_count, mat_size_ui,
cudaMemcpyDeviceToHost));
checkCudaErrors(cudaMemcpy(left, result.g_left, mat_size_f, cudaMemcpyDeviceToHost));
checkCudaErrors(cudaMemcpy(left_count, result.g_left_count, mat_size_ui, cudaMemcpyDeviceToHost));
float *eigenvalues = (float *)malloc(mat_size_f);
float *eigenvalues = (float *)malloc(mat_size_f);
for (unsigned int i = 0; i < mat_size; ++i) {
eigenvalues[left_count[i]] = left[i];
}
for (unsigned int i = 0; i < mat_size; ++i) {
eigenvalues[left_count[i]] = left[i];
}
// save result in matlab format
writeTridiagSymMatlab(filename, input.a, input.b + 1, eigenvalues, mat_size);
// save result in matlab format
writeTridiagSymMatlab(filename, input.a, input.b + 1, eigenvalues, mat_size);
freePtr(left);
freePtr(left_count);
freePtr(eigenvalues);
freePtr(left);
freePtr(left_count);
freePtr(eigenvalues);
}

View File

@@ -30,51 +30,53 @@
#ifndef _BISECT_SMALL_CUH_
#define _BISECT_SMALL_CUH_
extern "C" {
extern "C"
{
////////////////////////////////////////////////////////////////////////////////
//! Determine eigenvalues for matrices smaller than MAX_SMALL_MATRIX
//! @param TimingIterations number of iterations for timing
//! @param input handles to input data of kernel
//! @param result handles to result of kernel
//! @param mat_size matrix size
//! @param lg lower limit of Gerschgorin interval
//! @param ug upper limit of Gerschgorin interval
//! @param precision desired precision of eigenvalues
//! @param iterations number of iterations for timing
////////////////////////////////////////////////////////////////////////////////
void computeEigenvaluesSmallMatrix(const InputData &input,
ResultDataSmall &result,
const unsigned int mat_size, const float lg,
const float ug, const float precision,
const unsigned int iterations);
////////////////////////////////////////////////////////////////////////////////
//! Determine eigenvalues for matrices smaller than MAX_SMALL_MATRIX
//! @param TimingIterations number of iterations for timing
//! @param input handles to input data of kernel
//! @param result handles to result of kernel
//! @param mat_size matrix size
//! @param lg lower limit of Gerschgorin interval
//! @param ug upper limit of Gerschgorin interval
//! @param precision desired precision of eigenvalues
//! @param iterations number of iterations for timing
////////////////////////////////////////////////////////////////////////////////
void computeEigenvaluesSmallMatrix(const InputData &input,
ResultDataSmall &result,
const unsigned int mat_size,
const float lg,
const float ug,
const float precision,
const unsigned int iterations);
////////////////////////////////////////////////////////////////////////////////
//! Initialize variables and memory for the result for small matrices
//! @param result handles to the necessary memory
//! @param mat_size matrix_size
////////////////////////////////////////////////////////////////////////////////
void initResultSmallMatrix(ResultDataSmall &result,
const unsigned int mat_size);
////////////////////////////////////////////////////////////////////////////////
//! Initialize variables and memory for the result for small matrices
//! @param result handles to the necessary memory
//! @param mat_size matrix_size
////////////////////////////////////////////////////////////////////////////////
void initResultSmallMatrix(ResultDataSmall &result, const unsigned int mat_size);
////////////////////////////////////////////////////////////////////////////////
//! Cleanup memory and variables for result for small matrices
//! @param result handle to variables
////////////////////////////////////////////////////////////////////////////////
void cleanupResultSmallMatrix(ResultDataSmall &result);
////////////////////////////////////////////////////////////////////////////////
//! Cleanup memory and variables for result for small matrices
//! @param result handle to variables
////////////////////////////////////////////////////////////////////////////////
void cleanupResultSmallMatrix(ResultDataSmall &result);
////////////////////////////////////////////////////////////////////////////////
//! Process the result obtained on the device, that is transfer to host and
//! perform basic sanity checking
//! @param input handles to input data
//! @param result handles to result variables
//! @param mat_size matrix size
//! @param filename output filename
////////////////////////////////////////////////////////////////////////////////
void processResultSmallMatrix(const InputData &input,
const ResultDataSmall &result,
const unsigned int mat_size,
const char *filename);
////////////////////////////////////////////////////////////////////////////////
//! Process the result obtained on the device, that is transfer to host and
//! perform basic sanity checking
//! @param input handles to input data
//! @param result handles to result variables
//! @param mat_size matrix size
//! @param filename output filename
////////////////////////////////////////////////////////////////////////////////
void processResultSmallMatrix(const InputData &input,
const ResultDataSmall &result,
const unsigned int mat_size,
const char *filename);
}
#endif // #ifndef _BISECT_SMALL_CUH_
#endif // #ifndef _BISECT_SMALL_CUH_

View File

@@ -42,30 +42,32 @@ namespace cg = cooperative_groups;
//! Compute the next lower power of two of n
//! @param n number for which next higher power of two is sought
////////////////////////////////////////////////////////////////////////////////
__device__ inline int floorPow2(int n) {
// early out if already power of two
if (0 == (n & (n - 1))) {
return n;
}
__device__ inline int floorPow2(int n)
{
// early out if already power of two
if (0 == (n & (n - 1))) {
return n;
}
int exp;
frexp((float)n, &exp);
return (1 << (exp - 1));
int exp;
frexp((float)n, &exp);
return (1 << (exp - 1));
}
////////////////////////////////////////////////////////////////////////////////
//! Compute the next higher power of two of n
//! @param n number for which next higher power of two is sought
////////////////////////////////////////////////////////////////////////////////
__device__ inline int ceilPow2(int n) {
// early out if already power of two
if (0 == (n & (n - 1))) {
return n;
}
__device__ inline int ceilPow2(int n)
{
// early out if already power of two
if (0 == (n & (n - 1))) {
return n;
}
int exp;
frexp((float)n, &exp);
return (1 << exp);
int exp;
frexp((float)n, &exp);
return (1 << exp);
}
////////////////////////////////////////////////////////////////////////////////
@@ -74,16 +76,18 @@ __device__ inline int ceilPow2(int n) {
//! @param left left / lower limit of interval
//! @param right right / upper limit of interval
////////////////////////////////////////////////////////////////////////////////
__device__ inline float computeMidpoint(const float left, const float right) {
float mid;
__device__ inline float computeMidpoint(const float left, const float right)
{
float mid;
if (sign_f(left) == sign_f(right)) {
mid = left + (right - left) * 0.5f;
} else {
mid = (left + right) * 0.5f;
}
if (sign_f(left) == sign_f(right)) {
mid = left + (right - left) * 0.5f;
}
else {
mid = (left + right) * 0.5f;
}
return mid;
return mid;
}
////////////////////////////////////////////////////////////////////////////////
@@ -102,29 +106,37 @@ __device__ inline float computeMidpoint(const float left, const float right) {
//! @param precision desired precision for eigenvalues
////////////////////////////////////////////////////////////////////////////////
template <class S, class T>
__device__ void storeInterval(unsigned int addr, float *s_left, float *s_right,
T *s_left_count, T *s_right_count, float left,
float right, S left_count, S right_count,
float precision) {
s_left_count[addr] = left_count;
s_right_count[addr] = right_count;
__device__ void storeInterval(unsigned int addr,
float *s_left,
float *s_right,
T *s_left_count,
T *s_right_count,
float left,
float right,
S left_count,
S right_count,
float precision)
{
s_left_count[addr] = left_count;
s_right_count[addr] = right_count;
// check if interval converged
float t0 = abs(right - left);
float t1 = max(abs(left), abs(right)) * precision;
// check if interval converged
float t0 = abs(right - left);
float t1 = max(abs(left), abs(right)) * precision;
if (t0 <= max(MIN_ABS_INTERVAL, t1)) {
// compute mid point
float lambda = computeMidpoint(left, right);
if (t0 <= max(MIN_ABS_INTERVAL, t1)) {
// compute mid point
float lambda = computeMidpoint(left, right);
// mark as converged
s_left[addr] = lambda;
s_right[addr] = lambda;
} else {
// store current limits
s_left[addr] = left;
s_right[addr] = right;
}
// mark as converged
s_left[addr] = lambda;
s_right[addr] = lambda;
}
else {
// store current limits
s_left[addr] = left;
s_right[addr] = right;
}
}
////////////////////////////////////////////////////////////////////////////////
@@ -145,35 +157,42 @@ __device__ void storeInterval(unsigned int addr, float *s_left, float *s_right,
//! @param converged flag if the current thread is already converged (that
//! is count does not have to be computed)
////////////////////////////////////////////////////////////////////////////////
__device__ inline unsigned int computeNumSmallerEigenvals(
float *g_d, float *g_s, const unsigned int n, const float x,
const unsigned int tid, const unsigned int num_intervals_active, float *s_d,
float *s_s, unsigned int converged, cg::thread_block cta) {
float delta = 1.0f;
unsigned int count = 0;
__device__ inline unsigned int computeNumSmallerEigenvals(float *g_d,
float *g_s,
const unsigned int n,
const float x,
const unsigned int tid,
const unsigned int num_intervals_active,
float *s_d,
float *s_s,
unsigned int converged,
cg::thread_block cta)
{
float delta = 1.0f;
unsigned int count = 0;
cg::sync(cta);
cg::sync(cta);
// read data into shared memory
if (threadIdx.x < n) {
s_d[threadIdx.x] = *(g_d + threadIdx.x);
s_s[threadIdx.x] = *(g_s + threadIdx.x - 1);
}
cg::sync(cta);
// perform loop only for active threads
if ((tid < num_intervals_active) && (0 == converged)) {
// perform (optimized) Gaussian elimination to determine the number
// of eigenvalues that are smaller than n
for (unsigned int k = 0; k < n; ++k) {
delta = s_d[k] - x - (s_s[k] * s_s[k]) / delta;
count += (delta < 0) ? 1 : 0;
// read data into shared memory
if (threadIdx.x < n) {
s_d[threadIdx.x] = *(g_d + threadIdx.x);
s_s[threadIdx.x] = *(g_s + threadIdx.x - 1);
}
} // end if thread currently processing an interval
cg::sync(cta);
return count;
// perform loop only for active threads
if ((tid < num_intervals_active) && (0 == converged)) {
// perform (optimized) Gaussian elimination to determine the number
// of eigenvalues that are smaller than n
for (unsigned int k = 0; k < n; ++k) {
delta = s_d[k] - x - (s_s[k] * s_s[k]) / delta;
count += (delta < 0) ? 1 : 0;
}
} // end if thread currently processing an interval
return count;
}
////////////////////////////////////////////////////////////////////////////////
@@ -194,42 +213,49 @@ __device__ inline unsigned int computeNumSmallerEigenvals(
//! @param converged flag if the current thread is already converged (that
//! is count does not have to be computed)
////////////////////////////////////////////////////////////////////////////////
__device__ inline unsigned int computeNumSmallerEigenvalsLarge(
float *g_d, float *g_s, const unsigned int n, const float x,
const unsigned int tid, const unsigned int num_intervals_active, float *s_d,
float *s_s, unsigned int converged, cg::thread_block cta) {
float delta = 1.0f;
unsigned int count = 0;
__device__ inline unsigned int computeNumSmallerEigenvalsLarge(float *g_d,
float *g_s,
const unsigned int n,
const float x,
const unsigned int tid,
const unsigned int num_intervals_active,
float *s_d,
float *s_s,
unsigned int converged,
cg::thread_block cta)
{
float delta = 1.0f;
unsigned int count = 0;
unsigned int rem = n;
unsigned int rem = n;
// do until whole diagonal and superdiagonal has been loaded and processed
for (unsigned int i = 0; i < n; i += blockDim.x) {
cg::sync(cta);
// do until whole diagonal and superdiagonal has been loaded and processed
for (unsigned int i = 0; i < n; i += blockDim.x) {
cg::sync(cta);
// read new chunk of data into shared memory
if ((i + threadIdx.x) < n) {
s_d[threadIdx.x] = *(g_d + i + threadIdx.x);
s_s[threadIdx.x] = *(g_s + i + threadIdx.x - 1);
// read new chunk of data into shared memory
if ((i + threadIdx.x) < n) {
s_d[threadIdx.x] = *(g_d + i + threadIdx.x);
s_s[threadIdx.x] = *(g_s + i + threadIdx.x - 1);
}
cg::sync(cta);
if (tid < num_intervals_active) {
// perform (optimized) Gaussian elimination to determine the number
// of eigenvalues that are smaller than n
for (unsigned int k = 0; k < min(rem, blockDim.x); ++k) {
delta = s_d[k] - x - (s_s[k] * s_s[k]) / delta;
// delta = (abs( delta) < (1.0e-10)) ? -(1.0e-10) : delta;
count += (delta < 0) ? 1 : 0;
}
} // end if thread currently processing an interval
rem -= blockDim.x;
}
cg::sync(cta);
if (tid < num_intervals_active) {
// perform (optimized) Gaussian elimination to determine the number
// of eigenvalues that are smaller than n
for (unsigned int k = 0; k < min(rem, blockDim.x); ++k) {
delta = s_d[k] - x - (s_s[k] * s_s[k]) / delta;
// delta = (abs( delta) < (1.0e-10)) ? -(1.0e-10) : delta;
count += (delta < 0) ? 1 : 0;
}
} // end if thread currently processing an interval
rem -= blockDim.x;
}
return count;
return count;
}
////////////////////////////////////////////////////////////////////////////////
@@ -258,39 +284,51 @@ __device__ inline unsigned int computeNumSmallerEigenvalsLarge(
//! @is_active_interval mark is thread has a second non-empty child interval
////////////////////////////////////////////////////////////////////////////////
template <class S, class T>
__device__ void storeNonEmptyIntervals(
unsigned int addr, const unsigned int num_threads_active, float *s_left,
float *s_right, T *s_left_count, T *s_right_count, float left, float mid,
float right, const S left_count, const S mid_count, const S right_count,
float precision, unsigned int &compact_second_chunk,
T *s_compaction_list_exc, unsigned int &is_active_second) {
// check if both child intervals are valid
if ((left_count != mid_count) && (mid_count != right_count)) {
// store the left interval
storeInterval(addr, s_left, s_right, s_left_count, s_right_count, left, mid,
left_count, mid_count, precision);
__device__ void storeNonEmptyIntervals(unsigned int addr,
const unsigned int num_threads_active,
float *s_left,
float *s_right,
T *s_left_count,
T *s_right_count,
float left,
float mid,
float right,
const S left_count,
const S mid_count,
const S right_count,
float precision,
unsigned int &compact_second_chunk,
T *s_compaction_list_exc,
unsigned int &is_active_second)
{
// check if both child intervals are valid
if ((left_count != mid_count) && (mid_count != right_count)) {
// store the left interval
storeInterval(addr, s_left, s_right, s_left_count, s_right_count, left, mid, left_count, mid_count, precision);
// mark that a second interval has been generated, only stored after
// stream compaction of second chunk
is_active_second = 1;
s_compaction_list_exc[threadIdx.x] = 1;
atomicExch(&compact_second_chunk, 1);
} else {
// only one non-empty child interval
// mark that no second child
is_active_second = 0;
s_compaction_list_exc[threadIdx.x] = 0;
// store the one valid child interval
if (left_count != mid_count) {
storeInterval(addr, s_left, s_right, s_left_count, s_right_count, left,
mid, left_count, mid_count, precision);
} else {
storeInterval(addr, s_left, s_right, s_left_count, s_right_count, mid,
right, mid_count, right_count, precision);
// mark that a second interval has been generated, only stored after
// stream compaction of second chunk
is_active_second = 1;
s_compaction_list_exc[threadIdx.x] = 1;
atomicExch(&compact_second_chunk, 1);
}
else {
// only one non-empty child interval
// mark that no second child
is_active_second = 0;
s_compaction_list_exc[threadIdx.x] = 0;
// store the one valid child interval
if (left_count != mid_count) {
storeInterval(
addr, s_left, s_right, s_left_count, s_right_count, left, mid, left_count, mid_count, precision);
}
else {
storeInterval(
addr, s_left, s_right, s_left_count, s_right_count, mid, right, mid_count, right_count, precision);
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
//! Create indices for compaction, that is process \a s_compaction_list_exc
@@ -303,42 +341,40 @@ __device__ void storeNonEmptyIntervals(
//! @param num_threads_compaction number of threads to employ for compaction
////////////////////////////////////////////////////////////////////////////////
template <class T>
__device__ void createIndicesCompaction(T *s_compaction_list_exc,
unsigned int num_threads_compaction,
cg::thread_block cta) {
unsigned int offset = 1;
const unsigned int tid = threadIdx.x;
__device__ void
createIndicesCompaction(T *s_compaction_list_exc, unsigned int num_threads_compaction, cg::thread_block cta)
{
unsigned int offset = 1;
const unsigned int tid = threadIdx.x;
// higher levels of scan tree
for (int d = (num_threads_compaction >> 1); d > 0; d >>= 1) {
cg::sync(cta);
// higher levels of scan tree
for (int d = (num_threads_compaction >> 1); d > 0; d >>= 1) {
cg::sync(cta);
if (tid < d) {
unsigned int ai = offset * (2 * tid + 1) - 1;
unsigned int bi = offset * (2 * tid + 2) - 1;
if (tid < d) {
unsigned int ai = offset * (2 * tid + 1) - 1;
unsigned int bi = offset * (2 * tid + 2) - 1;
s_compaction_list_exc[bi] =
s_compaction_list_exc[bi] + s_compaction_list_exc[ai];
s_compaction_list_exc[bi] = s_compaction_list_exc[bi] + s_compaction_list_exc[ai];
}
offset <<= 1;
}
offset <<= 1;
}
// traverse down tree: first down to level 2 across
for (int d = 2; d < num_threads_compaction; d <<= 1) {
offset >>= 1;
cg::sync(cta);
// traverse down tree: first down to level 2 across
for (int d = 2; d < num_threads_compaction; d <<= 1) {
offset >>= 1;
cg::sync(cta);
if (tid < (d - 1)) {
unsigned int ai = offset * (tid + 1) - 1;
unsigned int bi = ai + (offset >> 1);
if (tid < (d - 1)) {
unsigned int ai = offset * (tid + 1) - 1;
unsigned int bi = ai + (offset >> 1);
s_compaction_list_exc[bi] =
s_compaction_list_exc[bi] + s_compaction_list_exc[ai];
s_compaction_list_exc[bi] = s_compaction_list_exc[bi] + s_compaction_list_exc[ai];
}
}
}
cg::sync(cta);
cg::sync(cta);
}
///////////////////////////////////////////////////////////////////////////////
@@ -359,24 +395,30 @@ __device__ void createIndicesCompaction(T *s_compaction_list_exc,
//! @is_active_interval mark is thread has a second non-empty child interval
///////////////////////////////////////////////////////////////////////////////
template <class T>
__device__ void compactIntervals(float *s_left, float *s_right, T *s_left_count,
T *s_right_count, float mid, float right,
__device__ void compactIntervals(float *s_left,
float *s_right,
T *s_left_count,
T *s_right_count,
float mid,
float right,
unsigned int mid_count,
unsigned int right_count, T *s_compaction_list,
unsigned int right_count,
T *s_compaction_list,
unsigned int num_threads_active,
unsigned int is_active_second) {
const unsigned int tid = threadIdx.x;
unsigned int is_active_second)
{
const unsigned int tid = threadIdx.x;
// perform compaction / copy data for all threads where the second
// child is not dead
if ((tid < num_threads_active) && (1 == is_active_second)) {
unsigned int addr_w = num_threads_active + s_compaction_list[tid];
// perform compaction / copy data for all threads where the second
// child is not dead
if ((tid < num_threads_active) && (1 == is_active_second)) {
unsigned int addr_w = num_threads_active + s_compaction_list[tid];
s_left[addr_w] = mid;
s_right[addr_w] = right;
s_left_count[addr_w] = mid_count;
s_right_count[addr_w] = right_count;
}
s_left[addr_w] = mid;
s_right[addr_w] = right;
s_left_count[addr_w] = mid_count;
s_right_count[addr_w] = right_count;
}
}
///////////////////////////////////////////////////////////////////////////////
@@ -401,86 +443,102 @@ __device__ void compactIntervals(float *s_left, float *s_right, T *s_left_count,
//! @param num_threads_active number of active threads / intervals
///////////////////////////////////////////////////////////////////////////////
template <class T, class S>
__device__ void storeIntervalConverged(float *s_left, float *s_right,
T *s_left_count, T *s_right_count,
float &left, float &mid, float &right,
S &left_count, S &mid_count,
S &right_count, T *s_compaction_list_exc,
unsigned int &compact_second_chunk,
const unsigned int num_threads_active) {
const unsigned int tid = threadIdx.x;
const unsigned int multiplicity = right_count - left_count;
__device__ void storeIntervalConverged(float *s_left,
float *s_right,
T *s_left_count,
T *s_right_count,
float &left,
float &mid,
float &right,
S &left_count,
S &mid_count,
S &right_count,
T *s_compaction_list_exc,
unsigned int &compact_second_chunk,
const unsigned int num_threads_active)
{
const unsigned int tid = threadIdx.x;
const unsigned int multiplicity = right_count - left_count;
// check multiplicity of eigenvalue
if (1 == multiplicity) {
// just re-store intervals, simple eigenvalue
s_left[tid] = left;
s_right[tid] = right;
s_left_count[tid] = left_count;
s_right_count[tid] = right_count;
// check multiplicity of eigenvalue
if (1 == multiplicity) {
// just re-store intervals, simple eigenvalue
s_left[tid] = left;
s_right[tid] = right;
s_left_count[tid] = left_count;
s_right_count[tid] = right_count;
// mark that no second child / clear
s_right_count[tid + num_threads_active] = 0;
s_compaction_list_exc[tid] = 0;
} else {
// number of eigenvalues after the split less than mid
mid_count = left_count + (multiplicity >> 1);
// mark that no second child / clear
s_right_count[tid + num_threads_active] = 0;
s_compaction_list_exc[tid] = 0;
}
else {
// number of eigenvalues after the split less than mid
mid_count = left_count + (multiplicity >> 1);
// store left interval
s_left[tid] = left;
s_right[tid] = right;
s_left_count[tid] = left_count;
s_right_count[tid] = mid_count;
// store left interval
s_left[tid] = left;
s_right[tid] = right;
s_left_count[tid] = left_count;
s_right_count[tid] = mid_count;
mid = left;
mid = left;
// mark that second child interval exists
s_right_count[tid + num_threads_active] = right_count;
s_compaction_list_exc[tid] = 1;
compact_second_chunk = 1;
}
// mark that second child interval exists
s_right_count[tid + num_threads_active] = right_count;
s_compaction_list_exc[tid] = 1;
compact_second_chunk = 1;
}
}
template <class T, class S>
__device__ void storeIntervalConverged(float *s_left, float *s_right,
T *s_left_count, T *s_right_count,
float &left, float &mid, float &right,
S &left_count, S &mid_count,
S &right_count, T *s_compaction_list_exc,
unsigned int &compact_second_chunk,
__device__ void storeIntervalConverged(float *s_left,
float *s_right,
T *s_left_count,
T *s_right_count,
float &left,
float &mid,
float &right,
S &left_count,
S &mid_count,
S &right_count,
T *s_compaction_list_exc,
unsigned int &compact_second_chunk,
const unsigned int num_threads_active,
unsigned int &is_active_second) {
const unsigned int tid = threadIdx.x;
const unsigned int multiplicity = right_count - left_count;
unsigned int &is_active_second)
{
const unsigned int tid = threadIdx.x;
const unsigned int multiplicity = right_count - left_count;
// check multiplicity of eigenvalue
if (1 == multiplicity) {
// just re-store intervals, simple eigenvalue
s_left[tid] = left;
s_right[tid] = right;
s_left_count[tid] = left_count;
s_right_count[tid] = right_count;
// check multiplicity of eigenvalue
if (1 == multiplicity) {
// just re-store intervals, simple eigenvalue
s_left[tid] = left;
s_right[tid] = right;
s_left_count[tid] = left_count;
s_right_count[tid] = right_count;
// mark that no second child / clear
is_active_second = 0;
s_compaction_list_exc[tid] = 0;
} else {
// number of eigenvalues after the split less than mid
mid_count = left_count + (multiplicity >> 1);
// mark that no second child / clear
is_active_second = 0;
s_compaction_list_exc[tid] = 0;
}
else {
// number of eigenvalues after the split less than mid
mid_count = left_count + (multiplicity >> 1);
// store left interval
s_left[tid] = left;
s_right[tid] = right;
s_left_count[tid] = left_count;
s_right_count[tid] = mid_count;
// store left interval
s_left[tid] = left;
s_right[tid] = right;
s_left_count[tid] = left_count;
s_right_count[tid] = mid_count;
mid = left;
mid = left;
// mark that second child interval exists
is_active_second = 1;
s_compaction_list_exc[tid] = 1;
compact_second_chunk = 1;
}
// mark that second child interval exists
is_active_second = 1;
s_compaction_list_exc[tid] = 1;
compact_second_chunk = 1;
}
}
///////////////////////////////////////////////////////////////////////////////
@@ -501,29 +559,38 @@ __device__ void storeIntervalConverged(float *s_left, float *s_right,
//! converged
///////////////////////////////////////////////////////////////////////////////
template <class T>
__device__ void subdivideActiveInterval(
const unsigned int tid, float *s_left, float *s_right, T *s_left_count,
T *s_right_count, const unsigned int num_threads_active, float &left,
float &right, unsigned int &left_count, unsigned int &right_count,
float &mid, unsigned int &all_threads_converged) {
// for all active threads
if (tid < num_threads_active) {
left = s_left[tid];
right = s_right[tid];
left_count = s_left_count[tid];
right_count = s_right_count[tid];
__device__ void subdivideActiveInterval(const unsigned int tid,
float *s_left,
float *s_right,
T *s_left_count,
T *s_right_count,
const unsigned int num_threads_active,
float &left,
float &right,
unsigned int &left_count,
unsigned int &right_count,
float &mid,
unsigned int &all_threads_converged)
{
// for all active threads
if (tid < num_threads_active) {
left = s_left[tid];
right = s_right[tid];
left_count = s_left_count[tid];
right_count = s_right_count[tid];
// check if thread already converged
if (left != right) {
mid = computeMidpoint(left, right);
atomicExch(&all_threads_converged, 0);
} else if ((right_count - left_count) > 1) {
// mark as not converged if multiple eigenvalues enclosed
// duplicate interval in storeIntervalsConverged()
atomicExch(&all_threads_converged, 0);
}
// check if thread already converged
if (left != right) {
mid = computeMidpoint(left, right);
atomicExch(&all_threads_converged, 0);
}
else if ((right_count - left_count) > 1) {
// mark as not converged if multiple eigenvalues enclosed
// duplicate interval in storeIntervalsConverged()
atomicExch(&all_threads_converged, 0);
}
} // end for all active threads
} // end for all active threads
}
#endif // #ifndef _BISECT_UTIL_H_
#endif // #ifndef _BISECT_UTIL_H_

View File

@@ -33,9 +33,9 @@
// should be power of two
#define MAX_THREADS_BLOCK 256
#define MAX_SMALL_MATRIX 512
#define MAX_SMALL_MATRIX 512
#define MAX_THREADS_BLOCK_SMALL_MATRIX 512
#define MIN_ABS_INTERVAL 5.0e-37
#endif // #ifndef _CONFIG_H_
#endif // #ifndef _CONFIG_H_

View File

@@ -27,13 +27,15 @@
/* Computation of Gerschgorin interval for symmetric, tridiagonal matrix */
#include "gerschgorin.h"
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cfloat>
#include "util.h"
#include "gerschgorin.h"
////////////////////////////////////////////////////////////////////////////////
//! Compute Gerschgorin interval for symmetric, tridiagonal matrix
@@ -43,40 +45,40 @@
//! @param lg lower limit of Gerschgorin interval
//! @param ug upper limit of Gerschgorin interval
////////////////////////////////////////////////////////////////////////////////
void computeGerschgorin(float *d, float *s, unsigned int n, float &lg,
float &ug) {
lg = FLT_MAX;
ug = -FLT_MAX;
void computeGerschgorin(float *d, float *s, unsigned int n, float &lg, float &ug)
{
lg = FLT_MAX;
ug = -FLT_MAX;
// compute bounds
for (unsigned int i = 1; i < (n - 1); ++i) {
// sum over the absolute values of all elements of row i
float sum_abs_ni = fabsf(s[i - 1]) + fabsf(s[i]);
// compute bounds
for (unsigned int i = 1; i < (n - 1); ++i) {
// sum over the absolute values of all elements of row i
float sum_abs_ni = fabsf(s[i - 1]) + fabsf(s[i]);
lg = min(lg, d[i] - sum_abs_ni);
ug = max(ug, d[i] + sum_abs_ni);
}
lg = min(lg, d[i] - sum_abs_ni);
ug = max(ug, d[i] + sum_abs_ni);
}
// first and last row, only one superdiagonal element
// first and last row, only one superdiagonal element
// first row
lg = min(lg, d[0] - fabsf(s[0]));
ug = max(ug, d[0] + fabsf(s[0]));
// first row
lg = min(lg, d[0] - fabsf(s[0]));
ug = max(ug, d[0] + fabsf(s[0]));
// last row
lg = min(lg, d[n - 1] - fabsf(s[n - 2]));
ug = max(ug, d[n - 1] + fabsf(s[n - 2]));
// last row
lg = min(lg, d[n - 1] - fabsf(s[n - 2]));
ug = max(ug, d[n - 1] + fabsf(s[n - 2]));
// increase interval to avoid side effects of fp arithmetic
float bnorm = max(fabsf(ug), fabsf(lg));
// increase interval to avoid side effects of fp arithmetic
float bnorm = max(fabsf(ug), fabsf(lg));
// these values depend on the implementation of floating count that is
// employed in the following
float psi_0 = 11 * FLT_EPSILON * bnorm;
float psi_n = 11 * FLT_EPSILON * bnorm;
// these values depend on the implementation of floating count that is
// employed in the following
float psi_0 = 11 * FLT_EPSILON * bnorm;
float psi_n = 11 * FLT_EPSILON * bnorm;
lg = lg - bnorm * 2 * n * FLT_EPSILON - psi_0;
ug = ug + bnorm * 2 * n * FLT_EPSILON + psi_n;
lg = lg - bnorm * 2 * n * FLT_EPSILON - psi_0;
ug = ug + bnorm * 2 * n * FLT_EPSILON + psi_n;
ug = max(lg, ug);
ug = max(lg, ug);
}

View File

@@ -38,7 +38,6 @@
//! @param lg lower limit of Gerschgorin interval
//! @param ug upper limit of Gerschgorin interval
////////////////////////////////////////////////////////////////////////////////
extern "C" void computeGerschgorin(float *d, float *s, unsigned int n,
float &lg, float &ug);
extern "C" void computeGerschgorin(float *d, float *s, unsigned int n, float &lg, float &ug);
#endif // #ifndef _GERSCHGORIN_H_
#endif // #ifndef _GERSCHGORIN_H_

View File

@@ -30,24 +30,24 @@
*/
// includes, system
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <assert.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// includes, project
#include <helper_functions.h>
#include <helper_cuda.h>
#include "config.h"
#include "structs.h"
#include "matlab.h"
#include "util.h"
#include "gerschgorin.h"
#include <helper_functions.h>
#include "bisect_small.cuh"
#include "bisect_large.cuh"
#include "bisect_small.cuh"
#include "config.h"
#include "gerschgorin.h"
#include "matlab.h"
#include "structs.h"
#include "util.h"
////////////////////////////////////////////////////////////////////////////////
// declaration, forward
@@ -56,15 +56,16 @@ bool runTest(int argc, char **argv);
////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv) {
bool bQAResults = false;
int main(int argc, char **argv)
{
bool bQAResults = false;
printf("Starting eigenvalues\n");
printf("Starting eigenvalues\n");
bQAResults = runTest(argc, argv);
printf("Test %s\n", bQAResults ? "Succeeded!" : "Failed!");
bQAResults = runTest(argc, argv);
printf("Test %s\n", bQAResults ? "Succeeded!" : "Failed!");
exit(bQAResults ? EXIT_SUCCESS : EXIT_FAILURE);
exit(bQAResults ? EXIT_SUCCESS : EXIT_FAILURE);
}
////////////////////////////////////////////////////////////////////////////////
@@ -75,69 +76,67 @@ int main(int argc, char **argv) {
//! @param user_defined 1 if the matrix size has been requested by the user,
//! 0 if the default size
////////////////////////////////////////////////////////////////////////////////
void initInputData(InputData &input, char *exec_path,
const unsigned int mat_size,
const unsigned int user_defined) {
// allocate memory
input.a = (float *)malloc(sizeof(float) * mat_size);
input.b = (float *)malloc(sizeof(float) * mat_size);
void initInputData(InputData &input, char *exec_path, const unsigned int mat_size, const unsigned int user_defined)
{
// allocate memory
input.a = (float *)malloc(sizeof(float) * mat_size);
input.b = (float *)malloc(sizeof(float) * mat_size);
if (1 == user_defined) {
// initialize diagonal and superdiagonal entries with random values
srand(278217421);
if (1 == user_defined) {
// initialize diagonal and superdiagonal entries with random values
srand(278217421);
// srand( clock());
for (unsigned int i = 0; i < mat_size; ++i) {
input.a[i] = (float)(2.0 * (((double)rand() / (double)RAND_MAX) - 0.5));
input.b[i] = (float)(2.0 * (((double)rand() / (double)RAND_MAX) - 0.5));
// srand( clock());
for (unsigned int i = 0; i < mat_size; ++i) {
input.a[i] = (float)(2.0 * (((double)rand() / (double)RAND_MAX) - 0.5));
input.b[i] = (float)(2.0 * (((double)rand() / (double)RAND_MAX) - 0.5));
}
// the first element of s is used as padding on the device (thus the
// whole vector is copied to the device but the kernels are launched
// with (s+1) as start address
input.b[0] = 0.0f;
}
else {
// read default matrix
unsigned int input_data_size = mat_size;
char *diag_path = sdkFindFilePath("diagonal.dat", exec_path);
assert(NULL != diag_path);
sdkReadFile(diag_path, &(input.a), &input_data_size, false);
char *sdiag_path = sdkFindFilePath("superdiagonal.dat", exec_path);
assert(NULL != sdiag_path);
sdkReadFile(sdiag_path, &(input.b), &input_data_size, false);
free(diag_path);
free(sdiag_path);
}
// the first element of s is used as padding on the device (thus the
// whole vector is copied to the device but the kernels are launched
// with (s+1) as start address
input.b[0] = 0.0f;
} else {
// read default matrix
unsigned int input_data_size = mat_size;
char *diag_path = sdkFindFilePath("diagonal.dat", exec_path);
assert(NULL != diag_path);
sdkReadFile(diag_path, &(input.a), &input_data_size, false);
// allocate device memory for input
checkCudaErrors(cudaMalloc((void **)&(input.g_a), sizeof(float) * mat_size));
checkCudaErrors(cudaMalloc((void **)&(input.g_b_raw), sizeof(float) * mat_size));
char *sdiag_path = sdkFindFilePath("superdiagonal.dat", exec_path);
assert(NULL != sdiag_path);
sdkReadFile(sdiag_path, &(input.b), &input_data_size, false);
// copy data to device
checkCudaErrors(cudaMemcpy(input.g_a, input.a, sizeof(float) * mat_size, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(input.g_b_raw, input.b, sizeof(float) * mat_size, cudaMemcpyHostToDevice));
free(diag_path);
free(sdiag_path);
}
// allocate device memory for input
checkCudaErrors(cudaMalloc((void **)&(input.g_a), sizeof(float) * mat_size));
checkCudaErrors(
cudaMalloc((void **)&(input.g_b_raw), sizeof(float) * mat_size));
// copy data to device
checkCudaErrors(cudaMemcpy(input.g_a, input.a, sizeof(float) * mat_size,
cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy(input.g_b_raw, input.b, sizeof(float) * mat_size,
cudaMemcpyHostToDevice));
input.g_b = input.g_b_raw + 1;
input.g_b = input.g_b_raw + 1;
}
////////////////////////////////////////////////////////////////////////////////
//! Clean up input data, in particular allocated memory
//! @param input handles to the input data
////////////////////////////////////////////////////////////////////////////////
void cleanupInputData(InputData &input) {
freePtr(input.a);
freePtr(input.b);
void cleanupInputData(InputData &input)
{
freePtr(input.a);
freePtr(input.b);
checkCudaErrors(cudaFree(input.g_a));
input.g_a = NULL;
checkCudaErrors(cudaFree(input.g_b_raw));
input.g_b_raw = NULL;
input.g_b = NULL;
checkCudaErrors(cudaFree(input.g_a));
input.g_a = NULL;
checkCudaErrors(cudaFree(input.g_b_raw));
input.g_b_raw = NULL;
input.g_b = NULL;
}
////////////////////////////////////////////////////////////////////////////////
@@ -147,26 +146,26 @@ void cleanupInputData(InputData &input) {
//! @param matrix_size size of matrix, updated if specific size specified on
//! command line
////////////////////////////////////////////////////////////////////////////////
void getMatrixSize(int argc, char **argv, unsigned int &mat_size,
unsigned int &user_defined) {
int temp = -1;
void getMatrixSize(int argc, char **argv, unsigned int &mat_size, unsigned int &user_defined)
{
int temp = -1;
if (checkCmdLineFlag(argc, (const char **)argv, "matrix-size")) {
temp = getCmdLineArgumentInt(argc, (const char **)argv, "matrix-size");
}
if (checkCmdLineFlag(argc, (const char **)argv, "matrix-size")) {
temp = getCmdLineArgumentInt(argc, (const char **)argv, "matrix-size");
}
if (temp > 0) {
mat_size = (unsigned int)temp;
// data type short is used in the kernel
assert(mat_size < (1 << 16));
if (temp > 0) {
mat_size = (unsigned int)temp;
// data type short is used in the kernel
assert(mat_size < (1 << 16));
// mat_size should be large than 2
assert(mat_size >= 2);
// mat_size should be large than 2
assert(mat_size >= 2);
user_defined = 1;
}
user_defined = 1;
}
printf("Matrix size: %i x %i\n", mat_size, mat_size);
printf("Matrix size: %i x %i\n", mat_size, mat_size);
}
////////////////////////////////////////////////////////////////////////////////
@@ -178,21 +177,21 @@ void getMatrixSize(int argc, char **argv, unsigned int &mat_size,
//! @param user_defined 1 if the precision has been requested by the user,
//! 0 if the default size
////////////////////////////////////////////////////////////////////////////////
void getPrecision(int argc, char **argv, float &precision,
unsigned int &user_defined) {
float temp = -1.0f;
void getPrecision(int argc, char **argv, float &precision, unsigned int &user_defined)
{
float temp = -1.0f;
if (checkCmdLineFlag(argc, (const char **)argv, "precision")) {
temp = getCmdLineArgumentFloat(argc, (const char **)argv, "precision");
printf("Precision is between [0.001, 0.000001]\n");
}
if (checkCmdLineFlag(argc, (const char **)argv, "precision")) {
temp = getCmdLineArgumentFloat(argc, (const char **)argv, "precision");
printf("Precision is between [0.001, 0.000001]\n");
}
if (temp > 1e-6 && temp <= 0.001) {
precision = temp;
user_defined = 1;
}
if (temp > 1e-6 && temp <= 0.001) {
precision = temp;
user_defined = 1;
}
printf("Precision: %f\n", precision);
printf("Precision: %f\n", precision);
}
////////////////////////////////////////////////////////////////////////////////
@@ -202,18 +201,19 @@ void getPrecision(int argc, char **argv, float &precision,
//! @param iters_timing number of timing iterations, updated if user
//! specific value
////////////////////////////////////////////////////////////////////////////////
void getItersTiming(int argc, char **argv, unsigned int &iters_timing) {
int temp = -1;
void getItersTiming(int argc, char **argv, unsigned int &iters_timing)
{
int temp = -1;
if (checkCmdLineFlag(argc, (const char **)argv, "iters-timing")) {
temp = getCmdLineArgumentInt(argc, (const char **)argv, "iters-timing");
}
if (checkCmdLineFlag(argc, (const char **)argv, "iters-timing")) {
temp = getCmdLineArgumentInt(argc, (const char **)argv, "iters-timing");
}
if (temp > 0) {
iters_timing = temp;
}
if (temp > 0) {
iters_timing = temp;
}
printf("Iterations to be timed: %i\n", iters_timing);
printf("Iterations to be timed: %i\n", iters_timing);
}
////////////////////////////////////////////////////////////////////////////////
@@ -224,102 +224,102 @@ void getItersTiming(int argc, char **argv, unsigned int &iters_timing) {
//! @param filename filename of result file, updated if user specified
//! filename
////////////////////////////////////////////////////////////////////////////////
void getResultFilename(int argc, char **argv, char *&filename) {
char *temp = NULL;
getCmdLineArgumentString(argc, (const char **)argv, "filename-result", &temp);
void getResultFilename(int argc, char **argv, char *&filename)
{
char *temp = NULL;
getCmdLineArgumentString(argc, (const char **)argv, "filename-result", &temp);
if (NULL != temp) {
filename = (char *)malloc(sizeof(char) * strlen(temp));
strcpy(filename, temp);
if (NULL != temp) {
filename = (char *)malloc(sizeof(char) * strlen(temp));
strcpy(filename, temp);
free(temp);
}
free(temp);
}
printf("Result filename: '%s'\n", filename);
printf("Result filename: '%s'\n", filename);
}
////////////////////////////////////////////////////////////////////////////////
//! Run a simple test for CUDA
////////////////////////////////////////////////////////////////////////////////
bool runTest(int argc, char **argv) {
bool bCompareResult = false;
bool runTest(int argc, char **argv)
{
bool bCompareResult = false;
findCudaDevice(argc, (const char **)argv);
findCudaDevice(argc, (const char **)argv);
StopWatchInterface *timer = NULL;
StopWatchInterface *timer_total = NULL;
sdkCreateTimer(&timer);
sdkCreateTimer(&timer_total);
StopWatchInterface *timer = NULL;
StopWatchInterface *timer_total = NULL;
sdkCreateTimer(&timer);
sdkCreateTimer(&timer_total);
// default
unsigned int mat_size = 2048;
// flag if the matrix size is due to explicit user request
unsigned int user_defined = 0;
// desired precision of eigenvalues
float precision = 0.00001f;
unsigned int iters_timing = 100;
char *result_file = (char *)"eigenvalues.dat";
// default
unsigned int mat_size = 2048;
// flag if the matrix size is due to explicit user request
unsigned int user_defined = 0;
// desired precision of eigenvalues
float precision = 0.00001f;
unsigned int iters_timing = 100;
char *result_file = (char *)"eigenvalues.dat";
// check if there is a command line request for the matrix size
getMatrixSize(argc, argv, mat_size, user_defined);
// check if there is a command line request for the matrix size
getMatrixSize(argc, argv, mat_size, user_defined);
// check if user requested specific precision
getPrecision(argc, argv, precision, user_defined);
// check if user requested specific precision
getPrecision(argc, argv, precision, user_defined);
// check if user requested specific number of iterations for timing
getItersTiming(argc, argv, iters_timing);
// check if user requested specific number of iterations for timing
getItersTiming(argc, argv, iters_timing);
// file name for result file
getResultFilename(argc, argv, result_file);
// file name for result file
getResultFilename(argc, argv, result_file);
// set up input
InputData input;
initInputData(input, argv[0], mat_size, user_defined);
// set up input
InputData input;
initInputData(input, argv[0], mat_size, user_defined);
// compute Gerschgorin interval
float lg = FLT_MAX;
float ug = -FLT_MAX;
computeGerschgorin(input.a, input.b + 1, mat_size, lg, ug);
printf("Gerschgorin interval: %f / %f\n", lg, ug);
// compute Gerschgorin interval
float lg = FLT_MAX;
float ug = -FLT_MAX;
computeGerschgorin(input.a, input.b + 1, mat_size, lg, ug);
printf("Gerschgorin interval: %f / %f\n", lg, ug);
// two kernels, for small matrices a lot of overhead can be avoided
if (mat_size <= MAX_SMALL_MATRIX) {
// initialize memory for result
ResultDataSmall result;
initResultSmallMatrix(result, mat_size);
// two kernels, for small matrices a lot of overhead can be avoided
if (mat_size <= MAX_SMALL_MATRIX) {
// initialize memory for result
ResultDataSmall result;
initResultSmallMatrix(result, mat_size);
// run the kernel
computeEigenvaluesSmallMatrix(input, result, mat_size, lg, ug, precision,
iters_timing);
// run the kernel
computeEigenvaluesSmallMatrix(input, result, mat_size, lg, ug, precision, iters_timing);
// get the result from the device and do some sanity checks,
// save the result
processResultSmallMatrix(input, result, mat_size, result_file);
// get the result from the device and do some sanity checks,
// save the result
processResultSmallMatrix(input, result, mat_size, result_file);
// clean up
cleanupResultSmallMatrix(result);
// clean up
cleanupResultSmallMatrix(result);
printf("User requests non-default argument(s), skipping self-check!\n");
bCompareResult = true;
} else {
// initialize memory for result
ResultDataLarge result;
initResultDataLargeMatrix(result, mat_size);
printf("User requests non-default argument(s), skipping self-check!\n");
bCompareResult = true;
}
else {
// initialize memory for result
ResultDataLarge result;
initResultDataLargeMatrix(result, mat_size);
// run the kernel
computeEigenvaluesLargeMatrix(input, result, mat_size, precision, lg, ug,
iters_timing);
// run the kernel
computeEigenvaluesLargeMatrix(input, result, mat_size, precision, lg, ug, iters_timing);
// get the result from the device and do some sanity checks
// save the result if user specified matrix size
bCompareResult = processResultDataLargeMatrix(
input, result, mat_size, result_file, user_defined, argv[0]);
// get the result from the device and do some sanity checks
// save the result if user specified matrix size
bCompareResult = processResultDataLargeMatrix(input, result, mat_size, result_file, user_defined, argv[0]);
// cleanup
cleanupResultDataLargeMatrix(result);
}
// cleanup
cleanupResultDataLargeMatrix(result);
}
cleanupInputData(input);
cleanupInputData(input);
return bCompareResult;
return bCompareResult;
}

View File

@@ -26,20 +26,21 @@
*/
//! includes, system
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
// includes, projcet
#include "matlab.h"
// namespace, unnamed
namespace {} // end namespace, unnamed
namespace {
} // namespace
///////////////////////////////////////////////////////////////////////////////
//! Write a tridiagonal, symmetric matrix in vector representation and
@@ -52,18 +53,18 @@ namespace {} // end namespace, unnamed
//! if these are sorted in ascending order
//! @param n size of the matrix
///////////////////////////////////////////////////////////////////////////////
void writeTridiagSymMatlab(const char *filename, float *d, float *s,
float *eigenvals, const unsigned int n) {
std::ofstream file(filename, std::ios::out);
void writeTridiagSymMatlab(const char *filename, float *d, float *s, float *eigenvals, const unsigned int n)
{
std::ofstream file(filename, std::ios::out);
// write diagonal entries
writeVectorMatlab(file, "d", d, n);
// write diagonal entries
writeVectorMatlab(file, "d", d, n);
// write superdiagonal entries
writeVectorMatlab(file, "s", s, n - 1);
// write superdiagonal entries
writeVectorMatlab(file, "s", s, n - 1);
// write eigenvalues
writeVectorMatlab(file, "eigvals", eigenvals, n);
// write eigenvalues
writeVectorMatlab(file, "eigvals", eigenvals, n);
file.close();
file.close();
}

View File

@@ -26,17 +26,17 @@
*/
/* Header for utility functionality.
* Host code.
*/
* Host code.
*/
#ifndef _MATLAB_H_
#define _MATLAB_H_
// includes, system
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// includes, project
@@ -51,8 +51,7 @@
//! if these are sorted in ascending order
//! @param n size of the matrix
////////////////////////////////////////////////////////////////////////////////
extern "C" void writeTridiagSymMatlab(const char *filename, float *d, float *s,
float *eigenvals, const unsigned int n);
extern "C" void writeTridiagSymMatlab(const char *filename, float *d, float *s, float *eigenvals, const unsigned int n);
////////////////////////////////////////////////////////////////////////////////
//! Write matrix to a file in Matlab format
@@ -61,9 +60,7 @@ extern "C" void writeTridiagSymMatlab(const char *filename, float *d, float *s,
//! @param mat matrix to write to the file
//! @param mat_size size of the (square) matrix \a mat
////////////////////////////////////////////////////////////////////////////////
template <class T, class S>
void writeMatrixMatlab(T &file, const char *mat_name, S *&mat,
const unsigned int mat_size);
template <class T, class S> void writeMatrixMatlab(T &file, const char *mat_name, S *&mat, const unsigned int mat_size);
////////////////////////////////////////////////////////////////////////////////
//! Write vector to a file in Matlab format
@@ -72,9 +69,7 @@ void writeMatrixMatlab(T &file, const char *mat_name, S *&mat,
//! @param vec matrix to write to the file
//! @param vec_len length of the vector
////////////////////////////////////////////////////////////////////////////////
template <class T, class S>
void writeVectorMatlab(T &file, const char *vec_name, S *&vec,
const unsigned int vec_len);
template <class T, class S> void writeVectorMatlab(T &file, const char *vec_name, S *&vec, const unsigned int vec_len);
// implementations
@@ -85,24 +80,23 @@ void writeVectorMatlab(T &file, const char *vec_name, S *&vec,
//! @param mat matrix to write to the file
//! @param mat_size size of the (square) matrix \a mat
////////////////////////////////////////////////////////////////////////////////
template <class T, class S>
void writeMatrixMatlab(T &file, const char *mat_name, S *&mat,
const unsigned int mat_size) {
const unsigned int pitch = sizeof(S) * mat_size;
template <class T, class S> void writeMatrixMatlab(T &file, const char *mat_name, S *&mat, const unsigned int mat_size)
{
const unsigned int pitch = sizeof(S) * mat_size;
file << mat_name << " = [";
file << mat_name << " = [";
for (unsigned int i = 0; i < mat_size; ++i) {
for (unsigned int j = 0; j < mat_size; ++j) {
file << getMatrix(mat, pitch, i, j) << " ";
for (unsigned int i = 0; i < mat_size; ++i) {
for (unsigned int j = 0; j < mat_size; ++j) {
file << getMatrix(mat, pitch, i, j) << " ";
}
if (i != mat_size - 1) {
file << "; ";
}
}
if (i != mat_size - 1) {
file << "; ";
}
}
file << "];\n";
file << "];\n";
}
////////////////////////////////////////////////////////////////////////////////
@@ -112,16 +106,15 @@ void writeMatrixMatlab(T &file, const char *mat_name, S *&mat,
//! @param vec matrix to write to the file
//! @param vec_len length of the vector
////////////////////////////////////////////////////////////////////////////////
template <class T, class S>
void writeVectorMatlab(T &file, const char *vec_name, S *&vec,
const unsigned int vec_len) {
file << vec_name << " = [";
template <class T, class S> void writeVectorMatlab(T &file, const char *vec_name, S *&vec, const unsigned int vec_len)
{
file << vec_name << " = [";
for (unsigned int i = 0; i < vec_len; ++i) {
file << vec[i] << " ";
}
for (unsigned int i = 0; i < vec_len; ++i) {
file << vec[i] << " ";
}
file << "];\n";
file << "];\n";
}
#endif // _MATLAB_H_
#endif // _MATLAB_H_

View File

@@ -30,100 +30,103 @@
#ifndef _STRUCTS_H_
#define _STRUCTS_H_
struct InputData {
//! host side representation of diagonal
float *a;
//! host side representation superdiagonal
float *b;
struct InputData
{
//! host side representation of diagonal
float *a;
//! host side representation superdiagonal
float *b;
//! device side representation of diagonal
float *g_a;
//! device side representation of superdiagonal
float *g_b;
//! helper variable pointing to the mem allocated for g_b which provides
//! space for one additional element of padding at the beginning
float *g_b_raw;
//! device side representation of diagonal
float *g_a;
//! device side representation of superdiagonal
float *g_b;
//! helper variable pointing to the mem allocated for g_b which provides
//! space for one additional element of padding at the beginning
float *g_b_raw;
};
struct ResultDataSmall {
//! eigenvalues (host side)
float *eigenvalues;
struct ResultDataSmall
{
//! eigenvalues (host side)
float *eigenvalues;
// left interval limits at the end of the computation
float *g_left;
// left interval limits at the end of the computation
float *g_left;
// right interval limits at the end of the computation
float *g_right;
// right interval limits at the end of the computation
float *g_right;
// number of eigenvalues smaller than the left interval limit
unsigned int *g_left_count;
// number of eigenvalues smaller than the left interval limit
unsigned int *g_left_count;
// number of eigenvalues bigger than the right interval limit
unsigned int *g_right_count;
// number of eigenvalues bigger than the right interval limit
unsigned int *g_right_count;
//! flag if algorithm converged
unsigned int *g_converged;
//! flag if algorithm converged
unsigned int *g_converged;
// helper variables
// helper variables
unsigned int mat_size_f;
unsigned int mat_size_ui;
unsigned int mat_size_f;
unsigned int mat_size_ui;
float *zero_f;
unsigned int *zero_ui;
float *zero_f;
unsigned int *zero_ui;
};
struct ResultDataLarge {
// number of intervals containing one eigenvalue after the first step
unsigned int *g_num_one;
struct ResultDataLarge
{
// number of intervals containing one eigenvalue after the first step
unsigned int *g_num_one;
// number of (thread) blocks of intervals containing multiple eigenvalues
// after the first step
unsigned int *g_num_blocks_mult;
// number of (thread) blocks of intervals containing multiple eigenvalues
// after the first step
unsigned int *g_num_blocks_mult;
//! left interval limits of intervals containing one eigenvalue after the
//! first iteration step
float *g_left_one;
//! left interval limits of intervals containing one eigenvalue after the
//! first iteration step
float *g_left_one;
//! right interval limits of intervals containing one eigenvalue after the
//! first iteration step
float *g_right_one;
//! right interval limits of intervals containing one eigenvalue after the
//! first iteration step
float *g_right_one;
//! interval indices (position in sorted listed of eigenvalues)
//! of intervals containing one eigenvalue after the first iteration step
unsigned int *g_pos_one;
//! interval indices (position in sorted listed of eigenvalues)
//! of intervals containing one eigenvalue after the first iteration step
unsigned int *g_pos_one;
//! left interval limits of intervals containing multiple eigenvalues
//! after the first iteration step
float *g_left_mult;
//! left interval limits of intervals containing multiple eigenvalues
//! after the first iteration step
float *g_left_mult;
//! right interval limits of intervals containing multiple eigenvalues
//! after the first iteration step
float *g_right_mult;
//! right interval limits of intervals containing multiple eigenvalues
//! after the first iteration step
float *g_right_mult;
//! number of eigenvalues less than the left limit of the eigenvalue
//! intervals containing multiple eigenvalues
unsigned int *g_left_count_mult;
//! number of eigenvalues less than the left limit of the eigenvalue
//! intervals containing multiple eigenvalues
unsigned int *g_left_count_mult;
//! number of eigenvalues less than the right limit of the eigenvalue
//! intervals containing multiple eigenvalues
unsigned int *g_right_count_mult;
//! number of eigenvalues less than the right limit of the eigenvalue
//! intervals containing multiple eigenvalues
unsigned int *g_right_count_mult;
//! start addresses in g_left_mult etc. of blocks of intervals containing
//! more than one eigenvalue after the first step
unsigned int *g_blocks_mult;
//! start addresses in g_left_mult etc. of blocks of intervals containing
//! more than one eigenvalue after the first step
unsigned int *g_blocks_mult;
//! accumulated number of intervals in g_left_mult etc. of blocks of
//! intervals containing more than one eigenvalue after the first step
unsigned int *g_blocks_mult_sum;
//! accumulated number of intervals in g_left_mult etc. of blocks of
//! intervals containing more than one eigenvalue after the first step
unsigned int *g_blocks_mult_sum;
//! eigenvalues that have been generated in the second step from intervals
//! that still contained multiple eigenvalues after the first step
float *g_lambda_mult;
//! eigenvalues that have been generated in the second step from intervals
//! that still contained multiple eigenvalues after the first step
float *g_lambda_mult;
//! eigenvalue index of intervals that have been generated in the second
//! processing step
unsigned int *g_pos_mult;
//! eigenvalue index of intervals that have been generated in the second
//! processing step
unsigned int *g_pos_mult;
};
#endif // #ifndef _STRUCTS_H_
#endif // #ifndef _STRUCTS_H_

View File

@@ -33,12 +33,12 @@
////////////////////////////////////////////////////////////////////////////////
//! Safely free() for pointer
////////////////////////////////////////////////////////////////////////////////
template <class T>
inline void freePtr(T *&ptr) {
if (NULL != ptr) {
free(ptr);
ptr = NULL;
}
template <class T> inline void freePtr(T *&ptr)
{
if (NULL != ptr) {
free(ptr);
ptr = NULL;
}
}
////////////////////////////////////////////////////////////////////////////////
@@ -50,9 +50,10 @@ __host__
__device__
#endif
T
min(const T &lhs, const T &rhs) {
min(const T &lhs, const T &rhs)
{
return (lhs < rhs) ? lhs : rhs;
return (lhs < rhs) ? lhs : rhs;
}
////////////////////////////////////////////////////////////////////////////////
@@ -64,9 +65,10 @@ __host__
__device__
#endif
T
max(const T &lhs, const T &rhs) {
max(const T &lhs, const T &rhs)
{
return (lhs < rhs) ? rhs : lhs;
return (lhs < rhs) ? rhs : lhs;
}
////////////////////////////////////////////////////////////////////////////////
@@ -78,8 +80,9 @@ __host__
__device__
#endif
T
sign_i(const T &val) {
return (val < 0) ? -1 : 1;
sign_i(const T &val)
{
return (val < 0) ? -1 : 1;
}
////////////////////////////////////////////////////////////////////////////////
@@ -89,8 +92,9 @@ __host__
__host__ __device__
#endif
inline float
sign_f(const float &val) {
return (val < 0.0f) ? -1.0f : 1.0f;
sign_f(const float &val)
{
return (val < 0.0f) ? -1.0f : 1.0f;
}
////////////////////////////////////////////////////////////////////////////////
@@ -100,8 +104,9 @@ __host__ __device__
__host__ __device__
#endif
inline double
sign_d(const double &val) {
return (val < 0.0) ? -1.0 : 1.0;
sign_d(const double &val)
{
return (val < 0.0) ? -1.0 : 1.0;
}
////////////////////////////////////////////////////////////////////////////////
@@ -112,22 +117,22 @@ template <class T>
__host__ __device__
#endif
void
swap(T &lhs, T &rhs) {
swap(T &lhs, T &rhs)
{
T temp = rhs;
rhs = lhs;
lhs = temp;
T temp = rhs;
rhs = lhs;
lhs = temp;
}
///////////////////////////////////////////////////////////////////////////////
//! Get the number of blocks that are required to process \a num_threads with
//! \a num_threads_blocks threads per block
///////////////////////////////////////////////////////////////////////////////
extern "C" inline unsigned int getNumBlocksLinear(
const unsigned int num_threads, const unsigned int num_threads_block) {
const unsigned int block_rem =
((num_threads % num_threads_block) != 0) ? 1 : 0;
return (num_threads / num_threads_block) + block_rem;
extern "C" inline unsigned int getNumBlocksLinear(const unsigned int num_threads, const unsigned int num_threads_block)
{
const unsigned int block_rem = ((num_threads % num_threads_block) != 0) ? 1 : 0;
return (num_threads / num_threads_block) + block_rem;
}
#endif // #ifndef _UTIL_H_
#endif // #ifndef _UTIL_H_