Skip to content
Snippets Groups Projects
Commit ca8932cf authored by Oliver Bock's avatar Oliver Bock
Browse files

Turning Apple-specific code into OS-independent implementation (tests pending)

parent c7ad9ac5
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ OS = $(shell uname -s) ...@@ -11,6 +11,7 @@ OS = $(shell uname -s)
ARCH = $(shell uname -m) ARCH = $(shell uname -m)
ifeq ($(OS), Darwin) ifeq ($(OS), Darwin)
LDFLAGS += -framework OpenCL LDFLAGS += -framework OpenCL
LDFLAGS += -framework Accelerate
else else
LDFLAGS += -L$(ATISTREAMSDKROOT)/lib/$(ARCH) LDFLAGS += -L$(ATISTREAMSDKROOT)/lib/$(ARCH)
LDFLAGS += -lOpenCL LDFLAGS += -lOpenCL
......
...@@ -50,10 +50,14 @@ ...@@ -50,10 +50,14 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <OpenCL/opencl.h> #ifdef __APPLE__
#include "clFFT.h" #include <OpenCL/cl.h>
#include <mach/mach_time.h> #include <mach/mach_time.h>
#include <Accelerate/Accelerate.h> #include <Accelerate/Accelerate.h>
#else
#include <CL/cl.h>
#endif
#include <clFFT.h>
#include "procs.h" #include "procs.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -87,6 +91,7 @@ cl_command_queue queue; ...@@ -87,6 +91,7 @@ cl_command_queue queue;
typedef unsigned long long ulong; typedef unsigned long long ulong;
#ifdef __APPLE__
double subtractTimes( uint64_t endTime, uint64_t startTime ) double subtractTimes( uint64_t endTime, uint64_t startTime )
{ {
uint64_t difference = endTime - startTime; uint64_t difference = endTime - startTime;
...@@ -104,7 +109,9 @@ double subtractTimes( uint64_t endTime, uint64_t startTime ) ...@@ -104,7 +109,9 @@ double subtractTimes( uint64_t endTime, uint64_t startTime )
return conversion * (double) difference; return conversion * (double) difference;
} }
#endif
#ifdef __APPLE__
void computeReferenceF(clFFT_SplitComplex *out, clFFT_Dim3 n, void computeReferenceF(clFFT_SplitComplex *out, clFFT_Dim3 n,
unsigned int batchSize, clFFT_Dimension dim, clFFT_Direction dir) unsigned int batchSize, clFFT_Dimension dim, clFFT_Direction dir)
{ {
...@@ -214,7 +221,9 @@ void computeReferenceF(clFFT_SplitComplex *out, clFFT_Dim3 n, ...@@ -214,7 +221,9 @@ void computeReferenceF(clFFT_SplitComplex *out, clFFT_Dim3 n,
vDSP_destroy_fftsetup(plan_vdsp); vDSP_destroy_fftsetup(plan_vdsp);
} }
#endif
#ifdef __APPLE__
void computeReferenceD(clFFT_SplitComplexDouble *out, clFFT_Dim3 n, void computeReferenceD(clFFT_SplitComplexDouble *out, clFFT_Dim3 n,
unsigned int batchSize, clFFT_Dimension dim, clFFT_Direction dir) unsigned int batchSize, clFFT_Dimension dim, clFFT_Direction dir)
{ {
...@@ -324,6 +333,7 @@ void computeReferenceD(clFFT_SplitComplexDouble *out, clFFT_Dim3 n, ...@@ -324,6 +333,7 @@ void computeReferenceD(clFFT_SplitComplexDouble *out, clFFT_Dim3 n,
vDSP_destroy_fftsetupD(plan_vdsp); vDSP_destroy_fftsetupD(plan_vdsp);
} }
#endif
double complexNormSq(clFFT_ComplexDouble a) double complexNormSq(clFFT_ComplexDouble a)
{ {
...@@ -551,11 +561,13 @@ int runTest(clFFT_Dim3 n, int batchSize, clFFT_Direction dir, clFFT_Dimension di ...@@ -551,11 +561,13 @@ int runTest(clFFT_Dim3 n, int batchSize, clFFT_Direction dir, clFFT_Dimension di
goto cleanup; goto cleanup;
} }
#ifdef __APPLE__
t1 = mach_absolute_time(); t1 = mach_absolute_time();
t = subtractTimes(t1, t0); t = subtractTimes(t1, t0);
char temp[100]; char temp[100];
sprintf(temp, "GFlops achieved for n = (%d, %d, %d), batchsize = %d", n.x, n.y, n.z, batchSize); sprintf(temp, "GFlops achieved for n = (%d, %d, %d), batchsize = %d", n.x, n.y, n.z, batchSize);
log_perf(gflops / (float) t, 1, "GFlops/s", "%s", temp); log_perf(gflops / (float) t, 1, "GFlops/s", "%s", temp);
#endif
if(dataFormat == clFFT_SplitComplexFormat) if(dataFormat == clFFT_SplitComplexFormat)
{ {
...@@ -573,6 +585,7 @@ int runTest(clFFT_Dim3 n, int batchSize, clFFT_Direction dir, clFFT_Dimension di ...@@ -573,6 +585,7 @@ int runTest(clFFT_Dim3 n, int batchSize, clFFT_Direction dir, clFFT_Dimension di
goto cleanup; goto cleanup;
} }
#ifdef __APPLE__
computeReferenceD(&data_oref, n, batchSize, dim, dir); computeReferenceD(&data_oref, n, batchSize, dim, dir);
double diff_avg, diff_max, diff_min; double diff_avg, diff_max, diff_min;
...@@ -597,6 +610,7 @@ int runTest(clFFT_Dim3 n, int batchSize, clFFT_Direction dir, clFFT_Dimension di ...@@ -597,6 +610,7 @@ int runTest(clFFT_Dim3 n, int batchSize, clFFT_Direction dir, clFFT_Dimension di
free(result_split.real); free(result_split.real);
free(result_split.imag); free(result_split.imag);
} }
#endif
cleanup: cleanup:
clFFT_DestroyPlan(plan); clFFT_DestroyPlan(plan);
...@@ -726,7 +740,7 @@ int main (int argc, char * const argv[]) { ...@@ -726,7 +740,7 @@ int main (int argc, char * const argv[]) {
} }
device_id = NULL; device_id = NULL;
/*
unsigned int i; unsigned int i;
for(i = 0; i < num_devices; i++) for(i = 0; i < num_devices; i++)
{ {
...@@ -763,8 +777,7 @@ int main (int argc, char * const argv[]) { ...@@ -763,8 +777,7 @@ int main (int argc, char * const argv[]) {
test_finish(); test_finish();
return -1; return -1;
} }
*/
device_id = device_ids[1];
context = clCreateContext(0, 1, &device_id, NULL, NULL, &err); context = clCreateContext(0, 1, &device_id, NULL, NULL, &err);
if(!context || err) if(!context || err)
{ {
......
//
// File: procs.h
//
// Version: <1.0>
//
// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple")
// in consideration of your agreement to the following terms, and your use,
// installation, modification or redistribution of this Apple software
// constitutes acceptance of these terms. If you do not agree with these
// terms, please do not use, install, modify or redistribute this Apple
// software.
//
// In consideration of your agreement to abide by the following terms, and
// subject to these terms, Apple grants you a personal, non - exclusive
// license, under Apple's copyrights in this original Apple software ( the
// "Apple Software" ), to use, reproduce, modify and redistribute the Apple
// Software, with or without modifications, in source and / or binary forms;
// provided that if you redistribute the Apple Software in its entirety and
// without modifications, you must retain this notice and the following text
// and disclaimers in all such redistributions of the Apple Software. Neither
// the name, trademarks, service marks or logos of Apple Inc. may be used to
// endorse or promote products derived from the Apple Software without specific
// prior written permission from Apple. Except as expressly stated in this
// notice, no other rights or licenses, express or implied, are granted by
// Apple herein, including but not limited to any patent rights that may be
// infringed by your derivative works or by other works in which the Apple
// Software may be incorporated.
//
// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION
// ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
//
// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION
// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER
// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR
// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright ( C ) 2008 Apple Inc. All Rights Reserved.
//
////////////////////////////////////////////////////////////////////////////////////////////////////
#define test_start()
#define log_perf(_number, _higherBetter, _numType, _format, ...) printf("Performance Number " _format " (in %s, %s): %g\n",##__VA_ARGS__, _numType, _higherBetter?"higher is better":"lower is better" , _number)
#define log_info printf
#define log_error printf
#define test_finish()
...@@ -49,13 +49,17 @@ ...@@ -49,13 +49,17 @@
#ifndef __CLFFT_H #ifndef __CLFFT_H
#define __CLFFT_H #define __CLFFT_H
#include <stdio.h>
#ifdef __APPLE__
#include <OpenCL/cl.h>
#else
#include <CL/cl.h>
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <OpenCL/opencl.h>
#include <stdio.h>
// XForm type // XForm type
typedef enum typedef enum
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment