diff options
| author | Tor Aamodt <[email protected]> | 2010-07-15 18:09:46 -0800 |
|---|---|---|
| committer | Tor Aamodt <[email protected]> | 2010-07-15 18:09:46 -0800 |
| commit | 69f2911e04ffb1b19eef1fafb8c040af271f656e (patch) | |
| tree | 231d3b6bdc3a202f7c255bfcf7bf2c36e32cee9e /benchmarks/CUDA/template | |
creating branch for adding support for CUDA 3.x and Fermi
[git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 6829]
Diffstat (limited to 'benchmarks/CUDA/template')
| -rw-r--r-- | benchmarks/CUDA/template/Makefile | 52 | ||||
| -rw-r--r-- | benchmarks/CUDA/template/template.cu | 156 | ||||
| -rw-r--r-- | benchmarks/CUDA/template/template_gold.cpp | 57 | ||||
| -rw-r--r-- | benchmarks/CUDA/template/template_kernel.cu | 79 |
4 files changed, 344 insertions, 0 deletions
diff --git a/benchmarks/CUDA/template/Makefile b/benchmarks/CUDA/template/Makefile new file mode 100644 index 0000000..3d4e5b9 --- /dev/null +++ b/benchmarks/CUDA/template/Makefile @@ -0,0 +1,52 @@ +################################################################################ +# +# Copyright 1993-2006 NVIDIA Corporation. All rights reserved. +# +# NOTICE TO USER: +# +# This source code is subject to NVIDIA ownership rights under U.S. and +# international Copyright laws. +# +# NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE +# CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR +# IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. +# IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, +# OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE +# OR PERFORMANCE OF THIS SOURCE CODE. +# +# U.S. Government End Users. This source code is a "commercial item" as +# that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of +# "commercial computer software" and "commercial computer software +# documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) +# and is provided to the U.S. Government only as a commercial end item. +# Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through +# 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the +# source code with only those rights set forth herein. +# +################################################################################ +# +# Build script for project +# +################################################################################ + +# Add source files here +EXECUTABLE := template +# CUDA source files (compiled with cudacc) +CUFILES := template.cu +# CUDA dependency files +CU_DEPS := \ + template_kernel.cu \ + +# C/C++ source files (compiled with gcc / c++) +CCFILES := \ + template_gold.cpp \ + + +################################################################################ +# Rules and targets + +include ../../../common/common.mk diff --git a/benchmarks/CUDA/template/template.cu b/benchmarks/CUDA/template/template.cu new file mode 100644 index 0000000..dd548c3 --- /dev/null +++ b/benchmarks/CUDA/template/template.cu @@ -0,0 +1,156 @@ +/* + * Copyright 1993-2007 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO USER: + * + * This source code is subject to NVIDIA ownership rights under U.S. and + * international Copyright laws. Users and possessors of this source code + * are hereby granted a nonexclusive, royalty-free license to use this code + * in individual and commercial software. + * + * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE + * CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR + * IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE + * OR PERFORMANCE OF THIS SOURCE CODE. + * + * U.S. Government End Users. This source code is a "commercial item" as + * that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of + * "commercial computer software" and "commercial computer software + * documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) + * and is provided to the U.S. Government only as a commercial end item. + * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through + * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the + * source code with only those rights set forth herein. + * + * Any use of this source code in individual and commercial software must + * include, in the user documentation and internal comments to the code, + * the above Disclaimer and U.S. Government End Users Notice. + */ + +/* Template project which demonstrates the basics on how to setup a project +* example application. +* Host code. +*/ + +// includes, system +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <math.h> + +// includes, project +#include <cutil_inline.h> + +// includes, kernels +#include <template_kernel.cu> + +//////////////////////////////////////////////////////////////////////////////// +// declaration, forward +void runTest( int argc, char** argv); + +extern "C" +void computeGold( float* reference, float* idata, const unsigned int len); + +//////////////////////////////////////////////////////////////////////////////// +// Program main +//////////////////////////////////////////////////////////////////////////////// +int +main( int argc, char** argv) +{ + runTest( argc, argv); + + cutilExit(argc, argv); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Run a simple test for CUDA +//////////////////////////////////////////////////////////////////////////////// +void +runTest( int argc, char** argv) +{ + // use command-line specified CUDA device, otherwise use device with highest Gflops/s + if( cutCheckCmdLineFlag(argc, (const char**)argv, "device") ) + cutilDeviceInit(argc, argv); + else + cudaSetDevice( cutGetMaxGflopsDeviceId() ); + + unsigned int timer = 0; + cutilCheckError( cutCreateTimer( &timer)); + cutilCheckError( cutStartTimer( timer)); + + unsigned int num_threads = 32; + unsigned int mem_size = sizeof( float) * num_threads; + + // allocate host memory + float* h_idata = (float*) malloc( mem_size); + // initalize the memory + for( unsigned int i = 0; i < num_threads; ++i) + { + h_idata[i] = (float) i; + } + + // allocate device memory + float* d_idata; + cutilSafeCall( cudaMalloc( (void**) &d_idata, mem_size)); + // copy host memory to device + cutilSafeCall( cudaMemcpy( d_idata, h_idata, mem_size, + cudaMemcpyHostToDevice) ); + + // allocate device memory for result + float* d_odata; + cutilSafeCall( cudaMalloc( (void**) &d_odata, mem_size)); + + // setup execution parameters + dim3 grid( 1, 1, 1); + dim3 threads( num_threads, 1, 1); + + // execute the kernel + testKernel<<< grid, threads, mem_size >>>( d_idata, d_odata); + + // check if kernel execution generated and error + cutilCheckMsg("Kernel execution failed"); + + // allocate mem for the result on host side + float* h_odata = (float*) malloc( mem_size); + // copy result from device to host + cutilSafeCall( cudaMemcpy( h_odata, d_odata, sizeof( float) * num_threads, + cudaMemcpyDeviceToHost) ); + + cutilCheckError( cutStopTimer( timer)); + printf( "Processing time: %f (ms)\n", cutGetTimerValue( timer)); + cutilCheckError( cutDeleteTimer( timer)); + + // compute reference solution + float* reference = (float*) malloc( mem_size); + computeGold( reference, h_idata, num_threads); + + // check result + if( cutCheckCmdLineFlag( argc, (const char**) argv, "regression")) + { + // write file for regression test + cutilCheckError( cutWriteFilef( "./data/regression.dat", + h_odata, num_threads, 0.0)); + } + else + { + // custom output handling when no regression test running + // in this case check if the result is equivalent to the expected soluion + CUTBoolean res = cutComparef( reference, h_odata, num_threads); + printf( "Test %s\n", (1 == res) ? "PASSED" : "FAILED"); + } + + // cleanup memory + free( h_idata); + free( h_odata); + free( reference); + cutilSafeCall(cudaFree(d_idata)); + cutilSafeCall(cudaFree(d_odata)); + + cudaThreadExit(); +} diff --git a/benchmarks/CUDA/template/template_gold.cpp b/benchmarks/CUDA/template/template_gold.cpp new file mode 100644 index 0000000..578daa3 --- /dev/null +++ b/benchmarks/CUDA/template/template_gold.cpp @@ -0,0 +1,57 @@ +/* + * Copyright 1993-2007 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO USER: + * + * This source code is subject to NVIDIA ownership rights under U.S. and + * international Copyright laws. Users and possessors of this source code + * are hereby granted a nonexclusive, royalty-free license to use this code + * in individual and commercial software. + * + * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE + * CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR + * IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE + * OR PERFORMANCE OF THIS SOURCE CODE. + * + * U.S. Government End Users. This source code is a "commercial item" as + * that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of + * "commercial computer software" and "commercial computer software + * documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) + * and is provided to the U.S. Government only as a commercial end item. + * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through + * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the + * source code with only those rights set forth herein. + * + * Any use of this source code in individual and commercial software must + * include, in the user documentation and internal comments to the code, + * the above Disclaimer and U.S. Government End Users Notice. + */ + +//////////////////////////////////////////////////////////////////////////////// +// export C interface +extern "C" +void computeGold( float* reference, float* idata, const unsigned int len); + +//////////////////////////////////////////////////////////////////////////////// +//! Compute reference data set +//! Each element is multiplied with the number of threads / array length +//! @param reference reference data, computed but preallocated +//! @param idata input data as provided to device +//! @param len number of elements in reference / idata +//////////////////////////////////////////////////////////////////////////////// +void +computeGold( float* reference, float* idata, const unsigned int len) +{ + const float f_len = static_cast<float>( len); + for( unsigned int i = 0; i < len; ++i) + { + reference[i] = idata[i] * f_len; + } +} + diff --git a/benchmarks/CUDA/template/template_kernel.cu b/benchmarks/CUDA/template/template_kernel.cu new file mode 100644 index 0000000..2e8f035 --- /dev/null +++ b/benchmarks/CUDA/template/template_kernel.cu @@ -0,0 +1,79 @@ +/* + * Copyright 1993-2007 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO USER: + * + * This source code is subject to NVIDIA ownership rights under U.S. and + * international Copyright laws. Users and possessors of this source code + * are hereby granted a nonexclusive, royalty-free license to use this code + * in individual and commercial software. + * + * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE + * CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR + * IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE + * OR PERFORMANCE OF THIS SOURCE CODE. + * + * U.S. Government End Users. This source code is a "commercial item" as + * that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of + * "commercial computer software" and "commercial computer software + * documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) + * and is provided to the U.S. Government only as a commercial end item. + * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through + * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the + * source code with only those rights set forth herein. + * + * Any use of this source code in individual and commercial software must + * include, in the user documentation and internal comments to the code, + * the above Disclaimer and U.S. Government End Users Notice. + */ + +/* Template project which demonstrates the basics on how to setup a project + * example application. + * Device code. + */ + +#ifndef _TEMPLATE_KERNEL_H_ +#define _TEMPLATE_KERNEL_H_ + +#include <stdio.h> + +#define SDATA( index) cutilBankChecker(sdata, index) + +//////////////////////////////////////////////////////////////////////////////// +//! Simple test kernel for device functionality +//! @param g_idata input data in global memory +//! @param g_odata output data in global memory +//////////////////////////////////////////////////////////////////////////////// +__global__ void +testKernel( float* g_idata, float* g_odata) +{ + // shared memory + // the size is determined by the host application + extern __shared__ float sdata[]; + + // access thread id + const unsigned int tid = threadIdx.x; + // access number of threads in this block + const unsigned int num_threads = blockDim.x; + + // read in input data from global memory + // use the bank checker macro to check for bank conflicts during host + // emulation + SDATA(tid) = g_idata[tid]; + __syncthreads(); + + // perform some computations + SDATA(tid) = (float) num_threads * SDATA( tid); + __syncthreads(); + + // write data to global memory + g_odata[tid] = SDATA(tid); +} + +#endif // #ifndef _TEMPLATE_KERNEL_H_ |
