diff --git a/example/Makefile b/example/Makefile index 702041a48230eed8a9d13c838b7dfd0567f8a8b2..d1208a0c640874fd1e5d4a2b3fe6bc31f1255eb0 100644 --- a/example/Makefile +++ b/example/Makefile @@ -11,6 +11,7 @@ OS = $(shell uname -s) ARCH = $(shell uname -m) ifeq ($(OS), Darwin) LDFLAGS += -framework OpenCL + LDFLAGS += -framework Accelerate else LDFLAGS += -L$(ATISTREAMSDKROOT)/lib/$(ARCH) LDFLAGS += -lOpenCL diff --git a/example/main.cpp b/example/main.cpp index 1cc290554f3cfe894b318a208da50734dfcad77f..112efdaeb6aa87d3eecc6e8bcd397679869c5112 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -50,10 +50,14 @@ #include <math.h> #include <stdio.h> #include <stdlib.h> -#include <OpenCL/opencl.h> -#include "clFFT.h" -#include <mach/mach_time.h> -#include <Accelerate/Accelerate.h> +#ifdef __APPLE__ + #include <OpenCL/cl.h> + #include <mach/mach_time.h> + #include <Accelerate/Accelerate.h> +#else + #include <CL/cl.h> +#endif +#include <clFFT.h> #include "procs.h" #include <sys/types.h> #include <sys/stat.h> @@ -87,6 +91,7 @@ cl_command_queue queue; typedef unsigned long long ulong; +#ifdef __APPLE__ double subtractTimes( uint64_t endTime, uint64_t startTime ) { uint64_t difference = endTime - startTime; @@ -104,7 +109,9 @@ double subtractTimes( uint64_t endTime, uint64_t startTime ) return conversion * (double) difference; } +#endif +#ifdef __APPLE__ void computeReferenceF(clFFT_SplitComplex *out, clFFT_Dim3 n, unsigned int batchSize, clFFT_Dimension dim, clFFT_Direction dir) { @@ -214,7 +221,9 @@ void computeReferenceF(clFFT_SplitComplex *out, clFFT_Dim3 n, vDSP_destroy_fftsetup(plan_vdsp); } +#endif +#ifdef __APPLE__ void computeReferenceD(clFFT_SplitComplexDouble *out, clFFT_Dim3 n, unsigned int batchSize, clFFT_Dimension dim, clFFT_Direction dir) { @@ -324,6 +333,7 @@ void computeReferenceD(clFFT_SplitComplexDouble *out, clFFT_Dim3 n, vDSP_destroy_fftsetupD(plan_vdsp); } +#endif double complexNormSq(clFFT_ComplexDouble a) { @@ -550,12 +560,14 @@ int runTest(clFFT_Dim3 n, int batchSize, clFFT_Direction dir, clFFT_Dimension di log_error("clFFT_Execute\n"); goto cleanup; } - + +#ifdef __APPLE__ t1 = mach_absolute_time(); t = subtractTimes(t1, t0); char temp[100]; 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); +#endif if(dataFormat == clFFT_SplitComplexFormat) { @@ -573,6 +585,7 @@ int runTest(clFFT_Dim3 n, int batchSize, clFFT_Direction dir, clFFT_Dimension di goto cleanup; } +#ifdef __APPLE__ computeReferenceD(&data_oref, n, batchSize, dim, dir); double diff_avg, diff_max, diff_min; @@ -597,7 +610,8 @@ int runTest(clFFT_Dim3 n, int batchSize, clFFT_Direction dir, clFFT_Dimension di free(result_split.real); free(result_split.imag); } - +#endif + cleanup: clFFT_DestroyPlan(plan); if(dataFormat == clFFT_SplitComplexFormat) @@ -726,7 +740,7 @@ int main (int argc, char * const argv[]) { } device_id = NULL; -/* + unsigned int i; for(i = 0; i < num_devices; i++) { @@ -763,8 +777,7 @@ int main (int argc, char * const argv[]) { test_finish(); return -1; } -*/ -device_id = device_ids[1]; + context = clCreateContext(0, 1, &device_id, NULL, NULL, &err); if(!context || err) { diff --git a/example/procs.h b/example/procs.h new file mode 100644 index 0000000000000000000000000000000000000000..f6028c9e5218900accc97fa3dddc19fed885e7df --- /dev/null +++ b/example/procs.h @@ -0,0 +1,53 @@ + +// +// 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() diff --git a/include/clFFT.h b/include/clFFT.h index 2c455939f2ac23b932f94186c1b7a1bd54270997..8dde2a4a91a84fea04256f306ca1362329ed0c61 100644 --- a/include/clFFT.h +++ b/include/clFFT.h @@ -49,13 +49,17 @@ #ifndef __CLFFT_H #define __CLFFT_H +#include <stdio.h> +#ifdef __APPLE__ + #include <OpenCL/cl.h> +#else + #include <CL/cl.h> +#endif + #ifdef __cplusplus extern "C" { #endif -#include <OpenCL/opencl.h> -#include <stdio.h> - // XForm type typedef enum {