From 93a64be21eb3746de0b96a2f2a365f59cd8f1bbc Mon Sep 17 00:00:00 2001 From: Tor Aamodt Date: Fri, 16 Jul 2010 11:59:09 -0800 Subject: - template runs/passes with CUDA 3.1, but requires that CUDA 2.3 is installed for math intrinsics used in instructions.cc (since CUDA 3.1 does not seem to define __uint2float). - currently cuda-math.h has hardcoded paths to my own install of CUDA 2.3 (need to determine whether we can build simulator with CUDA 2.3 and run CUDA 3.1 / compute_2x PTX, or need to make current setup more portable) - modified ptxinfo.l to print out meaningful error message if error occurs on first line - modified ptxinfo.l,y to understand "for 'compute_NN'" syntax - updated template to 3.1 SDK version - updated cuda_runtime_api.cc to select highest compute capability version when multiple versions are present. - updated template/BlackScholes Makefiles to generate a "DLL build" instead of static linked build (still confusing... requires one to copy config files... probably need to modify config scripts) [git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 6837] --- Makefile | 1 + benchmarks/CUDA/BlackScholes/Makefile | 5 +++- benchmarks/CUDA/template/Makefile | 4 ++- benchmarks/CUDA/template/template.cu | 42 ++++++++--------------------- benchmarks/CUDA/template/template_gold.cpp | 40 +++++++-------------------- benchmarks/CUDA/template/template_kernel.cu | 40 +++++++-------------------- libcuda/cuda_runtime_api.cc | 22 ++++++++++++--- src/cuda-sim/cuda-math.h | 23 ++++++---------- src/cuda-sim/cuda-sim.cc | 12 +++++++-- src/cuda-sim/ptxinfo.l | 12 ++++++--- src/cuda-sim/ptxinfo.y | 2 ++ 11 files changed, 87 insertions(+), 116 deletions(-) diff --git a/Makefile b/Makefile index 1ad3fc4..70d61d2 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,7 @@ lib/libcudart.so: $(LIBS) cudalib ./src/*.o -lm -lz -lGL \ -o lib/libcudart.so if [ ! -f lib/libcudart.so.2 ]; then ln -s libcudart.so lib/libcudart.so.2; fi + if [ ! -f lib/libcudart.so.3 ]; then ln -s libcudart.so lib/libcudart.so.3; fi lib/libcudart.dylib: $(LIBS) cudalib if [ ! -d lib ]; then mkdir lib; fi; diff --git a/benchmarks/CUDA/BlackScholes/Makefile b/benchmarks/CUDA/BlackScholes/Makefile index 0a628ac..36e244c 100644 --- a/benchmarks/CUDA/BlackScholes/Makefile +++ b/benchmarks/CUDA/BlackScholes/Makefile @@ -48,4 +48,7 @@ CUDACCFLAGS := -po maxrregcount=16 ################################################################################ # Rules and targets -include ../../../common/common.mk +ROOTDIR=$(NVIDIA_CUDA_SDK_LOCATION)/src +BINDIR=. +include $(NVIDIA_CUDA_SDK_LOCATION)/common/common.mk + diff --git a/benchmarks/CUDA/template/Makefile b/benchmarks/CUDA/template/Makefile index 3d4e5b9..a36bce5 100644 --- a/benchmarks/CUDA/template/Makefile +++ b/benchmarks/CUDA/template/Makefile @@ -49,4 +49,6 @@ CCFILES := \ ################################################################################ # Rules and targets -include ../../../common/common.mk +ROOTDIR=$(NVIDIA_CUDA_SDK_LOCATION)/src +BINDIR=. +include $(NVIDIA_CUDA_SDK_LOCATION)/common/common.mk diff --git a/benchmarks/CUDA/template/template.cu b/benchmarks/CUDA/template/template.cu index dd548c3..8a44200 100644 --- a/benchmarks/CUDA/template/template.cu +++ b/benchmarks/CUDA/template/template.cu @@ -1,36 +1,16 @@ /* - * Copyright 1993-2007 NVIDIA Corporation. All rights reserved. + * Copyright 1993-2010 NVIDIA Corporation. All rights reserved. * - * NOTICE TO USER: + * NVIDIA Corporation and its licensors retain all intellectual property and + * proprietary rights in and to this software and related documentation. + * Any use, reproduction, disclosure, or distribution of this software + * and related documentation without an express license agreement from + * NVIDIA Corporation is strictly prohibited. * - * 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. + * Please refer to the applicable NVIDIA end user license agreement (EULA) + * associated with this source code for terms and conditions that govern + * your use of this NVIDIA software. + * */ /* Template project which demonstrates the basics on how to setup a project @@ -142,7 +122,7 @@ runTest( int argc, char** argv) // 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"); + printf( "%s\n", (1 == res) ? "PASSED" : "FAILED"); } // cleanup memory diff --git a/benchmarks/CUDA/template/template_gold.cpp b/benchmarks/CUDA/template/template_gold.cpp index 578daa3..92a8045 100644 --- a/benchmarks/CUDA/template/template_gold.cpp +++ b/benchmarks/CUDA/template/template_gold.cpp @@ -1,36 +1,16 @@ /* - * Copyright 1993-2007 NVIDIA Corporation. All rights reserved. + * Copyright 1993-2010 NVIDIA Corporation. All rights reserved. * - * NOTICE TO USER: + * NVIDIA Corporation and its licensors retain all intellectual property and + * proprietary rights in and to this software and related documentation. + * Any use, reproduction, disclosure, or distribution of this software + * and related documentation without an express license agreement from + * NVIDIA Corporation is strictly prohibited. * - * 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. + * Please refer to the applicable NVIDIA end user license agreement (EULA) + * associated with this source code for terms and conditions that govern + * your use of this NVIDIA software. + * */ //////////////////////////////////////////////////////////////////////////////// diff --git a/benchmarks/CUDA/template/template_kernel.cu b/benchmarks/CUDA/template/template_kernel.cu index 2e8f035..f65507b 100644 --- a/benchmarks/CUDA/template/template_kernel.cu +++ b/benchmarks/CUDA/template/template_kernel.cu @@ -1,36 +1,16 @@ /* - * Copyright 1993-2007 NVIDIA Corporation. All rights reserved. + * Copyright 1993-2010 NVIDIA Corporation. All rights reserved. * - * NOTICE TO USER: + * NVIDIA Corporation and its licensors retain all intellectual property and + * proprietary rights in and to this software and related documentation. + * Any use, reproduction, disclosure, or distribution of this software + * and related documentation without an express license agreement from + * NVIDIA Corporation is strictly prohibited. * - * 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. + * Please refer to the applicable NVIDIA end user license agreement (EULA) + * associated with this source code for terms and conditions that govern + * your use of this NVIDIA software. + * */ /* Template project which demonstrates the basics on how to setup a project diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc index d17383d..6e562fe 100644 --- a/libcuda/cuda_runtime_api.cc +++ b/libcuda/cuda_runtime_api.cc @@ -188,7 +188,7 @@ extern struct cudaArray* gpgpu_ptx_sim_accessArrayofTexture(struct textureRefere extern void gpgpu_ptx_sim_bindNameToTexture(const char* name, const struct textureReference* texref); extern struct textureReference* gpgpu_ptx_sim_accessTextureofName(char* name); extern char* gpgpu_ptx_sim_findNamefromTexture(const struct textureReference* texref); -extern void gpgpu_ptx_sim_add_ptxstring( const char * ); +extern void gpgpu_ptx_sim_add_ptxstring( const char *ptx, const char *source_fname ); extern int g_ptx_sim_mode; @@ -1038,8 +1038,24 @@ void** CUDARTAPI __cudaRegisterFatBinary( void *fatCubin ) { #if (CUDART_VERSION >= 2010) __cudaFatCudaBinary *info = (__cudaFatCudaBinary *)fatCubin; - if (info->ptx->ptx) - gpgpu_ptx_sim_add_ptxstring( info->ptx->ptx ); + assert( info->version == 4 ); + unsigned num_ptx_versions=0; + unsigned max_capability=0; + unsigned selected_capability_offset=(unsigned)-1; + while( info->ptx[num_ptx_versions].gpuProfileName != NULL ) { + unsigned capability=0; + sscanf(info->ptx[num_ptx_versions].gpuProfileName,"compute_%u",&capability); + if( capability > max_capability ) { + max_capability = capability; + selected_capability_offset=num_ptx_versions; + } + num_ptx_versions++; + } + if ( selected_capability_offset != (unsigned)-1 ) { + printf("GPGPU-Sim PTX: __cudaRegisterFatBinary found %u PTX versions for '%s', ", num_ptx_versions, info->ident); + printf("selected = %s\n", info->ptx[selected_capability_offset].gpuProfileName ); + gpgpu_ptx_sim_add_ptxstring( info->ptx[selected_capability_offset].ptx, info->ident ); + } #endif return 0; } diff --git a/src/cuda-sim/cuda-math.h b/src/cuda-sim/cuda-math.h index ea7f5fd..5abf4f3 100644 --- a/src/cuda-sim/cuda-math.h +++ b/src/cuda-sim/cuda-math.h @@ -47,7 +47,6 @@ namespace cuda_math { #define __attribute__(a) // to remove warnings inside math_functions.h #undef INT_MAX -#if CUDART_VERSION < 3000 // DEVICE_BUILTIN struct int4 { int x, y, z, w; @@ -70,27 +69,21 @@ namespace cuda_math { typedef struct float2 float2; extern float rsqrtf(float); // CUDA 2.3 beta -#else -#define UINT_MAX ((unsigned int)-1) -#endif +#if CUDART_VERSION < 3000 #define CUDA_FLOAT_MATH_FUNCTIONS #include #define __CUDA_INTERNAL_COMPILATION__ -#if CUDART_VERSION >= 3000 -#define __CUDACC__ -#include -#else #include -#endif #undef __CUDA_INTERNAL_COMPILATION__ #undef __attribute__ - -#if CUDART_VERSION >= 3000 -#define __internal_float2int float2int -#define __internal_float2uint float2uint -#include -#define __internal_accurate_fdividef fdividef +#else +#define CUDA_FLOAT_MATH_FUNCTIONS +#include "/home/taamodt/nvcuda/2.3/cuda/include/device_types.h" +#define __CUDA_INTERNAL_COMPILATION__ +#include "/home/taamodt/nvcuda/2.3/cuda/include/math_functions.h" +#undef __CUDA_INTERNAL_COMPILATION__ +#undef __attribute__ #endif } diff --git a/src/cuda-sim/cuda-sim.cc b/src/cuda-sim/cuda-sim.cc index d691a64..4480221 100644 --- a/src/cuda-sim/cuda-sim.cc +++ b/src/cuda-sim/cuda-sim.cc @@ -1617,6 +1617,7 @@ static FILE *open_ptxinfo (const char* ptx_filename) struct ptx_info_t { char *str; + char *fname; ptx_info_t *next; }; @@ -1624,11 +1625,12 @@ ptx_info_t *g_ptx_source_array = NULL; unsigned g_used_embedded_ptx_files; extern double g_ptx_version; -void gpgpu_ptx_sim_add_ptxstring( const char *ptx_string ) +void gpgpu_ptx_sim_add_ptxstring( const char *ptx_string, const char *sourcefname ) { ptx_info_t *t = new ptx_info_t; t->next = NULL; t->str = strdup(ptx_string); + t->fname = strdup(sourcefname); // put ptx source into a fifo if (g_ptx_source_array == NULL) { @@ -1732,7 +1734,13 @@ void gpgpu_ptx_sim_load_ptx_from_string( const char *p, unsigned source_num ) char tempfile_ptxinfo[1024]; snprintf(tempfile_ptxinfo,1024,"%sinfo",fname); char commandline[1024]; - snprintf(commandline,1024,"ptxas -v %s --output-file /dev/null 2> %s", fname2, tempfile_ptxinfo); + char extra_flags[1024]; + extra_flags[0]=0; +#if CUDART_VERSION >= 3000 + snprintf(extra_flags,1024,"--gpu-name=sm_20"); +#endif + snprintf(commandline,1024,"ptxas %s -v %s --output-file /dev/null 2> %s", + extra_flags, fname2, tempfile_ptxinfo); printf("GPGPU-Sim PTX: generating ptxinfo using \"%s\"\n", commandline); result = system(commandline); if( result != 0 ) { diff --git a/src/cuda-sim/ptxinfo.l b/src/cuda-sim/ptxinfo.l index 3a2ab52..bec382b 100644 --- a/src/cuda-sim/ptxinfo.l +++ b/src/cuda-sim/ptxinfo.l @@ -67,9 +67,13 @@ #include "ptxinfo.tab.h" #include -char ptxinfo_linebuf[1024]; +#define LINEBUF_SIZE 1024 +char ptxinfo_linebuf[LINEBUF_SIZE]; unsigned ptxinfo_col = 0; -#define TC ptxinfo_col+=strlen(ptxinfo_text); +#define TC if( (ptxinfo_lineno == 1) && ((ptxinfo_col + strlen(ptxinfo_text)) < LINEBUF_SIZE) ) { \ + strncpy(ptxinfo_linebuf+ptxinfo_col,ptxinfo_text,strlen(ptxinfo_text)); \ + } \ + ptxinfo_col+=strlen(ptxinfo_text); %} %% @@ -85,6 +89,7 @@ unsigned ptxinfo_col = 0; "smem" TC; return SMEM; "cmem" TC; return CMEM; "line" TC; return LINE; +"for" TC; return FOR; [_A-Za-z$%][_0-9A-Za-z$]* TC; ptxinfo_lval.string_value = strdup(yytext); return IDENTIFIER; [-]{0,1}[0-9]+ TC; ptxinfo_lval.int_value = atoi(yytext); return INT_OPERAND; @@ -112,8 +117,9 @@ int ptxinfo_error( const char *s ) int i; g_ptxinfo_error_detected = 1; fflush(stdout); + printf("GPGPU-Sim: ERROR while parsing output of ptxas (used to capture resource usage information)\n"); if( s != NULL ) - printf("ptxas -v %s (%s:%u) Syntax error:\n\n", g_filename, g_ptxinfo_filename, ptxinfo_lineno ); + printf("GPGPU-Sim: %s (%s:%u) Syntax error:\n\n", g_filename, g_ptxinfo_filename, ptxinfo_lineno ); printf(" %s\n", ptxinfo_linebuf ); printf(" "); for( i=0; i < ptxinfo_col-1; i++ ) { diff --git a/src/cuda-sim/ptxinfo.y b/src/cuda-sim/ptxinfo.y index c9c84b8..6d2f7a7 100644 --- a/src/cuda-sim/ptxinfo.y +++ b/src/cuda-sim/ptxinfo.y @@ -86,6 +86,7 @@ %token QUOTE %token LINE %token WARNING +%token FOR %{ #include @@ -118,6 +119,7 @@ line_info: function_name ; function_name: FUNC QUOTE IDENTIFIER QUOTE { ptxinfo_function($3); } + | FUNC QUOTE IDENTIFIER QUOTE FOR QUOTE IDENTIFIER QUOTE { ptxinfo_function($3); } function_info: info | function_info COMMA info -- cgit v1.3