From b9e70e11ab34dbeed383ca145f1a79cfc0bfcc43 Mon Sep 17 00:00:00 2001 From: Tom Deakin Date: Thu, 28 Apr 2016 16:58:32 +0100 Subject: [PATCH] Add CMakeLists.txt file with CUDA and OCL builds --- CMakeLists.txt | 19 +++++++++++++++++++ src/main.cpp | 10 +++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5e1abd6 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ + +cmake_minimum_required(VERSION 2.8) + +project(gpu-stream) + +set(CMAKE_SOURCE_DIR src/) + +list(APPEND CMAKE_CXX_FLAGS --std=c++11) + +find_package(CUDA REQUIRED) + +cuda_add_executable(cuda.exe src/main.cpp src/CUDAStream.cu) +target_compile_definitions(cuda.exe PUBLIC CUDA) + +find_package(OpenCL) +add_executable(ocl.exe src/main.cpp src/OCLStream.cpp) +target_compile_definitions(ocl.exe PUBLIC OCL) +target_link_libraries(ocl.exe ${OpenCL_LIBRARY}) + diff --git a/src/main.cpp b/src/main.cpp index 39cfe86..008a6a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,7 +11,11 @@ #include "common.h" #include "Stream.h" +#if defined(CUDA) +#include "CUDAStream.h" +#elif defined(OCL) #include "OCLStream.h" +#endif const unsigned int ARRAY_SIZE = 52428800; @@ -45,12 +49,16 @@ void run() Stream *stream; +#if defined(CUDA) // Use the CUDA implementation - //stream = new CUDAStream(ARRAY_SIZE); + stream = new CUDAStream(ARRAY_SIZE); +#elif defined(OCL) // Use the OpenCL implementation stream = new OCLStream(ARRAY_SIZE); +#endif + stream->write_arrays(a, b, c); // List of times