|
@@ -80,22 +80,6 @@ convertInterleavedToSplitMatrix(Matrix const *interleaved, MatrixSplit *split)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static int
|
|
|
-getRandomData (Matrix *ret)
|
|
|
-{
|
|
|
- ret->width = 256;
|
|
|
- ret->height = 128;
|
|
|
- int size = ret->width * ret->height;
|
|
|
- ret->elements = (clFFT_Complex *) malloc(sizeof(clFFT_Complex)*size);
|
|
|
-
|
|
|
- for (int i = 0; i < size; ++i) {
|
|
|
- ret->elements[i].real = 2.f * (float) rand() / (float) RAND_MAX - 1.0;
|
|
|
- ret->elements[i].imag = 2.f * (float) rand() / (float) RAND_MAX - 1.0;
|
|
|
- }
|
|
|
-
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
// reads complex numbers from binary file stored in row major order
|
|
|
static int
|
|
|
getDataFromSplitBinary (FILE *f, Matrix *ret)
|
|
@@ -151,34 +135,6 @@ readFilterFromFile (int isSmooth, int n, float **filter, int *filterlength)
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-static void
|
|
|
-printMatrix (const Matrix A)
|
|
|
-{
|
|
|
- for (int i = 0; i < A.height; ++i) {
|
|
|
- printf ("|");
|
|
|
- for (int j = 0; j < A.width; ++j) {
|
|
|
- printf (" %4.1f + (%4.1f)i;",
|
|
|
- A.elements[i * A.width + j].real,
|
|
|
- A.elements[i * A.width + j].imag);
|
|
|
- }
|
|
|
- printf (" | \n");
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static void
|
|
|
-printMatrixToFile (FILE *f, const Matrix A)
|
|
|
-{
|
|
|
- for (int i = 0; i < A.height; ++i) {
|
|
|
- fprintf (f, "|");
|
|
|
- for (int j = 0; j < A.width; ++j) {
|
|
|
- fprintf (f, " %4.1f + (%4.1f)i;",
|
|
|
- A.elements[i * A.width + j].real,
|
|
|
- A.elements[i * A.width + j].imag);
|
|
|
- }
|
|
|
- fprintf (f, " | \n");
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
static void
|
|
|
writeSplitMatrixToBinaryFile(FILE *f, MatrixSplit * const matrix)
|
|
|
{
|
|
@@ -186,26 +142,6 @@ writeSplitMatrixToBinaryFile(FILE *f, MatrixSplit * const matrix)
|
|
|
fwrite (matrix->imags, sizeof (float), matrix->width * matrix->height, f);
|
|
|
}
|
|
|
|
|
|
-static void
|
|
|
-squaredDifferencesMatrix (Matrix * const A, Matrix * const B, Matrix *C)
|
|
|
-{
|
|
|
-
|
|
|
- assert (A->width == B->width && A->height == B->height);
|
|
|
- int size = A->width * A->height;
|
|
|
- C->width = A->width;
|
|
|
- C->height = A->height;
|
|
|
- C->elements = (clFFT_Complex *) malloc(sizeof(clFFT_Complex)*size);
|
|
|
-
|
|
|
- float absAsq = 0.f;
|
|
|
- float absBsq = 0.f;
|
|
|
- for (int i = 0; i < size; ++i)
|
|
|
- {
|
|
|
- absAsq = A->elements[i].real * A->elements[i].real + A->elements[i].imag * A->elements[i].imag;
|
|
|
- absBsq = B->elements[i].real * B->elements[i].real + B->elements[i].imag * B->elements[i].imag;
|
|
|
- C->elements[i].real = fabs(absAsq - absBsq);
|
|
|
- C->elements[i].imag = 0.f;
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
static void
|
|
|
tranformFromKSpace (Matrix *A, Matrix *result,
|
|
@@ -224,7 +160,6 @@ tranformFromKSpace (Matrix *A, Matrix *result,
|
|
|
|
|
|
unsigned long waitFFTShift[2];
|
|
|
unsigned long executionFFTShift[2];
|
|
|
- unsigned long totalFFTShift;
|
|
|
unsigned long computeAbsSpectrum;
|
|
|
unsigned long readFromDevice;
|
|
|
|
|
@@ -305,11 +240,9 @@ tranformFromKSpace (Matrix *A, Matrix *result,
|
|
|
get_event_times (event, &wait, &execution);
|
|
|
waitFFTShift[0] = wait;
|
|
|
executionFFTShift[0] = execution;
|
|
|
- printf("Swap x axis: \nwaited for device %lu us:\n time to execute: %lu us\n", wait, execution);
|
|
|
-
|
|
|
wallClock = g_timer_elapsed (timer, NULL);
|
|
|
|
|
|
- printf("took %e on host\n", wallClock);
|
|
|
+ printf("fftshift x axis took %e on host\n", wallClock);
|
|
|
|
|
|
// swap along y axis
|
|
|
dim = 1;
|
|
@@ -336,11 +269,10 @@ tranformFromKSpace (Matrix *A, Matrix *result,
|
|
|
get_event_times (event, &wait, &execution);
|
|
|
waitFFTShift[1] = wait;
|
|
|
executionFFTShift[1] = execution;
|
|
|
- printf("Swap y axis: \n waited for device %lu us:\n time to execute: %lu us\n", wait, execution);
|
|
|
|
|
|
wallClock = g_timer_elapsed (timer, NULL);
|
|
|
|
|
|
- printf("took %e on host\n", wallClock);
|
|
|
+ printf("fftshift y axis took %e on host\n", wallClock);
|
|
|
|
|
|
// power spectral density
|
|
|
i = 0;
|
|
@@ -356,7 +288,11 @@ tranformFromKSpace (Matrix *A, Matrix *result,
|
|
|
0, NULL, &event));
|
|
|
|
|
|
clWaitForEvents (1, &event);
|
|
|
+ g_timer_stop (timer);
|
|
|
+ get_event_times (event, &wait, &execution);
|
|
|
+ computeAbsSpectrum = execution;
|
|
|
|
|
|
+ g_timer_start (timer);
|
|
|
// Read C from device memory
|
|
|
errcode = clEnqueueReadBuffer (queue, d_C.elements, CL_TRUE, 0,
|
|
|
length * sizeof(float) * 2, result->elements,
|
|
@@ -364,9 +300,17 @@ tranformFromKSpace (Matrix *A, Matrix *result,
|
|
|
OCL_CHECK_ERROR (errcode);
|
|
|
clWaitForEvents (1, &event);
|
|
|
get_event_times (event, &wait, &execution);
|
|
|
- printf("Read out result \n waited for device %lu us:\n time to execute: %lu us\n", wait, execution);
|
|
|
readFromDevice = wait + execution;
|
|
|
|
|
|
+ wallClock = g_timer_elapsed (timer, NULL);
|
|
|
+
|
|
|
+
|
|
|
+ printf("%lu\n%lu\n%lu\n%lu\n%lu\n%lu\n",
|
|
|
+ waitFFTShift[0], waitFFTShift[1],
|
|
|
+ executionFFTShift[0], executionFFTShift[0],
|
|
|
+ computeAbsSpectrum,
|
|
|
+ readFromDevice);
|
|
|
+
|
|
|
g_timer_destroy (timer);
|
|
|
|
|
|
|
|
@@ -475,7 +419,6 @@ main (int argc, const char **argv)
|
|
|
// declare variable for OpenCL environment
|
|
|
OclPlatform *ocl;
|
|
|
cl_context context;
|
|
|
- cl_device_id *devices;
|
|
|
cl_command_queue *queues;
|
|
|
cl_int errcode;
|
|
|
|
|
@@ -487,8 +430,6 @@ main (int argc, const char **argv)
|
|
|
|
|
|
ocl = ocl_new_from_args (argc, argv, CL_QUEUE_PROFILING_ENABLE);
|
|
|
context = ocl_get_context (ocl);
|
|
|
-
|
|
|
- devices = ocl_get_devices (ocl);
|
|
|
queues = ocl_get_cmd_queues (ocl);
|
|
|
|
|
|
program = ocl_create_program_from_file (ocl, "ffthelp.cl", NULL, &errcode);
|
|
@@ -502,8 +443,6 @@ main (int argc, const char **argv)
|
|
|
|
|
|
//create Matrices
|
|
|
Matrix k_Space, decimk_Space, absimg;
|
|
|
- Matrix refImg;
|
|
|
- Matrix sqD;
|
|
|
|
|
|
FILE *bin = fopen ("ksd.bin", "r");
|
|
|
if (bin == NULL)
|