diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index c60a46552..1bf83faa6 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -38,3 +38,41 @@ jobs: run: | echo "Built `ls bin/12.8/release | wc` Apps:" ls bin/12.8/release + + # The accel-sim org publishes no CUDA 13 image, so this job starts from the + # stock NVIDIA devel image and installs what the minimal image would have + # provided. 13.2 is the toolkit the Blackwell port was developed against. + test-13-2: + runs-on: ubuntu-latest + container: + image: nvidia/cuda:13.2.1-devel-ubuntu24.04 + env: + CUDA_INSTALL_PATH: /usr/local/cuda + BOOST_ROOT: /usr + DEBIAN_FRONTEND: noninteractive + + steps: + - name: Install build dependencies + run: | + apt-get update + apt-get install -y --no-install-recommends \ + build-essential cmake git ca-certificates libboost-dev zlib1g-dev \ + python3 + + - name: Checkout repository with submodules + uses: actions/checkout@v4 + with: + submodules: false + + - name: Build Apps + run: | + git config --global --add safe.directory /__w/gpu-app-collection/gpu-app-collection + git submodule update --init -- src/cuda/cuda-samples + git submodule update --init -- src/cuda/cutlass-bench + /bin/bash test-build.sh ci + + - name: Print Successful Apps + if: always() + run: | + echo "Built `ls bin/13.2/release | wc` Apps:" + ls bin/13.2/release diff --git a/.gitignore b/.gitignore index b729af5d6..4eb4ed874 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,16 @@ src/cuda/rodinia/3.1/cuda/nn/nn src/cuda/rodinia/3.1/cuda/particlefilter/particlefilter_float src/cuda/rodinia/3.1/cuda/particlefilter/particlefilter_naive src/cuda/rodinia/3.1/cuda/pathfinder/pathfinder +src/cuda/rodinia/3.1/cuda/huffman/pavle +src/cuda/rodinia/3.1/cuda/b+tree/b+tree.out +src/cuda/rodinia/3.1/cuda/dwt2d/dwt2d +src/cuda/rodinia/3.1/cuda/heartwall/heartwall +src/cuda/rodinia/3.1/cuda/hybridsort/hybridsort +src/cuda/rodinia/3.1/cuda/myocyte/myocyte.out +src/cuda/rodinia/3.1/cuda/hotspot3D/3D +src/cuda/rodinia/3.1/cuda/gaussian/gaussian +src/cuda/rodinia/3.1/cuda/srad/srad_v1/srad +src/cuda/rodinia/3.1/cuda/srad/srad_v2/srad 4.2 .venv/ __pycache__/ @@ -24,4 +34,4 @@ tmp/ src/cuda/GPU_Microbenchmark/ubench/**/* !src/cuda/GPU_Microbenchmark/ubench/**/*/ !src/cuda/GPU_Microbenchmark/ubench/**/*.* -!src/cuda/GPU_Microbenchmark/ubench/**/Makefile \ No newline at end of file +!src/cuda/GPU_Microbenchmark/ubench/**/Makefile diff --git a/src/.gitignore b/src/.gitignore index e95be6bd1..a11e1a5f9 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -23,6 +23,8 @@ cuda/ispass-2009/WP/wsm5_gpu.f.cu cuda/ispass-2009/WP/wsm5_gpu.f.cu.cpp.ii cuda/ispass-2009/WP-* 4.2/ +# built by setup_environment from the vendored sources alongside it +cuda/common/sdk-compat/lib/ cuda/lonestargpu-2.0/bin cuda/rodinia/3.1/cuda/huffman/pavle gpucomputingsdk_4.2.9_linux.run @@ -70,3 +72,9 @@ cuda/GPU_Microbenchmark/shared_bw/shared_bw cuda/GPU_Microbenchmark/shared_lat/shared_lat cuda/rodinia/3.1/cuda/leukocyte/meschach_lib/confdefs.h cuda/rodinia/3.1/cuda/leukocyte/meschach_lib/config.log + +# generated by running the benchmarks rather than building them +cuda/parboil/benchmarks/**/run/ +__pycache__/ +cuda/rodinia/3.1/cuda/kmeans/kmeans +cuda/rodinia/3.1/cuda/mummergpu/src/obj/ diff --git a/src/Makefile b/src/Makefile index a890d58f7..d51ce3d97 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,13 +1,13 @@ -ifeq ($(GPUAPPS_SETUP_ENVIRONMENT_WAS_RUN), 0) -$(error You must run "source setup_environment before calling make") +ifneq ($(GPUAPPS_SETUP_ENVIRONMENT_WAS_RUN),1) +$(error You must run "source setup_environment" before calling make) endif ifeq ($(CUDA_GT_7), 1) -all: GPU_Microbenchmark microbench rodinia_2.0-ft cutlass rodinia-3.1 pannotia proxy-apps ispass-2009 lonestargpu-2.0 polybench custom_apps heterosync cuda_samples mlperf_inference vllm huggingface # mlperf_training +all: GPU_Microbenchmark microbench rodinia_2.0-ft cutlass rodinia-3.1 pannotia proxy-apps ispass-2009 lonestargpu-2.0 polybench parboil custom_apps heterosync cuda_samples mlperf_inference vllm huggingface # mlperf_training else ifeq ($(CUDA_GT_4), 1) -all: pannotia rodinia_2.0-ft proxy-apps dragon-naive microbench rodinia-3.1 ispass-2009 dragon-cdp lonestargpu-2.0 polybench parboil shoc custom_apps +all: pannotia rodinia_2.0-ft proxy-apps microbench rodinia-3.1 ispass-2009 lonestargpu-2.0 polybench parboil shoc custom_apps else all: pannotia rodinia_2.0-ft proxy-apps microbench rodinia-3.1 ispass-2009 polybench parboil shoc custom_apps endif @@ -58,7 +58,7 @@ rodinia_2.0-ft: $(SETENV) $(MAKE) $(MAKE_ARGS) -C cuda/rodinia/2.0-ft/bfs $(SETENV) $(MAKE) $(MAKE_ARGS) -C cuda/rodinia/2.0-ft/heartwall $(SETENV) $(MAKE) $(MAKE_ARGS) -C cuda/rodinia/2.0-ft/hotspot -# $(SETENV) $(MAKE) $(MAKE_ARGS) -C cuda/rodinia/2.0-ft/kmeans + $(SETENV) $(MAKE) $(MAKE_ARGS) -C cuda/rodinia/2.0-ft/kmeans $(SETENV) $(MAKE) $(MAKE_ARGS) -C cuda/rodinia/2.0-ft/lud $(SETENV) $(MAKE) $(MAKE_ARGS) -C cuda/rodinia/2.0-ft/nn $(SETENV) $(MAKE) $(MAKE_ARGS) -C cuda/rodinia/2.0-ft/nw @@ -77,6 +77,9 @@ microbench: # Naive works wwith only SM_20 and above # Fro Dragon-cdp comilation, you need to ensure that you are using at least CUDA 5.5 ###################################################################################################3 +# NOTE: dragon-naive/dragon-cdp are omitted from "all" - dragon_li needs boost +# dev headers and only knows sm_20/35/50/61, all removed in CUDA 12/13. +# Still buildable explicitly via "make dragon-naive" once those are addressed. dragon-naive: chmod +x cuda/dragon_li/sconstruct if [ ${CUDA_VERSION_MAJOR} -lt 8 ]; then \ @@ -116,11 +119,14 @@ GPU_Microbenchmark_gmma: mv cuda/GPU_Microbenchmark/bin/* $(BINDIR)/$(BINSUBDIR)/ +# conv_bench and rnn_bench are disabled: they use 13 cuDNN APIs that cuDNN 9 +# removed (the whole v7 RNN path, plus the heuristic +# cudnnGetConvolution*Algorithm calls). Porting them changes which kernels +# the benchmarks actually run, so it needs a deliberate migration rather +# than a build fix. gemm_bench is unaffected. Deepbench_nvidia: - $(SETENV) $(MAKE) $(MAKE_ARGS) -C cuda/DeepBench/code/nvidia - cp -r cuda/DeepBench/code/nvidia/bin/conv_bench* $(BINDIR)/$(BINSUBDIR)/ + $(SETENV) make $(MAKE_ARGS) -C cuda/DeepBench/code/nvidia gemm cp -r cuda/DeepBench/code/nvidia/bin/gemm_bench* $(BINDIR)/$(BINSUBDIR)/ - cp -r cuda/DeepBench/code/nvidia/bin/rnn_bench* $(BINDIR)/$(BINSUBDIR)/ ###################################################################################################3 #pagerank and bc does not work with SM_10 because they need atomic_add @@ -149,6 +155,7 @@ pannotia: proxy-apps: chmod +x cuda/proxy-apps-doe/cns/compile.bash ($(SETENV) cd cuda/proxy-apps-doe/cns/ ; ./compile.bash) + cp cuda/proxy-apps-doe/cns/cns_all $(BINDIR)/$(BINSUBDIR)/ #chmod +x cuda/proxy-apps-doe/comd/cmd_compile.sh #( cd cuda/proxy-apps-doe/comd ; ./cmd_compile.sh) $(SETENV) $(MAKE) $(MAKE_ARGS) -C cuda/proxy-apps-doe/lulesh @@ -166,8 +173,9 @@ rodinia-3.1: $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/bfs -f Makefile_nvidia $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/cfd -f Makefile_nvidia $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/hotspot -f Makefile_nvidia -# All the texture binding stuff in this old workload seems to cause issues with the CUDA API -# $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/kmeans -f Makefile_nvidia +# The legacy texture-reference API was removed in CUDA 12; this kernel now uses +# texture objects and its gold check passes again. + $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/kmeans -f Makefile_nvidia $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/nw -f Makefile_nvidia $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/streamcluster -f Makefile_nvidia # $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/mummergpu @@ -187,32 +195,12 @@ rodinia-3.1: $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/gaussian $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/srad/srad_v1 $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/srad/srad_v2 -f Makefile_nvidia - if [ ${CUDA_VERSION_MAJOR} -gt 5 ]; then \ - mv cuda/rodinia/3.1/cuda/huffman/pavle $(BINDIR)/$(BINSUBDIR)/huffman-rodinia-3.1; \ - fi - mv cuda/rodinia/3.1/cuda/b+tree/b+tree.out $(BINDIR)/$(BINSUBDIR)/b+tree-rodinia-3.1 - mv cuda/rodinia/3.1/cuda/dwt2d/dwt2d $(BINDIR)/$(BINSUBDIR)/dwt2d-rodinia-3.1 - mv cuda/rodinia/3.1/cuda/heartwall/heartwall $(BINDIR)/$(BINSUBDIR)/heartwall-rodinia-3.1 +# These benchmarks now link straight into $(BINDIR)/$(BINSUBDIR) from their own +# Makefiles, so the post-build mv that used to relocate them is gone. # mv cuda/rodinia/3.1/cuda/hybridsort/hybridsort $(BINDIR)/$(BINSUBDIR)/hybridsort-rodinia-3.1 - mv cuda/rodinia/3.1/cuda/myocyte/myocyte.out $(BINDIR)/$(BINSUBDIR)/myocyte-rodinia-3.1 - mv cuda/rodinia/3.1/cuda/nn/nn $(BINDIR)/$(BINSUBDIR)/nn-rodinia-3.1 - mv cuda/rodinia/3.1/cuda/particlefilter/particlefilter_float $(BINDIR)/$(BINSUBDIR)/particlefilter_float-rodinia-3.1 - mv cuda/rodinia/3.1/cuda/particlefilter/particlefilter_naive $(BINDIR)/$(BINSUBDIR)/particlefilter_naive-rodinia-3.1 mv cuda/rodinia/3.1/cuda/pathfinder/pathfinder $(BINDIR)/$(BINSUBDIR)/pathfinder-rodinia-3.1 - mv cuda/rodinia/3.1/cuda/lavaMD/lavaMD $(BINDIR)/$(BINSUBDIR)/lavaMD-rodinia-3.1 - mv cuda/rodinia/3.1/cuda/lud/cuda/lud_cuda $(BINDIR)/$(BINSUBDIR)/lud-rodinia-3.1 # mv cuda/rodinia/3.1/cuda/leukocyte/CUDA/leukocyte $(BINDIR)/$(BINSUBDIR)/leukocyte-rodinia-3.1 - mv cuda/rodinia/3.1/cuda/hotspot3D/3D $(BINDIR)/$(BINSUBDIR)/hotspot3D-rodinia-3.1 - mv cuda/rodinia/3.1/cuda/gaussian/gaussian $(BINDIR)/$(BINSUBDIR)/gaussian-rodinia-3.1 - mv cuda/rodinia/3.1/cuda/srad/srad_v1/srad $(BINDIR)/$(BINSUBDIR)/srad_v1-rodinia-3.1 - mv $(BINDIR)/$(BINSUBDIR)/srad_v2 $(BINDIR)/$(BINSUBDIR)/srad_v2-rodinia-3.1 - mv $(BINDIR)/$(BINSUBDIR)/backprop $(BINDIR)/$(BINSUBDIR)/backprop-rodinia-3.1 - mv $(BINDIR)/$(BINSUBDIR)/bfs $(BINDIR)/$(BINSUBDIR)/bfs-rodinia-3.1 - mv $(BINDIR)/$(BINSUBDIR)/euler3d $(BINDIR)/$(BINSUBDIR)/cfd-rodinia-3.1 - mv $(BINDIR)/$(BINSUBDIR)/hotspot $(BINDIR)/$(BINSUBDIR)/hotspot-rodinia-3.1 # mv $(BINDIR)/$(BINSUBDIR)/kmeans $(BINDIR)/$(BINSUBDIR)/kmeans-rodinia-3.1 - mv $(BINDIR)/$(BINSUBDIR)/needle $(BINDIR)/$(BINSUBDIR)/nw-rodinia-3.1 - mv $(BINDIR)/$(BINSUBDIR)/streamcluster $(BINDIR)/$(BINSUBDIR)/streamcluster-rodinia-3.1 # mv $(BINDIR)/mummergpu $(BINDIR)/$(BINSUBDIR)/mummergpu-rodinia-3.1 rodinia-3.1_accelwattch_validation: @@ -223,9 +211,7 @@ rodinia-3.1_accelwattch_validation: $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/b+tree/ $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/pathfinder/ $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/rodinia/3.1/cuda/srad/srad_v1 - mv cuda/rodinia/3.1/cuda/b+tree/b+tree.out $(BINDIR)/$(BINSUBDIR)/b+tree-rodinia-3.1 mv cuda/rodinia/3.1/cuda/pathfinder/pathfinder $(BINDIR)/$(BINSUBDIR)/pathfinder-rodinia-3.1 - mv cuda/rodinia/3.1/cuda/srad/srad_v1/srad $(BINDIR)/$(BINSUBDIR)/srad_v1-rodinia-3.1 mv $(BINDIR)/$(BINSUBDIR)/backprop $(BINDIR)/$(BINSUBDIR)/backprop-rodinia-3.1 mv $(BINDIR)/$(BINSUBDIR)/hotspot $(BINDIR)/$(BINSUBDIR)/hotspot-rodinia-3.1 # mv $(BINDIR)/$(BINSUBDIR)/kmeans $(BINDIR)/$(BINSUBDIR)/kmeans-rodinia-3.1 @@ -299,14 +285,14 @@ cuda_samples-11.0_hw_power: ispass-2009: mkdir -p $(BINDIR)/$(BINSUBDIR) -# $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/ispass-2009/AES + $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/ispass-2009/AES $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/ispass-2009/BFS # cd CP; export PARBOIL_ROOT=`pwd`; cd common/src; $(MAKE) $(MAKE_ARGS); cd -; ./parboil compile cp cuda_short; cp benchmarks/cp/build/cuda_short/cp $(BINDIR)/$(BINSUBDIR)/CP # $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C DG/3rdParty/ParMetis-3.1 # $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C DG $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/ispass-2009/LIB $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/ispass-2009/LPS -# $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/ispass-2009/MUM + $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/ispass-2009/MUM $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/ispass-2009/NN $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/ispass-2009/NQU $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/ispass-2009/RAY @@ -318,7 +304,7 @@ lonestargpu-2.0: $(setenv) $(MAKE) $(make_args) noinline=$(noinline) -C cuda/lonestargpu-2.0 all mv cuda/lonestargpu-2.0/apps/bfs/bfs $(BINDIR)/$(BINSUBDIR)/lonestar-bfs mv cuda/lonestargpu-2.0/apps/bfs/bfs-atomic $(BINDIR)/$(BINSUBDIR)/lonestar-bfs-atomic -# mv cuda/lonestargpu-2.0/apps/bfs/bfs-wlc $(BINDIR)/$(BINSUBDIR)/lonestar-bfs-wlc + mv cuda/lonestargpu-2.0/apps/bfs/bfs-wlc $(BINDIR)/$(BINSUBDIR)/lonestar-bfs-wlc mv cuda/lonestargpu-2.0/apps/bfs/bfs-wla $(BINDIR)/$(BINSUBDIR)/lonestar-bfs-wla mv cuda/lonestargpu-2.0/apps/bfs/bfs-wlw $(BINDIR)/$(BINSUBDIR)/lonestar-bfs-wlw mv cuda/lonestargpu-2.0/apps/bh/bh $(BINDIR)/$(BINSUBDIR)/lonestar-bh @@ -327,7 +313,7 @@ lonestargpu-2.0: mv cuda/lonestargpu-2.0/apps/pta/pta $(BINDIR)/$(BINSUBDIR)/lonestar-pta mv cuda/lonestargpu-2.0/apps/sp/nsp $(BINDIR)/$(BINSUBDIR)/lonestar-nsp mv cuda/lonestargpu-2.0/apps/sssp/sssp $(BINDIR)/$(BINSUBDIR)/lonestar-sssp -# mv cuda/lonestargpu-2.0/apps/sssp/sssp-wlc $(BINDIR)/$(BINSUBDIR)/lonestar-sssp-wlc + mv cuda/lonestargpu-2.0/apps/sssp/sssp-wlc $(BINDIR)/$(BINSUBDIR)/lonestar-sssp-wlc mv cuda/lonestargpu-2.0/apps/sssp/sssp-wln $(BINDIR)/$(BINSUBDIR)/lonestar-sssp-wln parboil: @@ -433,19 +419,45 @@ clean_accelwattch_ubench: # $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C cuda/cudnn/mnist # cp cuda/cudnn/mnist/mnistCUDNN $(BINDIR)/$(BINSUBDIR)/ +# Keep only the architectures the installed toolkit actually accepts. One +# wish-list then works everywhere: CUDA 12.8 has no sm_103, CUDA 13 has no +# sm_50. The accelerated "a" variants are matched on their base number, so +# 90a survives wherever compute_90 does. +cutlass_supported = $(shell have=`nvcc --list-gpu-arch 2>/dev/null | sed -e 's/compute_//' | tr '\n' ' '`; \ + out=; for a in $(1); do b=`echo $$a | sed -e 's/[^0-9].*$$//'`; \ + if [ -z "$$have" ] || echo " $$have " | grep -q " $$b "; then out="$$out$${out:+;}$$a"; fi; \ + done; echo $$out) + +# Architectures to build CUTLASS for. Blackwell-era defaults: 100a covers +# GB100/B200, 103a covers GB300. Override on the command line to retarget, +# e.g. make cutlass CUTLASS_ARCHS="90a". +CUTLASS_ARCHS ?= $(call cutlass_supported,100a 103a) +# cutlass_mini builds the Hopper examples by name, so it needs 90a regardless +# of what the full build targets. This is the list `ci` has always used. +CUTLASS_MINI_ARCHS ?= $(call cutlass_supported,80 90 90a) +# CUTLASS generates thousands of kernels; a serial sub-make leaves most of the +# machine idle and takes days. Bounded at 32 to limit peak memory from nvcc. +CUTLASS_JOBS ?= $(shell n=$$(nproc 2>/dev/null || echo 8); [ $$n -gt 32 ] && echo 32 || echo $$n) +# Only examples 10/11 (planar complex) link cutlass_library, and they drag in +# the full generated kernel set: 56823 .cu files spanning sm_50..sm_103, of +# which 272 are the planar-complex kernels they actually use. Filter the +# library down to those so all 97 examples still build. +CUTLASS_LIBRARY_KERNELS ?= *planar_complex* + cutlass: mkdir -p $(BINDIR)/$(BINSUBDIR)/ git submodule init && git submodule update - mkdir -p cuda/cutlass/build - $(SETENV) cmake -S cuda/cutlass-bench -B cuda/cutlass-bench/build -DCUTLASS_NVCC_ARCHS="80;90;90a" -DCMAKE_CUDA_ARCHITECTURES="80;90;90a" -DCMAKE_CUDA_COMPILER=$(CUDA_INSTALL_PATH)/bin/nvcc - $(SETENV) $(MAKE) -C cuda/cutlass-bench/build/ cutlass_examples cutlass_profiler + $(SETENV) cmake -S cuda/cutlass-bench -B cuda/cutlass-bench/build -DCUTLASS_NVCC_ARCHS="$(CUTLASS_ARCHS)" -DCMAKE_CUDA_ARCHITECTURES="$(CUTLASS_ARCHS)" -DCUTLASS_LIBRARY_KERNELS="$(CUTLASS_LIBRARY_KERNELS)" -DCUTLASS_ENABLE_PROFILER=OFF -DCMAKE_CUDA_COMPILER=$(CUDA_INSTALL_PATH)/bin/nvcc +# Only cutlass_examples is built: the install step below copies from +# build/examples, so cutlass_profiler was compiled and then discarded. + $(SETENV) $(MAKE) -j$(CUTLASS_JOBS) -C cuda/cutlass-bench/build/ cutlass_examples find cuda/cutlass-bench/build/examples -type f -executable -exec sh -c 'cp "$$1" "$(BINDIR)/$(BINSUBDIR)/cutlass_$$(basename "$$1")"' sh {} \; cutlass_mini: mkdir -p $(BINDIR)/$(BINSUBDIR)/ git submodule init && git submodule update mkdir -p cuda/cutlass-bench/build - $(SETENV) cmake -S cuda/cutlass-bench -B cuda/cutlass-bench/build -DCUTLASS_NVCC_ARCHS="80;90;90a" -DCMAKE_CUDA_ARCHITECTURES="80;90;90a" -DCMAKE_CUDA_COMPILER=$(CUDA_INSTALL_PATH)/bin/nvcc + $(SETENV) cmake -S cuda/cutlass-bench -B cuda/cutlass-bench/build -DCUTLASS_NVCC_ARCHS="$(CUTLASS_MINI_ARCHS)" -DCMAKE_CUDA_ARCHITECTURES="$(CUTLASS_MINI_ARCHS)" -DCMAKE_CUDA_COMPILER=$(CUDA_INSTALL_PATH)/bin/nvcc # add any other cutlass examples you want to build here $(SETENV) $(MAKE) -C cuda/cutlass-bench/build/ 00_basic_gemm 48_hopper_warp_specialized_gemm 52_hopper_gather_scatter_fusion 57_hopper_grouped_gemm @@ -472,7 +484,9 @@ heterosync: git clone https://github.com/mattsinc/heterosync.git; \ fi && \ cd heterosync && git checkout 934a317 - $(SETENV) $(MAKE) $(MAKE_ARGS) CUDA_DIR=$(CUDA_INSTALL_PATH) -C cuda/heterosync/cuda/syncPrims/uvm/ +# heterosync hardcodes GENCODE for compute_60..80; compute_60 no longer exists +# in CUDA 13. Clear it so CUDA_CPPFLAGS (set by setup_environment) decides. + $(SETENV) $(MAKE) $(MAKE_ARGS) GENCODE= CUDA_DIR=$(CUDA_INSTALL_PATH) -C cuda/heterosync/cuda/syncPrims/uvm/ mv cuda/heterosync/cuda/syncPrims/uvm/allSyncPrims-1kernel $(BINDIR)/$(BINSUBDIR)/ # Only SSD,BERT,RESNET,3DUNET inference for now @@ -516,10 +530,21 @@ mlperf_training: cd $(BINDIR)/$(BINSUBDIR) && rm install_mlperf_and_virtual_environments_training.sh +# Every cuda-samples tag targets exactly one toolkit: its CMakeLists hardcodes +# `set(CMAKE_CUDA_ARCHITECTURES ...)`, which shadows any -D we could pass, and +# the v13.x list includes sm_110 that no CUDA 12 nvcc knows. The submodule is +# pinned at v13.2 for the Blackwell/CUDA 13 build, so skip the target rather +# than fail the whole make on an older toolkit. +CUDA_SAMPLES_MIN_MAJOR := 13 + cuda_samples: +ifeq ($(shell test $(CUDA_VERSION_MAJOR) -ge $(CUDA_SAMPLES_MIN_MAJOR) && echo yes),yes) mkdir -p $(BINDIR)/$(BINSUBDIR)/ mkdir -p ./cuda/cuda-samples/build && cd ./cuda/cuda-samples/build && cmake .. && $(MAKE) find $(GPUAPPS_ROOT)/src/cuda/cuda-samples/build/Samples -type f -executable -exec mv {} "$(BINDIR)/$(BINSUBDIR)/" \; ; +else + @echo "Skipping cuda_samples: the submodule is pinned at $$(git -C cuda/cuda-samples describe --tags 2>/dev/null || echo v13.x), which needs CUDA $(CUDA_SAMPLES_MIN_MAJOR)+ (found $(CUDA_VERSION))." +endif pytorch_examples: mkdir -p $(BINDIR)/$(BINSUBDIR)/ @@ -577,14 +602,14 @@ clean_lonestargpu-2.0: $(setenv) $(MAKE) $(make_args) noinline=$(noinline) -C cuda/lonestargpu-2.0 clean clean_ispass-2009: -# $(SETENV) $(MAKE) $(MAKE_ARGS) clean noinline=$(noinline) -C cuda/ispass-2009/AES + $(SETENV) $(MAKE) $(MAKE_ARGS) clean noinline=$(noinline) -C cuda/ispass-2009/AES $(SETENV) $(MAKE) $(MAKE_ARGS) clean noinline=$(noinline) -C cuda/ispass-2009/BFS # cd CP; export PARBOIL_ROOT=`pwd`; cd common/src; $(MAKE) $(MAKE_ARGS); cd -; ./parboil compile cp cuda_short; cp benchmarks/cp/build/cuda_short/cp $(BINDIR)/$(BINSUBDIR)/CP # $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C DG/3rdParty/ParMetis-3.1 # $(SETENV) $(MAKE) $(MAKE_ARGS) noinline=$(noinline) -C DG $(SETENV) $(MAKE) $(MAKE_ARGS) clean noinline=$(noinline) -C cuda/ispass-2009/LIB $(SETENV) $(MAKE) $(MAKE_ARGS) clean noinline=$(noinline) -C cuda/ispass-2009/LPS -# $(SETENV) $(MAKE) $(MAKE_ARGS) clean noinline=$(noinline) -C cuda/ispass-2009/MUM + $(SETENV) $(MAKE) $(MAKE_ARGS) clean noinline=$(noinline) -C cuda/ispass-2009/MUM $(SETENV) $(MAKE) $(MAKE_ARGS) clean noinline=$(noinline) -C cuda/ispass-2009/NN $(SETENV) $(MAKE) $(MAKE_ARGS) clean noinline=$(noinline) -C cuda/ispass-2009/NQU $(SETENV) $(MAKE) $(MAKE_ARGS) clean noinline=$(noinline) -C cuda/ispass-2009/RAY @@ -642,7 +667,7 @@ clean_rodinia_2.0-ft: $(SETENV) $(MAKE) $(MAKE_ARGS) clean -C cuda/rodinia/2.0-ft/bfs $(SETENV) $(MAKE) $(MAKE_ARGS) clean -C cuda/rodinia/2.0-ft/heartwall $(SETENV) $(MAKE) $(MAKE_ARGS) clean -C cuda/rodinia/2.0-ft/hotspot -# $(SETENV) $(MAKE) $(MAKE_ARGS) clean -C cuda/rodinia/2.0-ft/kmeans + $(SETENV) $(MAKE) $(MAKE_ARGS) clean -C cuda/rodinia/2.0-ft/kmeans $(SETENV) $(MAKE) $(MAKE_ARGS) clean -C cuda/rodinia/2.0-ft/lud $(SETENV) $(MAKE) $(MAKE_ARGS) clean -C cuda/rodinia/2.0-ft/nn $(SETENV) $(MAKE) $(MAKE_ARGS) clean -C cuda/rodinia/2.0-ft/nw diff --git a/src/cuda/DeepBench/code/nvidia/Makefile b/src/cuda/DeepBench/code/nvidia/Makefile index 0ecf93757..832eb3501 100644 --- a/src/cuda/DeepBench/code/nvidia/Makefile +++ b/src/cuda/DeepBench/code/nvidia/Makefile @@ -27,17 +27,17 @@ all: gemm conv rnn gemm: $(MKDIR) $(BIN_DIR) - $(CUDA_PATH)/bin/$(NVCC) gemm_bench.cu -DUSE_TENSOR_CORES=0 -DPAD_KERNELS=$(PAD_KERNELS) -o $(BIN_DIR)/gemm_bench -I $(KERNELS_DIR) -I $(CUDA_PATH)/include -L $(BLAS_PATH) -l$(BLAS_LIBRARY) -L $(CUDA_LIB64) -lcurand $(CUDA_CPPFLAGS) -std=c++14 + $(CUDA_PATH)/bin/$(NVCC) gemm_bench.cu -DUSE_TENSOR_CORES=0 -DPAD_KERNELS=$(PAD_KERNELS) -o $(BIN_DIR)/gemm_bench -I $(KERNELS_DIR) -I $(CUDA_PATH)/include -L $(BLAS_PATH) -l$(BLAS_LIBRARY) -L $(CUDA_LIB64) -lcurand $(CUDA_CPPFLAGS) -std=c++17 $(CUDA_PATH)/bin/$(NVCC) gemm_bench.cu -DUSE_TENSOR_CORES=1 -DPAD_KERNELS=$(PAD_KERNELS) -o $(BIN_DIR)/gemm_bench-tencore -I $(KERNELS_DIR) -I $(CUDA_PATH)/include -L $(BLAS_PATH) -l$(BLAS_LIBRARY) -L $(CUDA_LIB64) -lcurand $(CUDA_CPPFLAGS) conv: $(MKDIR) $(BIN_DIR) - $(CUDA_PATH)/bin/$(NVCC) conv_bench.cu -DUSE_TENSOR_CORES=0 -DPAD_KERNELS=$(PAD_KERNELS) -o $(BIN_DIR)/conv_bench -I $(KERNELS_DIR) -I $(CUDA_PATH)/include -I $(CUDNN_PATH)/include/ -L $(CUDNN_PATH)/lib64/ -L $(CUDA_LIB64) -lcurand -lcudnn $(CUDA_CPPFLAGS) -std=c++14 + $(CUDA_PATH)/bin/$(NVCC) conv_bench.cu -DUSE_TENSOR_CORES=0 -DPAD_KERNELS=$(PAD_KERNELS) -o $(BIN_DIR)/conv_bench -I $(KERNELS_DIR) -I $(CUDA_PATH)/include -I $(CUDNN_PATH)/include/ -L $(CUDNN_PATH)/lib64/ -L $(CUDA_LIB64) -lcurand -lcudnn $(CUDA_CPPFLAGS) -std=c++17 $(CUDA_PATH)/bin/$(NVCC) conv_bench.cu -DUSE_TENSOR_CORES=1 -DPAD_KERNELS=$(PAD_KERNELS) -o $(BIN_DIR)/conv_bench-tencore -I $(KERNELS_DIR) -I $(CUDA_PATH)/include -I $(CUDNN_PATH)/include/ -L $(CUDNN_PATH)/lib64/ -L $(CUDA_LIB64) -lcurand -lcudnn $(CUDA_CPPFLAGS) rnn: $(MKDIR) $(BIN_DIR) - $(CUDA_PATH)/bin/$(NVCC) rnn_bench.cu -DUSE_TENSOR_CORES=0 -o $(BIN_DIR)/rnn_bench -I $(KERNELS_DIR) -I $(CUDA_PATH)/include -I $(CUDNN_PATH)/include/ -L $(CUDNN_PATH)/lib64/ -L $(CUDA_LIB64) -lcurand -lcudnn $(CUDA_CPPFLAGS) -std=c++14 + $(CUDA_PATH)/bin/$(NVCC) rnn_bench.cu -DUSE_TENSOR_CORES=0 -o $(BIN_DIR)/rnn_bench -I $(KERNELS_DIR) -I $(CUDA_PATH)/include -I $(CUDNN_PATH)/include/ -L $(CUDNN_PATH)/lib64/ -L $(CUDA_LIB64) -lcurand -lcudnn $(CUDA_CPPFLAGS) -std=c++17 $(CUDA_PATH)/bin/$(NVCC) rnn_bench.cu -DUSE_TENSOR_CORES=1 -o $(BIN_DIR)/rnn_bench-tencore -I $(KERNELS_DIR) -I $(CUDA_PATH)/include -I $(CUDNN_PATH)/include/ -L $(CUDNN_PATH)/lib64/ -L $(CUDA_LIB64) -lcurand -lcudnn $(CUDA_CPPFLAGS) all_reduce: nccl_single nccl_mpi diff --git a/src/cuda/DeepBench/code/nvidia/tensor.h b/src/cuda/DeepBench/code/nvidia/tensor.h index 17ab0ea4b..ad14a8aaa 100644 --- a/src/cuda/DeepBench/code/nvidia/tensor.h +++ b/src/cuda/DeepBench/code/nvidia/tensor.h @@ -8,6 +8,7 @@ #include #include +#include template class Tensor { diff --git a/src/cuda/GPU_Microbenchmark/common/arch_filter.mk b/src/cuda/GPU_Microbenchmark/common/arch_filter.mk new file mode 100644 index 000000000..76eeba749 --- /dev/null +++ b/src/cuda/GPU_Microbenchmark/common/arch_filter.mk @@ -0,0 +1,11 @@ +# Drop any architecture the installed toolkit will not accept, instead of +# failing the build. These ubenches pin an explicit ARCH list (TMA and GMMA +# need the accelerated targets), and those lists drift: CUDA 13 removed +# sm_101, for example. The accelerated "a" variants are matched on their +# base number, so sm_90a survives as long as compute_90 is supported. +# +# Include this after setting ARCH and before deriving NVCC_FLAGS from it. +NVCC_SUPPORTED_ARCH := $(shell nvcc --list-gpu-arch 2>/dev/null | sed -e 's/compute_//') +ifneq ($(strip $(NVCC_SUPPORTED_ARCH)),) +ARCH := $(foreach a,$(ARCH),$(if $(filter $(patsubst %a,%,$(patsubst sm_%,%,$(a))),$(NVCC_SUPPORTED_ARCH)),$(a))) +endif diff --git a/src/cuda/GPU_Microbenchmark/common/common.mk b/src/cuda/GPU_Microbenchmark/common/common.mk index 7b05cb1dd..cafb1d951 100644 --- a/src/cuda/GPU_Microbenchmark/common/common.mk +++ b/src/cuda/GPU_Microbenchmark/common/common.mk @@ -1,7 +1,16 @@ BASE_DIR := $(shell pwd) BIN_DIR := $(BASE_DIR)/../../../bin/ +# Some ubenches need a minimum ISA (cp.async is sm_80+, wgmma sm_90+). They set +# MIN_ARCH before including this file and the -gencode flags for anything older +# are dropped, so one such benchmark cannot fail a build that still targets the +# older architectures for everything else. +MIN_ARCH ?= +ifeq ($(strip $(MIN_ARCH)),) CUOPTS = $(CUDA_CPPFLAGS) +else +CUOPTS = $(shell echo '$(CUDA_CPPFLAGS)' | tr ' ' '\n' | awk -v m=$(MIN_ARCH) '/compute_/ { a=$$0; sub(/.*compute_/,"",a); sub(/[^0-9].*/,"",a); if (a+0 < m+0) next } { printf "%s ", $$0 }') +endif CC := nvcc diff --git a/src/cuda/GPU_Microbenchmark/hw_def/common/gpuConfig.h b/src/cuda/GPU_Microbenchmark/hw_def/common/gpuConfig.h index 0b0306596..14df050e8 100644 --- a/src/cuda/GPU_Microbenchmark/hw_def/common/gpuConfig.h +++ b/src/cuda/GPU_Microbenchmark/hw_def/common/gpuConfig.h @@ -282,6 +282,9 @@ inline unsigned initializeDeviceProp(unsigned deviceID, int argc, char *argv[]) int clockRateKHz; cudaDeviceGetAttribute(&clockRateKHz, cudaDevAttrClockRate, deviceID); + // cudaDeviceProp::memoryClockRate went the same way as ::clockRate in CUDA 13 + int memClockRateKHz; + cudaDeviceGetAttribute(&memClockRateKHz, cudaDevAttrMemoryClockRate, deviceID); // core stats config.SM_NUMBER = deviceProp.multiProcessorCount; @@ -310,7 +313,7 @@ inline unsigned initializeDeviceProp(unsigned deviceID, int argc, char *argv[]) // memory config.MEM_SIZE = deviceProp.totalGlobalMem; - config.MEM_CLK_FREQUENCY = deviceProp.memoryClockRate * 1e-3f; + config.MEM_CLK_FREQUENCY = memClockRateKHz * 1e-3f; config.MEM_BITWIDTH = deviceProp.memoryBusWidth; config.CLK_FREQUENCY = clockRateKHz * 1e-3f; diff --git a/src/cuda/GPU_Microbenchmark/ubench/core/MaxFlops_gmma/Makefile b/src/cuda/GPU_Microbenchmark/ubench/core/MaxFlops_gmma/Makefile index db5a71737..a7bc8e99f 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/core/MaxFlops_gmma/Makefile +++ b/src/cuda/GPU_Microbenchmark/ubench/core/MaxFlops_gmma/Makefile @@ -9,6 +9,7 @@ INCLUDE += -I$(GPUAPPS_ROOT)/src/cuda/cutlass-bench/include -I./ # GMMA is only supported in sm_90a ARCH?=sm_90a +include ../../../common/arch_filter.mk # Unset the CUDA_CPPFLAGS which is set based on CUDA version CUDA_CPPFLAGS= # Generate code for both sm_XXX and compute_XXX (SASS and PTX) diff --git a/src/cuda/GPU_Microbenchmark/ubench/core/config_tensor/Makefile b/src/cuda/GPU_Microbenchmark/ubench/core/config_tensor/Makefile index d29e58ec8..537b335c8 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/core/config_tensor/Makefile +++ b/src/cuda/GPU_Microbenchmark/ubench/core/config_tensor/Makefile @@ -9,4 +9,10 @@ SRC = config_tensor.cu EXE = config_tensor +# only declares nvcuda::wmma for __CUDA_ARCH__ >= 700, so a gencode +# list that still reaches back to Maxwell/Pascal fails here with "wmma is not +# a class or namespace name". The GENCODE_SMxx assignments above predate +# CUDA_CPPFLAGS and never applied to it. +MIN_ARCH = 70 + include ../../../common/common.mk diff --git a/src/cuda/GPU_Microbenchmark/ubench/core/lat_gmma/Makefile b/src/cuda/GPU_Microbenchmark/ubench/core/lat_gmma/Makefile index ae5a5055f..742d43557 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/core/lat_gmma/Makefile +++ b/src/cuda/GPU_Microbenchmark/ubench/core/lat_gmma/Makefile @@ -9,6 +9,7 @@ INCLUDE += -I$(GPUAPPS_ROOT)/src/cuda/cutlass-bench/include -I./ # GMMA is only supported in sm_90a ARCH?=sm_90a +include ../../../common/arch_filter.mk # Unset the CUDA_CPPFLAGS which is set based on CUDA version CUDA_CPPFLAGS= # Generate code for both sm_90a and compute_90a (SASS and PTX) diff --git a/src/cuda/GPU_Microbenchmark/ubench/core/tensor_bw_half/Makefile b/src/cuda/GPU_Microbenchmark/ubench/core/tensor_bw_half/Makefile index c55e26c36..a8770ef87 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/core/tensor_bw_half/Makefile +++ b/src/cuda/GPU_Microbenchmark/ubench/core/tensor_bw_half/Makefile @@ -9,4 +9,10 @@ SRC = tensor_bw_half.cu EXE = tensor_bw_half +# only declares nvcuda::wmma for __CUDA_ARCH__ >= 700, so a gencode +# list that still reaches back to Maxwell/Pascal fails here with "wmma is not +# a class or namespace name". The GENCODE_SMxx assignments above predate +# CUDA_CPPFLAGS and never applied to it. +MIN_ARCH = 70 + include ../../../common/common.mk diff --git a/src/cuda/GPU_Microbenchmark/ubench/core/tensor_lat_half/Makefile b/src/cuda/GPU_Microbenchmark/ubench/core/tensor_lat_half/Makefile index 03b7e7ec8..4b005fb58 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/core/tensor_lat_half/Makefile +++ b/src/cuda/GPU_Microbenchmark/ubench/core/tensor_lat_half/Makefile @@ -9,4 +9,10 @@ SRC = tensor_lat_half.cu EXE = tensor_lat_half +# only declares nvcuda::wmma for __CUDA_ARCH__ >= 700, so a gencode +# list that still reaches back to Maxwell/Pascal fails here with "wmma is not +# a class or namespace name". The GENCODE_SMxx assignments above predate +# CUDA_CPPFLAGS and never applied to it. +MIN_ARCH = 70 + include ../../../common/common.mk diff --git a/src/cuda/GPU_Microbenchmark/ubench/mem/mem_config/mem_config.cu b/src/cuda/GPU_Microbenchmark/ubench/mem/mem_config/mem_config.cu index 088366980..905d1a17c 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/mem/mem_config/mem_config.cu +++ b/src/cuda/GPU_Microbenchmark/ubench/mem/mem_config/mem_config.cu @@ -12,7 +12,7 @@ int main(int argc, char *argv[]) snprintf(msg, sizeof(msg), "Global memory size = %.0f GB\n", static_cast(deviceProp.totalGlobalMem / 1073741824.0f)); std::cout << msg; - std::cout << "Memory Clock rate = " << deviceProp.memoryClockRate * 1e-3f + std::cout << "Memory Clock rate = " << config.MEM_CLK_FREQUENCY << " Mhz\n"; std::cout << "Memory Bus Width = " << deviceProp.memoryBusWidth << " bit\n"; std::cout << "Memory type = " << dram_model_str[DRAM_MODEL] << "\n"; @@ -38,7 +38,7 @@ int main(int argc, char *argv[]) << dram_model_freq_ratio[DRAM_MODEL] << std::endl; // timing - float device_freq_MHZ = (deviceProp.memoryClockRate * 1e-3f * 2) / + float device_freq_MHZ = (config.MEM_CLK_FREQUENCY * 2) / dram_model_freq_ratio[DRAM_MODEL]; if (DRAM_MODEL == dram_model::HBM) { diff --git a/src/cuda/GPU_Microbenchmark/ubench/shd/shared_cp_async/Makefile b/src/cuda/GPU_Microbenchmark/ubench/shd/shared_cp_async/Makefile index c4b3b511e..c9d1a8782 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/shd/shared_cp_async/Makefile +++ b/src/cuda/GPU_Microbenchmark/ubench/shd/shared_cp_async/Makefile @@ -4,4 +4,7 @@ EXE = cp_async NVCC_FLGAS = -Xptxas -dlcm=cg -Xptxas -dscm=wt +# ldgsts.cu uses cp.async, which ptxas rejects below sm_80 +MIN_ARCH = 80 + include ../../../common/common.mk diff --git a/src/cuda/GPU_Microbenchmark/ubench/shd/shared_cp_async/ldgsts.cu b/src/cuda/GPU_Microbenchmark/ubench/shd/shared_cp_async/ldgsts.cu index 6ff204623..7c4f1d565 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/shd/shared_cp_async/ldgsts.cu +++ b/src/cuda/GPU_Microbenchmark/ubench/shd/shared_cp_async/ldgsts.cu @@ -93,6 +93,10 @@ int main(int argc, char** argv) { // ============================== cudaDeviceProp prop; cudaGetDeviceProperties(&prop, 0); + // clockRate/memoryClockRate were removed from cudaDeviceProp in CUDA 13 + int smClockKHz = 0, memClockKHz = 0; + cudaDeviceGetAttribute(&smClockKHz, cudaDevAttrClockRate, 0); + cudaDeviceGetAttribute(&memClockKHz, cudaDevAttrMemoryClockRate, 0); size_t l2_size_bytes = prop.l2CacheSize; if (l2_size_bytes == 0) { @@ -175,7 +179,7 @@ for (size_t b = 0; b < num_blocks; b++) { double avg_cycles = static_cast(total_cycles) / num_blocks; // GPU frequency (kHz → Hz) -double gpu_clock_hz = static_cast(prop.clockRate) * 1000.0; +double gpu_clock_hz = static_cast(smClockKHz) * 1000.0; // Time in seconds double time_sec = avg_cycles / gpu_clock_hz; @@ -192,8 +196,8 @@ double bw_gbs = bytes_moved / time_sec / 1e9; double bytesclk = bytes_moved / avg_cycles; // Bytes per GPU cycle std::cout << "---------------------------------\n"; -std::cout << "SM Clock = " << prop.clockRate / 1000.0 << " MHz\n"; -std::cout << "Memory Clock = " << prop.memoryClockRate / 1000.0 << " MHz\n"; +std::cout << "SM Clock = " << smClockKHz / 1000.0 << " MHz\n"; +std::cout << "Memory Clock = " << memClockKHz / 1000.0 << " MHz\n"; std::cout << "Avg cycles (per block) = " << avg_cycles << "\n"; std::cout << "Time (s) = " << time_sec << "\n"; std::cout << "Bytes moved = " << bytes_moved / (1024.0*1024*1024) << " GB\n"; diff --git a/src/cuda/GPU_Microbenchmark/ubench/system/deviceQuery/Makefile b/src/cuda/GPU_Microbenchmark/ubench/system/deviceQuery/Makefile index 167a71704..72f168823 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/system/deviceQuery/Makefile +++ b/src/cuda/GPU_Microbenchmark/ubench/system/deviceQuery/Makefile @@ -2,7 +2,10 @@ SRC = deviceQuery.cpp EXE = deviceQuery -INCLUDE := -I../../../../cuda-samples/Common/ +# cuda-samples is cloned by a later target in the top-level Makefile, so it is +# not there yet when this builds. The only thing needed from it here is +# _ConvertSMVer2Cores, which the vendored sdk-compat headers also provide. +INCLUDE := -I../../../../cuda-samples/Common/ -I$(GPUAPPS_SDK_INC) NVCC_FLGAS = include ../../../common/common.mk diff --git a/src/cuda/GPU_Microbenchmark/ubench/system/deviceQuery/deviceQuery.cpp b/src/cuda/GPU_Microbenchmark/ubench/system/deviceQuery/deviceQuery.cpp index 4d8bb318a..f5a071ce9 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/system/deviceQuery/deviceQuery.cpp +++ b/src/cuda/GPU_Microbenchmark/ubench/system/deviceQuery/deviceQuery.cpp @@ -32,6 +32,10 @@ int main(int argc, char **argv) { cudaSetDevice(dev); cudaDeviceProp deviceProp; cudaGetDeviceProperties(&deviceProp, dev); + // clockRate/memoryClockRate were removed from cudaDeviceProp in CUDA 13 + int smClockKHz = 0, memClockKHz = 0; + cudaDeviceGetAttribute(&smClockKHz, cudaDevAttrClockRate, dev); + cudaDeviceGetAttribute(&memClockKHz, cudaDevAttrMemoryClockRate, dev); // device printf(" Device : \"%s\"\n\n", deviceProp.name); @@ -40,7 +44,7 @@ int main(int argc, char **argv) { // core printf(" GPU Max Clock rate : %.0f MHz \n", - deviceProp.clockRate * 1e-3f); + smClockKHz * 1e-3f); printf(" Multiprocessors Count : %d\n", deviceProp.multiProcessorCount); printf(" Maximum number of threads per multiprocessor: %d\n", @@ -81,7 +85,7 @@ int main(int argc, char **argv) { static_cast(deviceProp.totalGlobalMem / 1073741824.0f)); printf("%s", msg); printf(" Memory Clock rate : %.0f Mhz\n", - deviceProp.memoryClockRate * 1e-3f); + memClockKHz * 1e-3f); printf(" Memory Bus Width : %d bit\n", deviceProp.memoryBusWidth); diff --git a/src/cuda/GPU_Microbenchmark/ubench/tma/mbarrier/Makefile b/src/cuda/GPU_Microbenchmark/ubench/tma/mbarrier/Makefile index 3b7aa310c..a54e6ca26 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/tma/mbarrier/Makefile +++ b/src/cuda/GPU_Microbenchmark/ubench/tma/mbarrier/Makefile @@ -3,6 +3,8 @@ SRC = mbarrier.cu EXE = mbarrier ARCH?=sm_80 sm_90a sm_100a sm_101 sm_120 +include ../../../common/arch_filter.mk + # Unset the CUDA_CPPFLAGS which is set based on CUDA version CUDA_CPPFLAGS= diff --git a/src/cuda/GPU_Microbenchmark/ubench/tma/tma_bulk/Makefile b/src/cuda/GPU_Microbenchmark/ubench/tma/tma_bulk/Makefile index f3c8bcd00..6694ea905 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/tma/tma_bulk/Makefile +++ b/src/cuda/GPU_Microbenchmark/ubench/tma/tma_bulk/Makefile @@ -4,6 +4,7 @@ EXE = tma_bulk # TMA is supported on SM_90a and above ARCH?=sm_90a sm_100a sm_101 sm_120 +include ../../../common/arch_filter.mk # Unset the CUDA_CPPFLAGS which is set based on CUDA version # but TMA is only supported on SM_90a and above CUDA_CPPFLAGS= diff --git a/src/cuda/GPU_Microbenchmark/ubench/tma/tma_bulk/tma_bulk.cu b/src/cuda/GPU_Microbenchmark/ubench/tma/tma_bulk/tma_bulk.cu index fc885b515..3bbd3a9df 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/tma/tma_bulk/tma_bulk.cu +++ b/src/cuda/GPU_Microbenchmark/ubench/tma/tma_bulk/tma_bulk.cu @@ -1,6 +1,7 @@ #include #include #include +#include // getopt/optarg; no longer pulled in transitively #include #include diff --git a/src/cuda/GPU_Microbenchmark/ubench/tma/tma_tensor/Makefile b/src/cuda/GPU_Microbenchmark/ubench/tma/tma_tensor/Makefile index b24b4dac9..f497f3935 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/tma/tma_tensor/Makefile +++ b/src/cuda/GPU_Microbenchmark/ubench/tma/tma_tensor/Makefile @@ -4,6 +4,7 @@ EXE = tma_tensor # TMA is supported on SM_90a and above ARCH?=sm_90a sm_100a sm_101 sm_120 +include ../../../common/arch_filter.mk # Unset the CUDA_CPPFLAGS which is set based on CUDA version # but TMA is only supported on SM_90a and above CUDA_CPPFLAGS= diff --git a/src/cuda/GPU_Microbenchmark/ubench/tma/tma_tensor/tma_tensor.cu b/src/cuda/GPU_Microbenchmark/ubench/tma/tma_tensor/tma_tensor.cu index d9f7879d7..0a97effbc 100644 --- a/src/cuda/GPU_Microbenchmark/ubench/tma/tma_tensor/tma_tensor.cu +++ b/src/cuda/GPU_Microbenchmark/ubench/tma/tma_tensor/tma_tensor.cu @@ -5,6 +5,7 @@ #include #include #include +#include // getopt/optarg; no longer pulled in transitively #include #include using barrier = cuda::barrier; diff --git a/src/cuda/common/common.mk b/src/cuda/common/common.mk index cd5f3cefc..39585e860 100644 --- a/src/cuda/common/common.mk +++ b/src/cuda/common/common.mk @@ -20,8 +20,14 @@ .SUFFIXES : .cu .cu_dbg.o .c_dbg.o .cpp_dbg.o .cu_rel.o .c_rel.o .cpp_rel.o .cubin .ptx -INCLUDES += -I$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/common/inc -ADDITIONAL_LIBS += -L$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/lib -lcutil_x86_64 +# Vendored SDK 4.2 helpers (cutil, helper_timer, ...); see cuda/common/sdk-compat. +# Offer the lib directory as a search path but do not force -lcutil here: it used +# to be hardcoded to a prebuilt x86_64 archive, which broke every non-x86 host. +# The OMIT_CUTIL_LIB logic below links it only where it is actually wanted. +GPUAPPS_SDK_INC ?= $(NVIDIA_COMPUTE_SDK_LOCATION)/inc +GPUAPPS_SDK_LIB ?= $(NVIDIA_COMPUTE_SDK_LOCATION)/lib +INCLUDES += -I$(GPUAPPS_SDK_INC) +ADDITIONAL_LIBS += -L$(GPUAPPS_SDK_LIB) # Add new SM Versions here as devices with new Compute Capability are released SM_VERSIONS := 70 75 @@ -56,14 +62,13 @@ BINDIR ?= $(ROOTBINDIR)/$(OSLOWER) ROOTOBJDIR ?= obj LIBDIR ?= $(ROOTDIR)/../lib -ifeq ($(shell test ${CUDA_VERSION_MAJOR} -lt 5; echo $$?), 0) - LIBDIRSDK := $(NVIDIA_COMPUTE_SDK_LOCATION)/C/lib - COMMONDIR := $(NVIDIA_COMPUTE_SDK_LOCATION)/C/common - SHAREDDIR := $(NVIDIA_COMPUTE_SDK_LOCATION)/shared -else - LIBDIRSDK ?= $(NVIDIA_COMPUTE_SDK_LOCATION)/lib - COMMONDIR ?= $(NVIDIA_COMPUTE_SDK_LOCATION)/common - SHAREDDIR ?= $(NVIDIA_COMPUTE_SDK_LOCATION)/shared +# The vendored tree is a flat inc/ + lib/, not the old SDK's C/common + shared +# split, so both branches resolve to the same place. COMMONDIR/SHAREDDIR are +# consumed below as $(DIR)/inc, which lands on sdk-compat/inc either way. +LIBDIRSDK ?= $(GPUAPPS_SDK_LIB) +COMMONDIR ?= $(NVIDIA_COMPUTE_SDK_LOCATION) +SHAREDDIR ?= $(NVIDIA_COMPUTE_SDK_LOCATION) +ifneq ($(shell test ${CUDA_VERSION_MAJOR} -lt 5; echo $$?), 0) OMIT_CUTIL_LIB ?= 1 OMIT_SHRUTIL_LIB ?= 1 endif @@ -132,7 +137,13 @@ else else CXX_ARCH_FLAGS += -m32 endif - else + else + # -m32/-m64 are x86-only. On aarch64 the HP_64 test below still matches + # (uname -m is "aarch64"), so without this branch we hand gcc a -m64 it + # rejects. Non-x86 hosts just build for their native ABI. + ifeq ($(strip $(filter i386 i686 x86_64,$(OSARCH))),) + LIB_ARCH = $(OSARCH) + else ifeq "$(strip $(HP_64))" "" LIB_ARCH = i386 NVCCFLAGS += -m32 @@ -150,6 +161,7 @@ else CXX_ARCH_FLAGS += -m64 endif endif + endif endif endif @@ -430,11 +442,11 @@ $(OBJDIR)/%.cpp.o : $(SRCDIR)%.cpp $(C_DEPS) makedirectories # Default arch includes gencode for sm_10, sm_20, sm_30, and other archs from GENCODE_ARCH declared in the makefile $(OBJDIR)/%.cu.o : $(SRCDIR)%.cu $(CU_DEPS) makedirectories - $(VERBOSE)$(NVCC) $(GENCODE_SM70) $(GENCODE_SM75) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -c $< + $(VERBOSE)$(NVCC) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -c $< # Default arch includes gencode for sm_10, sm_20, sm_30, and other archs from GENCODE_ARCH declared in the makefile $(CUBINDIR)/%.cubin : $(SRCDIR)%.cu cubindirectory makedirectories - $(VERBOSE)$(NVCC) $(GENCODE_SM70) $(GENCODE_SM75) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -cubin $< + $(VERBOSE)$(NVCC) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -cubin $< $(PTXDIR)/%.ptx : $(SRCDIR)%.cu ptxdirectory makedirectories $(VERBOSE)$(NVCC) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -ptx $< @@ -459,7 +471,7 @@ define SMVERSION_template OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_$(1).o,$(notdir $(CUFILES_sm_$(1)))) $(OBJDIR)/%.cu_$(1).o : $(SRCDIR)%.cu $(CU_DEPS) # $(VERBOSE)$(NVCC) -o $$@ -c $$< $(NVCCFLAGS) $(1) - $(VERBOSE)$(NVCC) -gencode=arch=compute_$(1),code=\"sm_$(1),compute_$(1)\" $(GENCODE_SM20) $(GENCODE_SM30) -o $$@ -c $$< $(NVCCFLAGS) + $(VERBOSE)$(NVCC) -gencode=arch=compute_$(1),code=\"sm_$(1),compute_$(1)\" $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) -o $$@ -c $$< $(NVCCFLAGS) endef # This line invokes the above template for each arch version stored in diff --git a/src/cuda/common/inc/cutil.h b/src/cuda/common/inc/cutil.h index 2b1ad41d8..06d6b435b 100644 --- a/src/cuda/common/inc/cutil.h +++ b/src/cuda/common/inc/cutil.h @@ -739,13 +739,13 @@ extern "C" { #if CUDART_VERSION >= 4000 #define CUT_DEVICE_SYNCHRONIZE( ) cudaDeviceSynchronize(); #else -#define CUT_DEVICE_SYNCHRONIZE( ) cudaThreadSynchronize(); +#define CUT_DEVICE_SYNCHRONIZE( ) cudaDeviceSynchronize(); #endif #if CUDART_VERSION >= 4000 #define CUT_DEVICE_RESET( ) cudaDeviceReset(); #else -#define CUT_DEVICE_RESET( ) cudaThreadExit(); +#define CUT_DEVICE_RESET( ) cudaDeviceReset(); #endif // This is for the CUTIL bank checker diff --git a/src/cuda/common/sdk-compat/LICENSE-NVIDIA.txt b/src/cuda/common/sdk-compat/LICENSE-NVIDIA.txt new file mode 100644 index 000000000..8a764765b --- /dev/null +++ b/src/cuda/common/sdk-compat/LICENSE-NVIDIA.txt @@ -0,0 +1,56 @@ +NVIDIA Corporation +GPU COMPUTING SDK END USER LICENSE AGREEMENT (“Agreement”) + +BY DOWNLOADING THE SOFTWARE AND OTHER AVAILABLE MATERIALS, YOU ("DEVELOPER" or “LICENSEE”) AGREE TO BE BOUND BY THE FOLLOWING TERMS AND CONDITIONS OF THIS AGREEMENT. IF DEVELOPER DOES NOT AGREE TO THE TERMS AND CONDITION OF THIS AGREEMENT, THEN DO NOT DOWNLOAD THE SOFTWARE AND MATERIALS. + +The materials available for download to Developers may include software in both sample source ("Source Code") and object code ("Object Code") versions, documentation ("Documentation"), certain art work ("Art Assets") and other materials (collectively, these materials referred to herein as "Materials"). Except as expressly indicated herein, all terms and conditions of this Agreement apply to all of the Materials. + +Except as expressly set forth herein, NVIDIA owns all of the Materials and makes them available to Developer only under the terms and conditions set forth in this Agreement. + +License: Subject to the terms of this Agreement, NVIDIA hereby grants to Developer a royalty-free, non-exclusive license to possess and to use the Materials. Developer may install and use multiple copies of the Materials on a shared computer or concurrently on different computers, and make multiple back-up copies of the Materials, solely for Licensee’s use within Licensee’s Enterprise. “Enterprise” shall mean individual use by Licensee or any legal entity (such as a corporation or university) and the subsidiaries it owns by more than 50 percent. The following terms apply to the specified type of Material: + +Source Code: Developer shall have the right to modify and create derivative works with the Source Code. Developer shall own any derivative works ("Derivatives") it creates to the Source Code, provided that Developer uses the Materials in accordance with the terms and conditions of this Agreement. Developer may distribute the Derivatives, provided that all NVIDIA copyright notices and trademarks are propagated and used properly and the Derivatives include the following statement: "This software contains source code provided by NVIDIA Corporation." + +Object Code: Developer agrees not to disassemble, decompile or reverse engineer the Object Code versions of any of the Materials. Developer acknowledges that certain of the Materials provided in Object Code version may contain third party components that may be subject to restrictions, and expressly agrees not to attempt to modify or distribute such Materials without first receiving consent from NVIDIA. + +Art Assets: Developer shall have the right to modify and create Derivatives of the Art Assets, but may not distribute any of the Art Assets or Derivatives created therefrom without NVIDIA’s prior written consent. + +No Other License: No rights or licenses with respect to any proprietary information or patent, copyright, trade secret or other intellectual property right owned or controlled by NVIDIA are granted by NVIDIA to Developer under this Agreement, expressly or by implication, except as expressly provided in this Agreement. Licensee represents and warrants that any and all third party licensing and/or royalty payment obligations in connection with Licensee’s use of the H.264 video codecs are solely the responsibility of Licensee. + +Intellectual Property Ownership: All rights, title, interest and copyrights in and to the Materials (including but not limited to all images, photographs, animations, video, audio, music, text, and other information incorporated into the Materials), are owned by NVIDIA, or its suppliers. The Materials are protected by copyright laws and international treaty provisions. Accordingly, Developer is required to treat the Materials like any other copyrighted material, except as otherwise allowed pursuant to this Agreement. + +Term of Agreement: This Agreement is effective until (i) automatically terminated if Developer fails to comply with any of the terms and conditions of this Agreement; or (ii) terminated by NVIDIA. NVIDIA may terminate this Agreement (and with it, all of Developer’s right to the Materials) immediately upon written notice (which may include email) to Developer, with or without cause. For the sake of clarity, Licensee may continue to use the Derivatives created pursuant to this Agreement, after the termination or expiration of this Agreement + +Defensive Suspension: If Developer commences or participates in any legal proceeding against NVIDIA, then NVIDIA may, in its sole discretion, suspend or terminate all license grants and any other rights provided under this Agreement during the pendency of such legal proceedings. + + +No Support: NVIDIA has no obligation to support or to continue providing or updating any of the Materials. + +No Warranty: THE SOFTWARE AND ANY OTHER MATERIALS PROVIDED BY NVIDIA TO DEVELOPER HEREUNDER ARE PROVIDED "AS IS." NVIDIA DISCLAIMS ALL WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + +Limitation of Liability: NVIDIA SHALL NOT BE LIABLE TO DEVELOPER, DEVELOPER’S CUSTOMERS, OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR UNDER DEVELOPER FOR ANY LOSS OF PROFITS, INCOME, SAVINGS, OR ANY OTHER CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE, DIRECT OR INDIRECT DAMAGES (WHETHER IN AN ACTION IN CONTRACT, TORT OR BASED ON A WARRANTY), EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF THE ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. IN NO EVENT SHALL NVIDIA’S AGGREGATE LIABILITY TO DEVELOPER OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR UNDER DEVELOPER EXCEED THE AMOUNT OF MONEY ACTUALLY PAID BY DEVELOPER TO NVIDIA FOR THE SOFTWARE OR ANY OTHER MATERIALS. + +Applicable Law: This Agreement shall be deemed to have been made in, and shall be construed pursuant to, the laws of the State of Delaware. The United Nations Convention on Contracts for the International Sale of Goods is specifically disclaimed. + +Feedback. Notwithstanding any Non-Disclosure Agreement executed by and between the parties, the parties agree that in the event Licensee or NVIDIA provides Feedback (as defined below) to the other party on how to design, implement, or improve the SOFTWARE or Licensee’s product(s) for use with the SOFTWARE, the following terms and conditions apply the Feedback: + +a. Exchange of Feedback. Both parties agree that neither party has an obligation to give the other party any suggestions, comments or other feedback, whether verbally or in written or source code form, relating to (i) the SOFTWARE; (ii) Licensee’s products; (iii) Licensee’s use of the SOFTWARE; or (iv) optimization/interoperability of Licensee’s product with the SOFTWARE (collectively defined as “Feedback”). In the event either party provides Feedback to the other party, the party receiving the Feedback may use any Feedback that the other party voluntarily provides to improve the (i) SOFTWARE or other related NVIDIA technologies, respectively for the benefit of NVIDIA; or (ii) Licensee’s product or other related Licensee technologies, respectively for the benefit of Licensee. Accordingly, if either party provides Feedback to the other party, both parties agree that the other party and its respective licensees may freely use, reproduce, license, distribute, and otherwise commercialize the Feedback in the (i) SOFTWARE or other related technologies; or (ii) Licensee’s products or other related technologies, respectively, without the payment of any royalties or fees. + +b. Residual Rights. Licensee agrees that NVIDIA shall be free to use any general knowledge, skills and experience, (including, but not limited to, ideas, concepts, know-how, or techniques) (“Residuals”), contained in the (i) Feedback provided by Licensee to NVIDIA; (ii) Licensee’s products shared or disclosed to NVIDIA in connection with the Feedback; or (c) Licensee’s confidential information voluntarily provided to NVIDIA in connection with the Feedback, which are retained in the memories of NVIDIA’s employees, agents, or contractors who have had access to such Residuals. Subject to the terms and conditions of this Agreement, NVIDIA’s employees, agents, or contractors shall not be prevented from using Residuals as part of such employee’s, agent’s or contractor’s general knowledge, skills, experience, talent, and/or expertise. NVIDIA shall not have any obligation to limit or restrict the assignment of such employees, agents or contractors or to pay royalties for any work resulting from the use of Residuals. + +c. Disclaimer of Warranty. FEEDBACK FROM EITHER PARTY IS PROVIDED FOR THE OTHER PARTY’S USE “AS IS” AND BOTH PARTIES DISCLAIM ALL WARRANTIES, EXPRESS, IMPLIED AND STATUTORY INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR INFRINGEMENT. BOTH PARTIES DO NOT REPRESENT OR WARRANT THAT THE FEEDBACK WILL MEET THE OTHER PARTY’S REQUIREMENTS OR THAT THE OPERATION OR IMPLEMENTATION OF THE FEEDBACK WILL BE UNINTERRUPTED OR ERROR-FREE. + +d. No Liability for Consequential Damages. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL EITHER PARTY OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THE FEEDBACK, EVEN IF THE OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +Freedom of Action. Developer agrees that this Agreement is nonexclusive and NVIDIA may currently or in the future be developing software, other technology or confidential information internally, or receiving confidential information from other parties that maybe similar to the Feedback and Developer’s confidential information (as provided in subsection 2 above), which may be provided to NVIDIA in connection with Feedback by Developer. Accordingly, Developer agrees that nothing in this Agreement will be construed as a representation or inference that NVIDIA will not develop, design, manufacture, acquire, market products, or have products developed, designed, manufactured, acquired, or marketed for NVIDIA, that compete with the Developer’s products or confidential information. + +RESTRICTED RIGHTS NOTICE: Materials has been developed entirely at private expense and is commercial computer software provided with RESTRICTED RIGHTS. Use, duplication or disclosure by the U.S. Government or a U.S. Government subcontractor is subject to the restrictions set forth in the license agreement under which Materials was obtained pursuant to DFARS 227.7202-3(a) or as set forth in subparagraphs (c)(1) and (2) of the Commercial Computer Software - Restricted Rights clause at FAR 52.227-19, as applicable. Contractor/manufacturer is NVIDIA, 2701 San Tomas Expressway, Santa Clara, CA 95050. + +Miscellaneous: If any provision of this Agreement is inconsistent with, or cannot be fully enforced under, the law, such provision will be construed as limited to the extent necessary to be consistent with and fully enforceable under the law. This Agreement is the final, complete and exclusive agreement between the parties relating to the subject matter hereof, and supersedes all prior or contemporaneous understandings and agreements relating to such subject matter, whether oral or written. This Agreement may only be modified in writing signed by an authorized officer of NVIDIA. Developer agrees that it will not ship, transfer or export the Materials into any country, or use the Materials in any manner, prohibited by the United States Bureau of Industry and Security or any export laws, restrictions or regulations. + + + + +3 + + diff --git a/src/cuda/common/sdk-compat/NOTICE b/src/cuda/common/sdk-compat/NOTICE new file mode 100644 index 000000000..d7daaf66c --- /dev/null +++ b/src/cuda/common/sdk-compat/NOTICE @@ -0,0 +1,30 @@ +This software contains source code provided by NVIDIA Corporation. + +These files are an unmodified subset of the NVIDIA GPU Computing SDK 4.2.9 +(gpucomputingsdk_4.2.9_linux.run), redistributed under the terms of the GPU +Computing SDK End User License Agreement, which grants the right to distribute +derivative works provided NVIDIA copyright notices are propagated and the above +statement is included. The full license text is in LICENSE-NVIDIA.txt. + +Why this directory exists +------------------------- +Benchmarks in this collection (ISPASS-2009, parts of Rodinia, Pannotia, +LonestarGPU) were written against the SDK's cutil helper library and its +headers. Newer CUDA toolkits stopped shipping these entirely - CUDA 11 removed +the bundled samples - so helper_timer.h and friends have no upstream source +anymore, and the SDK's own prebuilt libcutil_x86_64.a is x86-only. + +setup_environment used to download the full 152 MB SDK installer at setup time +just to obtain these files. Of the 49 headers in that download, the benchmarks +reference 6; the rest is DirectX interop, GL widget toolkits and sample code. +Vendoring the ~450 KB actually needed removes the download, removes the +dependency on a 2012-era NVIDIA URL remaining reachable, and lets the library be +built for whatever architecture the host actually is rather than x86_64 only. + +Contents +-------- +inc/ 16 headers: the transitive closure the benchmarks and the cutil sources + require (cutil, timers, command-line parsing, bank checker, exceptions), + plus shrUtils.h/shrQATest.h used by the gpuwattch-ubench 'power' target. +src/ 7 sources compiled into lib/libcutil_.a by setup_environment. +lib/ build output, not checked in. diff --git a/src/cuda/common/sdk-compat/inc/bank_checker.h b/src/cuda/common/sdk-compat/inc/bank_checker.h new file mode 100644 index 000000000..288bf2332 --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/bank_checker.h @@ -0,0 +1,462 @@ +/* + * Copyright 1993-2012 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + +/* Helper to check for bank conflicts */ + +#ifndef _BANK_CHECKER_H_ +#define _BANK_CHECKER_H_ + +// includes, system +#include +#include +#include +#include +#include + +//! Helper class to check for bank conflicts +class BankChecker +{ + + //! singleton, handle to the instance + static BankChecker bank_checker; + +public: + + //! Get a handle to the instance of this class + static BankChecker* const getHandle(); + + //! Destructor + ~BankChecker(); + +private: + + //! Constructor + BankChecker(); + +public: + + //! Side effect of shared memory access + //! @param tidx thread id in x dimension of block + //! @param tidy thread id in y dimension of block + //! @param tidz thread id in z dimension of block + //! @param bdimx block size in x dimension + //! @param bdimy block size in y dimension + //! @param bdimz block size in z dimension + //! @param file name of the source file where the access takes place + //! @param line line in the source file where the access takes place + //! @param aname name of the array which is accessed + //! @param index index into the array + void access( unsigned int tidx, unsigned int tidy, unsigned int tidz, + unsigned int bdimx, unsigned int bdimy, unsigned int bdimz, + const char* file, const int line, const std::string& aname, + const int index); + +private: + + ////////////////////////////////////////////////////////////////////////////// + //! Uniquely defined access location + ///////////////////////////////////////////////////////////////////////////// + class AccessLocation { + + friend class BankChecker; + + //! type for hash value based on file + line + num_access + typedef std::string KeyType; + + public: + + //! Constructor, default + inline AccessLocation(); + + //! Constructor + //! @param file file where the shared memory access takes place + //! @param line line in \a file where the shared memory access takes place + //! @param array_name name of the array which is accessed + //! @param ltid linearized thread id + inline AccessLocation( const std::string& file, const unsigned int line, + const std::string& array_name, + const unsigned int ltid ); + + //! Constructor, copy + inline AccessLocation( const AccessLocation&); + + //! Assignment operator + inline AccessLocation& operator=( const AccessLocation&); + + //! Destructor + ~AccessLocation(); + + public: + + //! Get the hash key for the access based on file + line + num_access, + //! i.e. identical accesses result in identical hash values + inline const KeyType& getKey() const; + + public: + + // operators, overloaded + + //! Equality + inline bool operator==( const AccessLocation& other) const; + + public: + + //! Get the name of the file of the access + const std::string& getFile() const + { + return file; + } + + //! Get the line of the access in \a file + const unsigned int& getLine() const + { + return line; + } + + //! Get the number of the access in \a line + const unsigned int& getNumAccessLine() const + { + return num_access_line; + } + + private: + + // member variables + + //! file where shared mem is acccessed + std::string file; + + //! line where shared mem is accessed + unsigned int line; + + //! number of access within line + unsigned int num_access_line; + + //! name of the array which is accessed + std::string array_name; + + //! pre-computed key value + KeyType key; + + // invalid flag for data field + static const unsigned int invalid; + + private: + + // Counter for line accesses in a specific file + // @key file + line of access + // @value number of access in \a values::key + typedef std::map LineAccessCounter; + + //! Tracker for number of accesses per file and line for each thread + //! The access number with the file+line uniquely identifies a specific + //! shared memory access + //! Note: The access number itself would not be sufficient because there + //! might be branches in the code so that a specific access is only + //! by a subset of threads of a warp. + //! @key ltid (linearized thread id) + //! @value line accesses in a specific file + static std::map< unsigned int, LineAccessCounter > thread_access; + + }; + + ////////////////////////////////////////////////////////////////////////////// + //! Comparator for AccessLocation + ////////////////////////////////////////////////////////////////////////////// + struct AccessLocationComparator { + + //! Compare operator for std container + inline bool + operator()( const AccessLocation& lhs, const AccessLocation& rhs) const; + }; + +private: + + ////////////////////////////////////////////////////////////////////////////// + //! Meta information about an access + ////////////////////////////////////////////////////////////////////////////// + class AccessInfo { + + friend class BankChecker; + + public: + + //! Constructor, default + inline AccessInfo(); + + //! Constructor, default + //! @param l linearized thread id + //! @param x thread id in x dimension + //! @param y thread id in y dimension + //! @param z thread id in z dimension + //! @param i index used to access shared memory + inline AccessInfo( const unsigned int l, + const unsigned int x, + const unsigned int y, + const unsigned int z, + const unsigned int i ); + + // Constructor, copy + inline AccessInfo( const AccessInfo& other); + + // Assignment operator + inline AccessInfo& operator=( const AccessInfo& other); + + // Destructor + ~AccessInfo(); + + public: + + //! Provide infos as string + const std::string getInfo() const; + const unsigned int getIndex() const; + private: + + //! linearized thread id + unsigned int ltid; + + // thread id in the three dimensions + unsigned int tidx; + unsigned int tidy; + unsigned int tidz; + + // index used to access shared memory + unsigned int index; + + // invalid flag for data field + static const unsigned int invalid; + + }; + + private: + + // data members + + // list of access information + typedef std::vector AccessInfoList; + typedef AccessInfoList::iterator AccessInfoListIter; + typedef AccessInfoList::const_iterator AccessInfoListCIter; + + // information about the access to a specific location + // @key index index of array access + // @value infos about threads which tried to access the threads + typedef std::map< unsigned int, AccessInfoList > IndexAInfoList; + typedef IndexAInfoList::iterator IndexAInfoListIter; + typedef IndexAInfoList::const_iterator IndexAInfoListCIter; + + typedef std::map< AccessLocation, + IndexAInfoList, + AccessLocationComparator > AccessData; + typedef AccessData::iterator AccessDataIter; + typedef AccessData::const_iterator AccessDataCIter; + + //! Tracker for shared memory accesses + AccessData access_data; + + //! Linearized thread id of last thread processed + unsigned int last_ltid; + + //! Total number of bank conflicts + unsigned int total_num_conflicts; + + // flag if bank checker is used + bool is_active; + +private: + + // private helper functions + + //! Get the linearized thread id for a thread + //! @return linear thread id + //! @param tidx thread id in x dimension of block + //! @param tidy thread id in y dimension of block + //! @param tidz thread id in z dimension of block + //! @param bdimx block size in x dimension + //! @param bdimy block size in y dimension + //! @param bdimz block size in z dimension + unsigned int + getLtid( unsigned int tidx, unsigned int tidy, unsigned int tidz, + unsigned int bdimx, unsigned int bdimy, unsigned int bdimz ); + + //! Reset all internal state for a new warp + void reset(); + + //! Analyse the accesses by one warp + void analyse( const AccessDataCIter& iter_loc); + +public: + + // constants + + // size of warp + static const unsigned int warp_size = 16; + +}; + +// functions, inlined + +//////////////////////////////////////////////////////////////////////////////// +// BankChecker::AccessLocation + +//////////////////////////////////////////////////////////////////////////////// +//! Constructor, standard +//! @param file file where the shared memory access takes place +//! @param line line in \a file where the shared memory access takes place +//! @param array_name name of the array which is accessed +//! @param ltid linearized thread id +//////////////////////////////////////////////////////////////////////////////// +BankChecker::AccessLocation:: +AccessLocation( const std::string& f, const unsigned int l, + const std::string& aname, + const unsigned int ltid ) : + file( f), + line( l), + num_access_line( 0), + array_name( aname) +{ + std::ostringstream oss; + oss << file << "l" << line; + + const std::string sstr = oss.str(); + // check if this (file + line) has already been accessed by this thread + if( thread_access[ltid].end() == thread_access[ltid].find( sstr)) { + thread_access[ltid][oss.str()] = 0; + } + else { + thread_access[ltid][oss.str()]++; + } + + // number of access in this line by thread ltid + num_access_line = thread_access[ltid][oss.str()]; + + // generate key + oss << "c" << num_access_line; + key = oss.str(); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Constructor, copy +//////////////////////////////////////////////////////////////////////////////// +BankChecker::AccessLocation:: +AccessLocation( const AccessLocation& other) : + file( other.file), + line( other.line), + num_access_line( other.num_access_line), + array_name( other.array_name), + key( other.key) +{ } + +//////////////////////////////////////////////////////////////////////////////// +//! Assignment operator +//////////////////////////////////////////////////////////////////////////////// +BankChecker::AccessLocation& BankChecker::AccessLocation:: +operator=( const AccessLocation& other) +{ + + if( this != &other) { + + file = other.file; + line = other.line; + array_name = other.array_name; + num_access_line = other.num_access_line; + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Equality +//////////////////////////////////////////////////////////////////////////////// +bool BankChecker::AccessLocation:: +operator==( const AccessLocation& other) const +{ + + return ( (file == other.file) + && (line == other.line) + && (num_access_line == other.num_access_line)) ? true : false; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Get the hash key for the access based on file + line + num_access, +//! i.e. identical accesses result in identical hash values +//! @return the key value +//////////////////////////////////////////////////////////////////////////////// +const BankChecker::AccessLocation::KeyType& BankChecker::AccessLocation:: +getKey() const { + + return key; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare operator for std container +//////////////////////////////////////////////////////////////////////////////// +inline bool +BankChecker::AccessLocationComparator::operator()( const AccessLocation& lhs, + const AccessLocation& rhs) const { + return (lhs.getKey() < rhs.getKey()); +} + +//////////////////////////////////////////////////////////////////////////////// +// BankChecker::AccessInfo + +//////////////////////////////////////////////////////////////////////////////// +//! Constructor, default +//! @param l linearized thread id +//! @param x thread id in x dimension +//! @param y thread id in y dimension +//! @param z thread id in z dimension +//////////////////////////////////////////////////////////////////////////////// +BankChecker::AccessInfo:: +AccessInfo( const unsigned int l, + const unsigned int x, + const unsigned int y, + const unsigned int z, + const unsigned int i ) : + ltid( l), + tidx( x), + tidy( y), + tidz( z), + index( i) +{ } + +//////////////////////////////////////////////////////////////////////////////// +// Constructor, copy +//////////////////////////////////////////////////////////////////////////////// +BankChecker::AccessInfo:: +AccessInfo( const AccessInfo& other) : + ltid( other.ltid), + tidx( other.tidx), + tidy( other.tidy), + tidz( other.tidz), + index( other.index) +{ } + +//////////////////////////////////////////////////////////////////////////////// +// Assignment operator +//////////////////////////////////////////////////////////////////////////////// +BankChecker::AccessInfo& BankChecker::AccessInfo:: +operator=( const AccessInfo& other) +{ + + if( this != &other) + { + + ltid = other.ltid; + tidx = other.tidx; + tidy = other.tidy; + tidz = other.tidz; + index = other.index; + } + + return *this; +} + +#endif // #ifdef _BANK_CHECKER_H_ diff --git a/src/cuda/common/sdk-compat/inc/cmd_arg_reader.h b/src/cuda/common/sdk-compat/inc/cmd_arg_reader.h new file mode 100644 index 000000000..825278a98 --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/cmd_arg_reader.h @@ -0,0 +1,500 @@ +/* + * Copyright 1993-2012 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + + /* +* Copyright 1993-2012 NVIDIA Corporation. All rights reserved. +* +* Please refer to the NVIDIA end user license agreement (EULA) associated +* with this source code for terms and conditions that govern your use of +* this software. Any use, reproduction, disclosure, or distribution of +* this software and related documentation outside the terms of the EULA +* is strictly prohibited. +* +*/ + +/* CUda UTility Library */ + +#ifndef _CMDARGREADER_H_ +#define _CMDARGREADER_H_ + +// includes, system +#include +#include +#include +#include +#include + +// includes, project +#include + +//! Preprocessed command line arguments +//! @note Lazy evaluation: The arguments are converted from strings to +//! the correct data type upon request. Converted values are stored +//! in an additonal map so that no additional conversion is +//! necessary. Arrays of command line arguments are stored in +//! std::vectors +//! @note Usage: +//! const std::string* file = +//! CmdArgReader::getArg< std::string>( "model") +//! const std::vector< std::string>* files = +//! CmdArgReader::getArg< std::vector< std::string> >( "model") +//! @note All command line arguments begin with '--' followed by the token; +//! token and value are seperated by '='; example --samples=50 +//! @note Arrays have the form --model=[one.obj,two.obj,three.obj] +//! (without whitespaces) + +//! Command line argument parser +class CmdArgReader +{ + template friend class TestCmdArgReader; + +protected: + + //! @param self handle to the only instance of this class + static CmdArgReader* self; + +public: + + //! Public construction interface + //! @return a handle to the class instance + //! @param argc number of command line arguments (as given to main()) + //! @param argv command line argument string (as given to main()) + static void init( const int argc, const char** argv); + +public: + + //! Get the value of the command line argument with given name + //! @return A const handle to the requested argument. + //! If the argument does not exist or if it + //! is not from type T NULL is returned + //! @param name the name of the requested argument + //! @note T the type of the argument requested + template + static inline const T* getArg( const std::string& name); + + //! Check if a command line argument with the given name exists + //! @return true if a command line argument with name \a name exists, + //! otherwise false + //! @param name name of the command line argument in question + static inline bool existArg( const std::string& name); + + //! Get the original / raw argc program argument + static inline int& getRArgc(); + + //! Get the original / raw argv program argument + static inline char**& getRArgv(); + +public: + + //! Destructor + ~CmdArgReader(); + +protected: + + //! Constructor, default + CmdArgReader(); + +private: + + // private helper functions + + //! Get the value of the command line argument with given name + //! @note Private helper function for 'getArg' to work on the members + //! @return A const handle to the requested argument. If the argument + //! does not exist or if it is not from type T a NULL pointer + //! is returned. + //! @param name the name of the requested argument + //! @note T the type of the argument requested + template + inline const T* getArgHelper( const std::string& name); + + //! Check if a command line argument with name \a name exists + //! @return true if a command line argument of name \a name exists, + //! otherwise false + //! @param name the name of the requested argument + inline bool existArgHelper( const std::string& name) const; + + //! Read args as token value pair into map for better processing + //! (Even the values remain strings until the parameter values is + //! requested by the program.) + //! @param argc the argument count (as given to 'main') + //! @param argv the char* array containing the command line arguments + void createArgsMaps( const int argc, const char** argv); + + //! Helper for "casting" the strings from the map with the unprocessed + //! values to the correct + //! data type. + //! @return true if conversion succeeded, otherwise false + //! @param element the value as string + //! @param val the value as type T + template + static inline bool convertToT( const std::string& element, T& val); + +public: + + // typedefs internal + + //! container for a processed command line argument + //! typeid is used to easily be able to decide if a re-requested token-value + //! pair match the type of the first conversion + typedef std::pair< const std::type_info*, void*> ValType; + //! map of already converted values + typedef std::map< std::string, ValType > ArgsMap; + //! iterator for the map of already converted values + typedef ArgsMap::iterator ArgsMapIter; + typedef ArgsMap::const_iterator ConstArgsMapIter; + + //! map of unprocessed (means unconverted) token-value pairs + typedef std::map< std::string, std::string> UnpMap; + //! iterator for the map of unprocessed (means unconverted) token-value pairs + typedef std::map< std::string, std::string>::iterator UnpMapIter; + +private: + +#ifdef _WIN32 +# pragma warning( disable: 4251) +#endif + + //! rargc original value of argc + static int rargc; + + //! rargv contains command line arguments in raw format + static char** rargv; + + //! args Map containing the already converted token-value pairs + ArgsMap args; + + //! args Map containing the unprocessed / unconverted token-value pairs + UnpMap unprocessed; + + //! iter Iterator for the map with the already converted token-value + //! pairs (to avoid frequent reallocation) + ArgsMapIter iter; + + //! iter Iterator for the map with the unconverted token-value + //! pairs (to avoid frequent reallocation) + UnpMapIter iter_unprocessed; + +#ifdef _WIN32 +# pragma warning( default: 4251) +#endif + +private: + + //! Constructor, copy (not implemented) + CmdArgReader( const CmdArgReader&); + + //! Assignment operator (not implemented) + CmdArgReader& operator=( const CmdArgReader&); +}; + +// variables, exported (extern) + +// functions, inlined (inline) + +//////////////////////////////////////////////////////////////////////////////// +//! Conversion function for command line argument arrays +//! @note This function is used each type for which no template specialization +//! exist (which will cause errors if the type does not fulfill the std::vector +//! interface). +//////////////////////////////////////////////////////////////////////////////// +template +/*static*/ inline bool +CmdArgReader::convertToT( const std::string& element, T& val) +{ + // preallocate storage + val.resize( std::count( element.begin(), element.end(), ',') + 1); + + unsigned int i = 0; + std::string::size_type pos_start = 1; // leave array prefix '[' + std::string::size_type pos_end = 0; + + // do for all elements of the comma seperated list + while( std::string::npos != ( pos_end = element.find(',', pos_end+1)) ) + { + // convert each element by the appropriate function + if ( ! convertToT< typename T::value_type >( + std::string( element, pos_start, pos_end - pos_start), val[i])) + { + return false; + } + + pos_start = pos_end + 1; + ++i; + } + + std::string tmp1( element, pos_start, element.length() - pos_start - 1); + + // process last element (leave array postfix ']') + if ( ! convertToT< typename T::value_type >( std::string( element, + pos_start, + element.length() - pos_start - 1), + val[i])) + { + return false; + } + + // possible to process all elements? + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Conversion function for command line arguments of type int +//////////////////////////////////////////////////////////////////////////////// +template<> +inline bool +CmdArgReader::convertToT( const std::string& element, int& val) +{ + std::istringstream ios( element); + ios >> val; + + bool ret_val = false; + if ( ios.eof()) + { + ret_val = true; + } + + return ret_val; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Conversion function for command line arguments of type float +//////////////////////////////////////////////////////////////////////////////// +template<> +inline bool +CmdArgReader::convertToT( const std::string& element, float& val) +{ + std::istringstream ios( element); + ios >> val; + + bool ret_val = false; + if ( ios.eof()) + { + ret_val = true; + } + + return ret_val; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Conversion function for command line arguments of type double +//////////////////////////////////////////////////////////////////////////////// +template<> +inline bool +CmdArgReader::convertToT( const std::string& element, double& val) +{ + std::istringstream ios( element); + ios >> val; + + bool ret_val = false; + if ( ios.eof()) + { + ret_val = true; + } + + return ret_val; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Conversion function for command line arguments of type string +//////////////////////////////////////////////////////////////////////////////// +template<> +inline bool +CmdArgReader::convertToT( const std::string& element, + std::string& val) +{ + val = element; + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Conversion function for command line arguments of type bool +//////////////////////////////////////////////////////////////////////////////// +template<> +inline bool +CmdArgReader::convertToT( const std::string& element, bool& val) +{ + // check if value is given as string-type { true | false } + if ( "true" == element) + { + val = true; + return true; + } + else if ( "false" == element) + { + val = false; + return true; + } + // check if argument is given as integer { 0 | 1 } + else + { + int tmp; + if ( convertToT( element, tmp)) + { + if ( 1 == tmp) + { + val = true; + return true; + } + else if ( 0 == tmp) + { + val = false; + return true; + } + } + } + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Get the value of the command line argument with given name +//! @return A const handle to the requested argument. If the argument does +//! not exist or if it is not from type T NULL is returned +//! @param T the type of the argument requested +//! @param name the name of the requested argument +//////////////////////////////////////////////////////////////////////////////// +template +/*static*/ const T* +CmdArgReader::getArg( const std::string& name) +{ + if( ! self) + { + RUNTIME_EXCEPTION("CmdArgReader::getArg(): CmdArgReader not initialized."); + return NULL; + } + + return self->getArgHelper( name); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Check if a command line argument with the given name exists +//! @return true if a command line argument with name \a name exists, +//! otherwise false +//! @param name name of the command line argument in question +//////////////////////////////////////////////////////////////////////////////// +/*static*/ inline bool +CmdArgReader::existArg( const std::string& name) +{ + if( ! self) + { + RUNTIME_EXCEPTION("CmdArgReader::getArg(): CmdArgReader not initialized."); + return false; + } + + return self->existArgHelper( name); +} + +//////////////////////////////////////////////////////////////////////////////// +//! @brief Get the value of the command line argument with given name +//! @return A const handle to the requested argument. If the argument does +//! not exist or if it is not from type T NULL is returned +//! @param T the type of the argument requested +//! @param name the name of the requested argument +//////////////////////////////////////////////////////////////////////////////// +template +const T* +CmdArgReader::getArgHelper( const std::string& name) +{ + // check if argument already processed and stored in correct type + if ( args.end() != (iter = args.find( name))) + { + if ( (*(iter->second.first)) == typeid( T) ) + { + return (T*) iter->second.second; + } + } + else + { + T* tmp = new T; + + // check the array with unprocessed values + if ( unprocessed.end() != (iter_unprocessed = unprocessed.find( name))) + { + // try to "cast" the string to the type requested + if ( convertToT< T >( iter_unprocessed->second, *tmp)) + { + // add the token element pair to map of already converted values + args[name] = std::make_pair( &(typeid( T)), (void*) tmp); + + return tmp; + } + } + + // not used while not inserted into the map -> cleanup + delete tmp; + } + + // failed, argument not available + return NULL; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Check if a command line argument with name \a name exists +//! @return true if a command line argument of name \a name exists, +//! otherwise false +//! @param name the name of the requested argument +//////////////////////////////////////////////////////////////////////////////// +inline bool +CmdArgReader::existArgHelper( const std::string& name) const +{ + bool ret_val = false; + + // check if argument already processed and stored in correct type + if( args.end() != args.find( name)) + { + ret_val = true; + } + else + { + + // check the array with unprocessed values + if ( unprocessed.end() != unprocessed.find( name)) + { + ret_val = true; + } + } + + return ret_val; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Get the original / raw argc program argument +//////////////////////////////////////////////////////////////////////////////// +/*static*/ inline int& +CmdArgReader::getRArgc() +{ + if( ! self) + { + RUNTIME_EXCEPTION("CmdArgReader::getRArgc(): CmdArgReader not initialized."); + } + + return rargc; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Get the original / raw argv program argument +//////////////////////////////////////////////////////////////////////////////// +/*static*/ inline char**& +CmdArgReader::getRArgv() +{ + if( ! self) + { + RUNTIME_EXCEPTION("CmdArgReader::getRArgc(): CmdArgReader not initialized."); + } + + return rargv; +} + +// functions, exported (extern) + +#endif // #ifndef _CMDARGREADER_H_ + diff --git a/src/cuda/common/sdk-compat/inc/cutil.h b/src/cuda/common/sdk-compat/inc/cutil.h new file mode 100644 index 000000000..2b1ad41d8 --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/cutil.h @@ -0,0 +1,929 @@ +/* + * Copyright 1993-2012 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + + /* +* Copyright 1993-2012 NVIDIA Corporation. All rights reserved. +* +* Please refer to the NVIDIA end user license agreement (EULA) associated +* with this source code for terms and conditions that govern your use of +* this software. Any use, reproduction, disclosure, or distribution of +* this software and related documentation outside the terms of the EULA +* is strictly prohibited. +* +*/ + + +/* CUda UTility Library */ + +#ifndef _CUTIL_H_ +#define _CUTIL_H_ + +#ifdef _WIN32 +# pragma warning( disable : 4996 ) // disable deprecated warning +#endif + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + // helper typedefs for building DLL +#ifdef _WIN32 +# ifdef BUILD_DLL +# define DLL_MAPPING __declspec(dllexport) +# else +# define DLL_MAPPING __declspec(dllimport) +# endif +#else +# define DLL_MAPPING +#endif + +#ifdef _WIN32 + #define CUTIL_API __stdcall +#else + #define CUTIL_API +#endif + + //////////////////////////////////////////////////////////////////////////// + //! CUT bool type + //////////////////////////////////////////////////////////////////////////// + enum CUTBoolean + { + CUTFalse = 0, + CUTTrue = 1 + }; + + //////////////////////////////////////////////////////////////////////////// + //! Deallocate memory allocated within Cutil + //! @param pointer to memory + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + void CUTIL_API + cutFree( void* ptr); + + //////////////////////////////////////////////////////////////////////////// + //! Helper for bank conflict checking (should only be used with the + //! CUT_BANK_CHECKER macro) + //! @param tidx thread id in x dimension of block + //! @param tidy thread id in y dimension of block + //! @param tidz thread id in z dimension of block + //! @param bdimx block size in x dimension + //! @param bdimy block size in y dimension + //! @param bdimz block size in z dimension + //! @param file name of the source file where the access takes place + //! @param line line in the source file where the access takes place + //! @param aname name of the array which is accessed + //! @param index index into the array + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + void CUTIL_API + cutCheckBankAccess( unsigned int tidx, unsigned int tidy, unsigned int tidz, + unsigned int bdimx, unsigned int bdimy, + unsigned int bdimz, const char* file, const int line, + const char* aname, const int index); + + //////////////////////////////////////////////////////////////////////////// + //! Find the path for a filename + //! @return the path if succeeded, otherwise 0 + //! @param filename name of the file + //! @param executablePath optional absolute path of the executable + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + char* CUTIL_API + cutFindFilePath(const char* filename, const char* executablePath); + + //////////////////////////////////////////////////////////////////////////// + //! Read file \filename containing single precision floating point data + //! @return CUTTrue if reading the file succeeded, otherwise false + //! @param filename name of the source file + //! @param data uninitialized pointer, returned initialized and pointing to + //! the data read + //! @param len number of data elements in data, -1 on error + //! @note If a NULL pointer is passed to this function and it is + //! initialized within Cutil then cutFree() has to be used to + //! deallocate the memory + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutReadFilef( const char* filename, float** data, unsigned int* len, + bool verbose = false); + + //////////////////////////////////////////////////////////////////////////// + //! Read file \filename containing double precision floating point data + //! @return CUTTrue if reading the file succeeded, otherwise false + //! @param filename name of the source file + //! @param data uninitialized pointer, returned initialized and pointing to + //! the data read + //! @param len number of data elements in data, -1 on error + //! @note If a NULL pointer is passed to this function and it is + //! initialized within Cutil then cutFree() has to be used to + //! deallocate the memory + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutReadFiled( const char* filename, double** data, unsigned int* len, + bool verbose = false); + + //////////////////////////////////////////////////////////////////////////// + //! Read file \filename containing integer data + //! @return CUTTrue if reading the file succeeded, otherwise false + //! @param filename name of the source file + //! @param data uninitialized pointer, returned initialized and pointing to + //! the data read + //! @param len number of data elements in data, -1 on error + //! @note If a NULL pointer is passed to this function and it is + //! initialized within Cutil then cutFree() has to be used to + //! deallocate the memory + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutReadFilei( const char* filename, int** data, unsigned int* len, bool verbose = false); + + //////////////////////////////////////////////////////////////////////////// + //! Read file \filename containing unsigned integer data + //! @return CUTTrue if reading the file succeeded, otherwise false + //! @param filename name of the source file + //! @param data uninitialized pointer, returned initialized and pointing to + //! the data read + //! @param len number of data elements in data, -1 on error + //! @note If a NULL pointer is passed to this function and it is + //! initialized within Cutil then cutFree() has to be used to + //! deallocate the memory + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutReadFileui( const char* filename, unsigned int** data, + unsigned int* len, bool verbose = false); + + //////////////////////////////////////////////////////////////////////////// + //! Read file \filename containing char / byte data + //! @return CUTTrue if reading the file succeeded, otherwise false + //! @param filename name of the source file + //! @param data uninitialized pointer, returned initialized and pointing to + //! the data read + //! @param len number of data elements in data, -1 on error + //! @note If a NULL pointer is passed to this function and it is + //! initialized within Cutil then cutFree() has to be used to + //! deallocate the memory + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutReadFileb( const char* filename, char** data, unsigned int* len, + bool verbose = false); + + //////////////////////////////////////////////////////////////////////////// + //! Read file \filename containing unsigned char / byte data + //! @return CUTTrue if reading the file succeeded, otherwise false + //! @param filename name of the source file + //! @param data uninitialized pointer, returned initialized and pointing to + //! the data read + //! @param len number of data elements in data, -1 on error + //! @note If a NULL pointer is passed to this function and it is + //! initialized within Cutil then cutFree() has to be used to + //! deallocate the memory + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutReadFileub( const char* filename, unsigned char** data, + unsigned int* len, bool verbose = false); + + //////////////////////////////////////////////////////////////////////////// + //! Write a data file \filename containing single precision floating point + //! data + //! @return CUTTrue if writing the file succeeded, otherwise false + //! @param filename name of the file to write + //! @param data pointer to data to write + //! @param len number of data elements in data, -1 on error + //! @param epsilon epsilon for comparison + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutWriteFilef( const char* filename, const float* data, unsigned int len, + const float epsilon, bool verbose = false); + + //////////////////////////////////////////////////////////////////////////// + //! Write a data file \filename containing double precision floating point + //! data + //! @return CUTTrue if writing the file succeeded, otherwise false + //! @param filename name of the file to write + //! @param data pointer to data to write + //! @param len number of data elements in data, -1 on error + //! @param epsilon epsilon for comparison + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutWriteFiled( const char* filename, const float* data, unsigned int len, + const double epsilon, bool verbose = false); + + //////////////////////////////////////////////////////////////////////////// + //! Write a data file \filename containing integer data + //! @return CUTTrue if writing the file succeeded, otherwise false + //! @param filename name of the file to write + //! @param data pointer to data to write + //! @param len number of data elements in data, -1 on error + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutWriteFilei( const char* filename, const int* data, unsigned int len, + bool verbose = false); + + //////////////////////////////////////////////////////////////////////////// + //! Write a data file \filename containing unsigned integer data + //! @return CUTTrue if writing the file succeeded, otherwise false + //! @param filename name of the file to write + //! @param data pointer to data to write + //! @param len number of data elements in data, -1 on error + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutWriteFileui( const char* filename,const unsigned int* data, + unsigned int len, bool verbose = false); + + //////////////////////////////////////////////////////////////////////////// + //! Write a data file \filename containing char / byte data + //! @return CUTTrue if writing the file succeeded, otherwise false + //! @param filename name of the file to write + //! @param data pointer to data to write + //! @param len number of data elements in data, -1 on error + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutWriteFileb( const char* filename, const char* data, unsigned int len, + bool verbose = false); + + //////////////////////////////////////////////////////////////////////////// + //! Write a data file \filename containing unsigned char / byte data + //! @return CUTTrue if writing the file succeeded, otherwise false + //! @param filename name of the file to write + //! @param data pointer to data to write + //! @param len number of data elements in data, -1 on error + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutWriteFileub( const char* filename,const unsigned char* data, + unsigned int len, bool verbose = false); + + //////////////////////////////////////////////////////////////////////////// + //! Load PGM image file (with unsigned char as data element type) + //! @return CUTTrue if reading the file succeeded, otherwise false + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + //! @note If a NULL pointer is passed to this function and it is + //! initialized within Cutil then cutFree() has to be used to + //! deallocate the memory + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutLoadPGMub( const char* file, unsigned char** data, + unsigned int *w,unsigned int *h); + + //////////////////////////////////////////////////////////////////////////// + //! Load PPM image file (with unsigned char as data element type) + //! @return CUTTrue if reading the file succeeded, otherwise false + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutLoadPPMub( const char* file, unsigned char** data, + unsigned int *w,unsigned int *h); + + //////////////////////////////////////////////////////////////////////////// + //! Load PPM image file (with unsigned char as data element type), padding + //! 4th component + //! @return CUTTrue if reading the file succeeded, otherwise false + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutLoadPPM4ub( const char* file, unsigned char** data, + unsigned int *w,unsigned int *h); + + //////////////////////////////////////////////////////////////////////////// + //! Load PGM image file (with unsigned int as data element type) + //! @return CUTTrue if reading the file succeeded, otherwise false + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + //! @note If a NULL pointer is passed to this function and it is + //! initialized within Cutil then cutFree() has to be used to + //! deallocate the memory + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutLoadPGMi( const char* file, unsigned int** data, + unsigned int* w, unsigned int* h); + + //////////////////////////////////////////////////////////////////////////// + //! Load PGM image file (with unsigned short as data element type) + //! @return CUTTrue if reading the file succeeded, otherwise false + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + //! @note If a NULL pointer is passed to this function and it is + //! initialized withing Cutil then cutFree() has to be used to + //! deallocate the memory + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutLoadPGMs( const char* file, unsigned short** data, + unsigned int* w, unsigned int* h); + + //////////////////////////////////////////////////////////////////////////// + //! Load PGM image file (with float as data element type) + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + //! @note If a NULL pointer is passed to this function and it is + //! initialized withing Cutil then cutFree() has to be used to + //! deallocate the memory + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutLoadPGMf( const char* file, float** data, + unsigned int* w, unsigned int* h); + + //////////////////////////////////////////////////////////////////////////// + //! Save PGM image file (with unsigned char as data element type) + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutSavePGMub( const char* file, unsigned char* data, + unsigned int w, unsigned int h); + + //////////////////////////////////////////////////////////////////////////// + //! Save PPM image file (with unsigned char as data element type) + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutSavePPMub( const char* file, unsigned char *data, + unsigned int w, unsigned int h); + + //////////////////////////////////////////////////////////////////////////// + //! Save PPM image file (with unsigned char as data element type, padded to + //! 4 bytes) + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutSavePPM4ub( const char* file, unsigned char *data, + unsigned int w, unsigned int h); + + //////////////////////////////////////////////////////////////////////////// + //! Save PGM image file (with unsigned int as data element type) + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutSavePGMi( const char* file, unsigned int* data, + unsigned int w, unsigned int h); + + //////////////////////////////////////////////////////////////////////////// + //! Save PGM image file (with unsigned short as data element type) + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutSavePGMs( const char* file, unsigned short* data, + unsigned int w, unsigned int h); + + //////////////////////////////////////////////////////////////////////////// + //! Save PGM image file (with float as data element type) + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutSavePGMf( const char* file, float* data, + unsigned int w, unsigned int h); + + //////////////////////////////////////////////////////////////////////////// + // Command line arguments: General notes + // * All command line arguments begin with '--' followed by the token; + // token and value are seperated by '='; example --samples=50 + // * Arrays have the form --model=[one.obj,two.obj,three.obj] + // (without whitespaces) + //////////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////////// + //! Check if command line argument \a flag-name is given + //! @return CUTTrue if command line argument \a flag_name has been given, + //! otherwise 0 + //! @param argc argc as passed to main() + //! @param argv argv as passed to main() + //! @param flag_name name of command line flag + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutCheckCmdLineFlag( const int argc, const char** argv, + const char* flag_name); + + //////////////////////////////////////////////////////////////////////////// + //! Get the value of a command line argument of type int + //! @return CUTTrue if command line argument \a arg_name has been given and + //! is of the requested type, otherwise CUTFalse + //! @param argc argc as passed to main() + //! @param argv argv as passed to main() + //! @param arg_name name of the command line argument + //! @param val value of the command line argument + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutGetCmdLineArgumenti( const int argc, const char** argv, + const char* arg_name, int* val); + + //////////////////////////////////////////////////////////////////////////// + //! Get the value of a command line argument of type float + //! @return CUTTrue if command line argument \a arg_name has been given and + //! is of the requested type, otherwise CUTFalse + //! @param argc argc as passed to main() + //! @param argv argv as passed to main() + //! @param arg_name name of the command line argument + //! @param val value of the command line argument + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutGetCmdLineArgumentf( const int argc, const char** argv, + const char* arg_name, float* val); + + //////////////////////////////////////////////////////////////////////////// + //! Get the value of a command line argument of type string + //! @return CUTTrue if command line argument \a arg_name has been given and + //! is of the requested type, otherwise CUTFalse + //! @param argc argc as passed to main() + //! @param argv argv as passed to main() + //! @param arg_name name of the command line argument + //! @param val value of the command line argument + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutGetCmdLineArgumentstr( const int argc, const char** argv, + const char* arg_name, char** val); + + //////////////////////////////////////////////////////////////////////////// + //! Get the value of a command line argument list those element are strings + //! @return CUTTrue if command line argument \a arg_name has been given and + //! is of the requested type, otherwise CUTFalse + //! @param argc argc as passed to main() + //! @param argv argv as passed to main() + //! @param arg_name name of the command line argument + //! @param val command line argument list + //! @param len length of the list / number of elements + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutGetCmdLineArgumentListstr( const int argc, const char** argv, + const char* arg_name, char** val, + unsigned int* len); + + //////////////////////////////////////////////////////////////////////////// + //! Extended assert + //! @return CUTTrue if the condition \a val holds, otherwise CUTFalse + //! @param val condition to test + //! @param file __FILE__ macro + //! @param line __LINE__ macro + //! @note This function should be used via the CONDITION(val) macro + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutCheckCondition( int val, const char* file, const int line); + + //////////////////////////////////////////////////////////////////////////// + //! Compare two float arrays + //! @return CUTTrue if \a reference and \a data are identical, + //! otherwise CUTFalse + //! @param reference handle to the reference data / gold image + //! @param data handle to the computed data + //! @param len number of elements in reference and data + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutComparef( const float* reference, const float* data, + const unsigned int len); + + //////////////////////////////////////////////////////////////////////////// + //! Compare two integer arrays + //! @return CUTTrue if \a reference and \a data are identical, + //! otherwise CUTFalse + //! @param reference handle to the reference data / gold image + //! @param data handle to the computed data + //! @param len number of elements in reference and data + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutComparei( const int* reference, const int* data, + const unsigned int len ); + + //////////////////////////////////////////////////////////////////////////////// + //! Compare two unsigned integer arrays, with epsilon and threshold + //! @return CUTTrue if \a reference and \a data are identical, + //! otherwise CUTFalse + //! @param reference handle to the reference data / gold image + //! @param data handle to the computed data + //! @param len number of elements in reference and data + //! @param threshold tolerance % # of comparison errors (0.15f = 15%) + //////////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutCompareuit( const unsigned int* reference, const unsigned int* data, + const unsigned int len, const float epsilon, const float threshold ); + + //////////////////////////////////////////////////////////////////////////// + //! Compare two unsigned char arrays + //! @return CUTTrue if \a reference and \a data are identical, + //! otherwise CUTFalse + //! @param reference handle to the reference data / gold image + //! @param data handle to the computed data + //! @param len number of elements in reference and data + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutCompareub( const unsigned char* reference, const unsigned char* data, + const unsigned int len ); + + //////////////////////////////////////////////////////////////////////////////// + //! Compare two integers with a tolernance for # of byte errors + //! @return CUTTrue if \a reference and \a data are identical, + //! otherwise CUTFalse + //! @param reference handle to the reference data / gold image + //! @param data handle to the computed data + //! @param len number of elements in reference and data + //! @param epsilon epsilon to use for the comparison + //! @param threshold tolerance % # of comparison errors (0.15f = 15%) + //////////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutCompareubt( const unsigned char* reference, const unsigned char* data, + const unsigned int len, const float epsilon, const float threshold ); + + //////////////////////////////////////////////////////////////////////////////// + //! Compare two integer arrays witha n epsilon tolerance for equality + //! @return CUTTrue if \a reference and \a data are identical, + //! otherwise CUTFalse + //! @param reference handle to the reference data / gold image + //! @param data handle to the computed data + //! @param len number of elements in reference and data + //! @param epsilon epsilon to use for the comparison + //////////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutCompareube( const unsigned char* reference, const unsigned char* data, + const unsigned int len, const float epsilon ); + + //////////////////////////////////////////////////////////////////////////// + //! Compare two float arrays with an epsilon tolerance for equality + //! @return CUTTrue if \a reference and \a data are identical, + //! otherwise CUTFalse + //! @param reference handle to the reference data / gold image + //! @param data handle to the computed data + //! @param len number of elements in reference and data + //! @param epsilon epsilon to use for the comparison + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutComparefe( const float* reference, const float* data, + const unsigned int len, const float epsilon ); + + //////////////////////////////////////////////////////////////////////////////// + //! Compare two float arrays with an epsilon tolerance for equality and a + //! threshold for # pixel errors + //! @return CUTTrue if \a reference and \a data are identical, + //! otherwise CUTFalse + //! @param reference handle to the reference data / gold image + //! @param data handle to the computed data + //! @param len number of elements in reference and data + //! @param epsilon epsilon to use for the comparison + //////////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutComparefet( const float* reference, const float* data, + const unsigned int len, const float epsilon, const float threshold ); + + //////////////////////////////////////////////////////////////////////////// + //! Compare two float arrays using L2-norm with an epsilon tolerance for + //! equality + //! @return CUTTrue if \a reference and \a data are identical, + //! otherwise CUTFalse + //! @param reference handle to the reference data / gold image + //! @param data handle to the computed data + //! @param len number of elements in reference and data + //! @param epsilon epsilon to use for the comparison + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutCompareL2fe( const float* reference, const float* data, + const unsigned int len, const float epsilon ); + + //////////////////////////////////////////////////////////////////////////////// + //! Compare two PPM image files with an epsilon tolerance for equality + //! @return CUTTrue if \a reference and \a data are identical, + //! otherwise CUTFalse + //! @param src_file filename for the image to be compared + //! @param data filename for the reference data / gold image + //! @param epsilon epsilon to use for the comparison + //! @param threshold threshold of pixels that can still mismatch to pass (i.e. 0.15f = 15% must pass) + //! $param verboseErrors output details of image mismatch to std::err + //////////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutComparePPM( const char *src_file, const char *ref_file, const float epsilon, const float threshold, bool verboseErrors = false ); + + + //////////////////////////////////////////////////////////////////////////// + //! Timer functionality + + //////////////////////////////////////////////////////////////////////////// + //! Create a new timer + //! @return CUTTrue if a time has been created, otherwise false + //! @param name of the new timer, 0 if the creation failed + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutCreateTimer( unsigned int* name); + + //////////////////////////////////////////////////////////////////////////// + //! Delete a timer + //! @return CUTTrue if a time has been deleted, otherwise false + //! @param name of the timer to delete + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutDeleteTimer( unsigned int name); + + //////////////////////////////////////////////////////////////////////////// + //! Start the time with name \a name + //! @param name name of the timer to start + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutStartTimer( const unsigned int name); + + //////////////////////////////////////////////////////////////////////////// + //! Stop the time with name \a name. Does not reset. + //! @param name name of the timer to stop + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutStopTimer( const unsigned int name); + + //////////////////////////////////////////////////////////////////////////// + //! Resets the timer's counter. + //! @param name name of the timer to reset. + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + CUTBoolean CUTIL_API + cutResetTimer( const unsigned int name); + + //////////////////////////////////////////////////////////////////////////// + //! Returns total execution time in milliseconds for the timer over all + //! runs since the last reset or timer creation. + //! @param name name of the timer to return the time of + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + float CUTIL_API + cutGetTimerValue( const unsigned int name); + + //////////////////////////////////////////////////////////////////////////// + //! Return the average time in milliseconds for timer execution as the + //! total time for the timer dividied by the number of completed (stopped) + //! runs the timer has made. + //! Excludes the current running time if the timer is currently running. + //! @param name name of the timer to return the time of + //////////////////////////////////////////////////////////////////////////// + DLL_MAPPING + float CUTIL_API + cutGetAverageTimerValue( const unsigned int name); + + //////////////////////////////////////////////////////////////////////////// + //! Macros + +#if CUDART_VERSION >= 4000 +#define CUT_DEVICE_SYNCHRONIZE( ) cudaDeviceSynchronize(); +#else +#define CUT_DEVICE_SYNCHRONIZE( ) cudaThreadSynchronize(); +#endif + +#if CUDART_VERSION >= 4000 +#define CUT_DEVICE_RESET( ) cudaDeviceReset(); +#else +#define CUT_DEVICE_RESET( ) cudaThreadExit(); +#endif + +// This is for the CUTIL bank checker +#define CUT_BANK_CHECKER( array, index) array[index] + +# define CU_SAFE_CALL_NO_SYNC( call ) { \ + CUresult err = call; \ + if( CUDA_SUCCESS != err) { \ + fprintf(stderr, "Cuda driver error %x in file '%s' in line %i.\n", \ + err, __FILE__, __LINE__ ); \ + exit(EXIT_FAILURE); \ + } } + +# define CU_SAFE_CALL( call ) CU_SAFE_CALL_NO_SYNC(call); + +# define CU_SAFE_CTX_SYNC( ) { \ + CUresult err = cuCtxSynchronize(); \ + if( CUDA_SUCCESS != err) { \ + fprintf(stderr, "Cuda driver error %x in file '%s' in line %i.\n", \ + err, __FILE__, __LINE__ ); \ + exit(EXIT_FAILURE); \ + } } + +# define CUDA_SAFE_CALL_NO_SYNC( call) { \ + cudaError err = call; \ + if( cudaSuccess != err) { \ + fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \ + __FILE__, __LINE__, cudaGetErrorString( err) ); \ + exit(EXIT_FAILURE); \ + } } + +# define CUDA_SAFE_CALL( call) CUDA_SAFE_CALL_NO_SYNC(call); \ + +# define CUDA_SAFE_THREAD_SYNC( ) { \ + cudaError err = CUT_DEVICE_SYNCHRONIZE(); \ + if ( cudaSuccess != err) { \ + fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \ + __FILE__, __LINE__, cudaGetErrorString( err) ); \ + } } + +# define CUFFT_SAFE_CALL( call) { \ + cufftResult err = call; \ + if( CUFFT_SUCCESS != err) { \ + fprintf(stderr, "CUFFT error in file '%s' in line %i.\n", \ + __FILE__, __LINE__); \ + exit(EXIT_FAILURE); \ + } } + +# define CUT_SAFE_CALL( call) \ + if( CUTTrue != call) { \ + fprintf(stderr, "Cut error in file '%s' in line %i.\n", \ + __FILE__, __LINE__); \ + exit(EXIT_FAILURE); \ + } + + //! Check for CUDA error +#ifdef _DEBUG +# define CUT_CHECK_ERROR(errorMessage) { \ + cudaError_t err = cudaGetLastError(); \ + if( cudaSuccess != err) { \ + fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \ + errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\ + exit(EXIT_FAILURE); \ + } \ + err = CUT_DEVICE_SYNCHRONIZE(); \ + if( cudaSuccess != err) { \ + fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \ + errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\ + exit(EXIT_FAILURE); \ + } \ + } +#else +# define CUT_CHECK_ERROR(errorMessage) { \ + cudaError_t err = cudaGetLastError(); \ + if( cudaSuccess != err) { \ + fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \ + errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\ + exit(EXIT_FAILURE); \ + } \ + } +#endif + + //! Check for malloc error +# define CUT_SAFE_MALLOC( mallocCall ) { \ + if( !(mallocCall)) { \ + fprintf(stderr, "Host malloc failure in file '%s' in line %i\n", \ + __FILE__, __LINE__); \ + exit(EXIT_FAILURE); \ + } } while(0); + + //! Check if conditon is true (flexible assert) +# define CUT_CONDITION( val) \ + if( CUTFalse == cutCheckCondition( val, __FILE__, __LINE__)) { \ + exit(EXIT_FAILURE); \ + } + +# define CUT_DEVICE_INIT(ARGC, ARGV) { \ + int deviceCount; \ + CUDA_SAFE_CALL_NO_SYNC(cudaGetDeviceCount(&deviceCount)); \ + if (deviceCount == 0) { \ + fprintf(stderr, "cutil error: no devices supporting CUDA.\n"); \ + exit(EXIT_FAILURE); \ + } \ + int dev = 0; \ + cutGetCmdLineArgumenti(ARGC, (const char **) ARGV, "device", &dev); \ + if (dev < 0) dev = 0; \ + if (dev > deviceCount-1) dev = deviceCount - 1; \ + cudaDeviceProp deviceProp; \ + CUDA_SAFE_CALL_NO_SYNC(cudaGetDeviceProperties(&deviceProp, dev)); \ + if (cutCheckCmdLineFlag(ARGC, (const char **) ARGV, "quiet") == CUTFalse) \ + fprintf(stderr, "Using device %d: %s\n", dev, deviceProp.name); \ + CUDA_SAFE_CALL(cudaSetDevice(dev)); \ +} + + + //! Check for CUDA context lost +# define CUDA_CHECK_CTX_LOST(errorMessage) { \ + cudaError_t err = cudaGetLastError(); \ + if( cudaSuccess != err) { \ + fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \ + errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\ + exit(EXIT_FAILURE); \ + } \ + err = CUT_DEVICE_SYNCHRONIZE(); \ + if( cudaSuccess != err) { \ + fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \ + errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\ + exit(EXIT_FAILURE); \ + } } + +//! Check for CUDA context lost +# define CU_CHECK_CTX_LOST(errorMessage) { \ + cudaError_t err = cudaGetLastError(); \ + if( CUDA_ERROR_INVALID_CONTEXT != err) { \ + fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \ + errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\ + exit(EXIT_FAILURE); \ + } \ + err = CUT_DEVICE_SYNCHRONIZE(); \ + if( cudaSuccess != err) { \ + fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \ + errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\ + exit(EXIT_FAILURE); \ + } } + +# define CUT_DEVICE_INIT_DRV(cuDevice, ARGC, ARGV) { \ + cuDevice = 0; \ + int deviceCount = 0; \ + CUresult err = cuInit(0); \ + if (CUDA_SUCCESS == err) \ + CU_SAFE_CALL_NO_SYNC(cuDeviceGetCount(&deviceCount)); \ + if (deviceCount == 0) { \ + fprintf(stderr, "cutil error: no devices supporting CUDA\n"); \ + exit(EXIT_FAILURE); \ + } \ + int dev = 0; \ + cutGetCmdLineArgumenti(ARGC, (const char **) ARGV, "device", &dev); \ + if (dev < 0) dev = 0; \ + if (dev > deviceCount-1) dev = deviceCount - 1; \ + CU_SAFE_CALL_NO_SYNC(cuDeviceGet(&cuDevice, dev)); \ + char name[100]; \ + cuDeviceGetName(name, 100, cuDevice); \ + if (cutCheckCmdLineFlag(ARGC, (const char **) ARGV, "quiet") == CUTFalse) \ + fprintf(stderr, "Using device %d: %s\n", dev, name); \ +} + +#define CUT_EXIT(argc, argv) \ + if (!cutCheckCmdLineFlag(argc, (const char**)argv, "noprompt")) { \ + printf("\nPress ENTER to exit...\n"); \ + fflush( stdout); \ + fflush( stderr); \ + getchar(); \ + } \ + exit(EXIT_SUCCESS); + + +#ifdef __cplusplus +} +#endif // #ifdef _DEBUG (else branch) + +#endif // #ifndef _CUTIL_H_ diff --git a/src/cuda/common/sdk-compat/inc/cutil_math.h b/src/cuda/common/sdk-compat/inc/cutil_math.h new file mode 100644 index 000000000..cc3f7081e --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/cutil_math.h @@ -0,0 +1,1328 @@ +/* + * Copyright 1993-2012 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + +/* + This file implements common mathematical operations on vector types + (float3, float4 etc.) since these are not provided as standard by CUDA. + + The syntax is modelled on the Cg standard library. + + This is part of the CUTIL library and is not supported by NVIDIA. + + Thanks to Linh Hah for additions and fixes. +*/ + +#ifndef CUTIL_MATH_H +#define CUTIL_MATH_H + +#include "cuda_runtime.h" + +typedef unsigned int uint; +typedef unsigned short ushort; + +#ifndef __CUDACC__ +#include + +//////////////////////////////////////////////////////////////////////////////// +// host implementations of CUDA functions +//////////////////////////////////////////////////////////////////////////////// + +inline float fminf(float a, float b) +{ + return a < b ? a : b; +} + +inline float fmaxf(float a, float b) +{ + return a > b ? a : b; +} + +inline int max(int a, int b) +{ + return a > b ? a : b; +} + +inline int min(int a, int b) +{ + return a < b ? a : b; +} + +inline float rsqrtf(float x) +{ + return 1.0f / sqrtf(x); +} +#endif + +//////////////////////////////////////////////////////////////////////////////// +// constructors +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float2 make_float2(float s) +{ + return make_float2(s, s); +} +inline __host__ __device__ float2 make_float2(float3 a) +{ + return make_float2(a.x, a.y); +} +inline __host__ __device__ float2 make_float2(int2 a) +{ + return make_float2(float(a.x), float(a.y)); +} +inline __host__ __device__ float2 make_float2(uint2 a) +{ + return make_float2(float(a.x), float(a.y)); +} + +inline __host__ __device__ int2 make_int2(int s) +{ + return make_int2(s, s); +} +inline __host__ __device__ int2 make_int2(int3 a) +{ + return make_int2(a.x, a.y); +} +inline __host__ __device__ int2 make_int2(uint2 a) +{ + return make_int2(int(a.x), int(a.y)); +} +inline __host__ __device__ int2 make_int2(float2 a) +{ + return make_int2(int(a.x), int(a.y)); +} + +inline __host__ __device__ uint2 make_uint2(uint s) +{ + return make_uint2(s, s); +} +inline __host__ __device__ uint2 make_uint2(uint3 a) +{ + return make_uint2(a.x, a.y); +} +inline __host__ __device__ uint2 make_uint2(int2 a) +{ + return make_uint2(uint(a.x), uint(a.y)); +} + +inline __host__ __device__ float3 make_float3(float s) +{ + return make_float3(s, s, s); +} +inline __host__ __device__ float3 make_float3(float2 a) +{ + return make_float3(a.x, a.y, 0.0f); +} +inline __host__ __device__ float3 make_float3(float2 a, float s) +{ + return make_float3(a.x, a.y, s); +} +inline __host__ __device__ float3 make_float3(float4 a) +{ + return make_float3(a.x, a.y, a.z); +} +inline __host__ __device__ float3 make_float3(int3 a) +{ + return make_float3(float(a.x), float(a.y), float(a.z)); +} +inline __host__ __device__ float3 make_float3(uint3 a) +{ + return make_float3(float(a.x), float(a.y), float(a.z)); +} + +inline __host__ __device__ int3 make_int3(int s) +{ + return make_int3(s, s, s); +} +inline __host__ __device__ int3 make_int3(int2 a) +{ + return make_int3(a.x, a.y, 0); +} +inline __host__ __device__ int3 make_int3(int2 a, int s) +{ + return make_int3(a.x, a.y, s); +} +inline __host__ __device__ int3 make_int3(uint3 a) +{ + return make_int3(int(a.x), int(a.y), int(a.z)); +} +inline __host__ __device__ int3 make_int3(float3 a) +{ + return make_int3(int(a.x), int(a.y), int(a.z)); +} + +inline __host__ __device__ uint3 make_uint3(uint s) +{ + return make_uint3(s, s, s); +} +inline __host__ __device__ uint3 make_uint3(uint2 a) +{ + return make_uint3(a.x, a.y, 0); +} +inline __host__ __device__ uint3 make_uint3(uint2 a, uint s) +{ + return make_uint3(a.x, a.y, s); +} +inline __host__ __device__ uint3 make_uint3(uint4 a) +{ + return make_uint3(a.x, a.y, a.z); +} +inline __host__ __device__ uint3 make_uint3(int3 a) +{ + return make_uint3(uint(a.x), uint(a.y), uint(a.z)); +} + +inline __host__ __device__ float4 make_float4(float s) +{ + return make_float4(s, s, s, s); +} +inline __host__ __device__ float4 make_float4(float3 a) +{ + return make_float4(a.x, a.y, a.z, 0.0f); +} +inline __host__ __device__ float4 make_float4(float3 a, float w) +{ + return make_float4(a.x, a.y, a.z, w); +} +inline __host__ __device__ float4 make_float4(int4 a) +{ + return make_float4(float(a.x), float(a.y), float(a.z), float(a.w)); +} +inline __host__ __device__ float4 make_float4(uint4 a) +{ + return make_float4(float(a.x), float(a.y), float(a.z), float(a.w)); +} + +inline __host__ __device__ int4 make_int4(int s) +{ + return make_int4(s, s, s, s); +} +inline __host__ __device__ int4 make_int4(int3 a) +{ + return make_int4(a.x, a.y, a.z, 0); +} +inline __host__ __device__ int4 make_int4(int3 a, int w) +{ + return make_int4(a.x, a.y, a.z, w); +} +inline __host__ __device__ int4 make_int4(uint4 a) +{ + return make_int4(int(a.x), int(a.y), int(a.z), int(a.w)); +} +inline __host__ __device__ int4 make_int4(float4 a) +{ + return make_int4(int(a.x), int(a.y), int(a.z), int(a.w)); +} + + +inline __host__ __device__ uint4 make_uint4(uint s) +{ + return make_uint4(s, s, s, s); +} +inline __host__ __device__ uint4 make_uint4(uint3 a) +{ + return make_uint4(a.x, a.y, a.z, 0); +} +inline __host__ __device__ uint4 make_uint4(uint3 a, uint w) +{ + return make_uint4(a.x, a.y, a.z, w); +} +inline __host__ __device__ uint4 make_uint4(int4 a) +{ + return make_uint4(uint(a.x), uint(a.y), uint(a.z), uint(a.w)); +} + +//////////////////////////////////////////////////////////////////////////////// +// negate +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float2 operator-(float2 &a) +{ + return make_float2(-a.x, -a.y); +} +inline __host__ __device__ int2 operator-(int2 &a) +{ + return make_int2(-a.x, -a.y); +} +inline __host__ __device__ float3 operator-(float3 &a) +{ + return make_float3(-a.x, -a.y, -a.z); +} +inline __host__ __device__ int3 operator-(int3 &a) +{ + return make_int3(-a.x, -a.y, -a.z); +} +inline __host__ __device__ float4 operator-(float4 &a) +{ + return make_float4(-a.x, -a.y, -a.z, -a.w); +} +inline __host__ __device__ int4 operator-(int4 &a) +{ + return make_int4(-a.x, -a.y, -a.z, -a.w); +} + +//////////////////////////////////////////////////////////////////////////////// +// addition +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float2 operator+(float2 a, float2 b) +{ + return make_float2(a.x + b.x, a.y + b.y); +} +inline __host__ __device__ void operator+=(float2 &a, float2 b) +{ + a.x += b.x; a.y += b.y; +} +inline __host__ __device__ float2 operator+(float2 a, float b) +{ + return make_float2(a.x + b, a.y + b); +} +inline __host__ __device__ float2 operator+(float b, float2 a) +{ + return make_float2(a.x + b, a.y + b); +} +inline __host__ __device__ void operator+=(float2 &a, float b) +{ + a.x += b; a.y += b; +} + +inline __host__ __device__ int2 operator+(int2 a, int2 b) +{ + return make_int2(a.x + b.x, a.y + b.y); +} +inline __host__ __device__ void operator+=(int2 &a, int2 b) +{ + a.x += b.x; a.y += b.y; +} +inline __host__ __device__ int2 operator+(int2 a, int b) +{ + return make_int2(a.x + b, a.y + b); +} +inline __host__ __device__ int2 operator+(int b, int2 a) +{ + return make_int2(a.x + b, a.y + b); +} +inline __host__ __device__ void operator+=(int2 &a, int b) +{ + a.x += b; a.y += b; +} + +inline __host__ __device__ uint2 operator+(uint2 a, uint2 b) +{ + return make_uint2(a.x + b.x, a.y + b.y); +} +inline __host__ __device__ void operator+=(uint2 &a, uint2 b) +{ + a.x += b.x; a.y += b.y; +} +inline __host__ __device__ uint2 operator+(uint2 a, uint b) +{ + return make_uint2(a.x + b, a.y + b); +} +inline __host__ __device__ uint2 operator+(uint b, uint2 a) +{ + return make_uint2(a.x + b, a.y + b); +} +inline __host__ __device__ void operator+=(uint2 &a, uint b) +{ + a.x += b; a.y += b; +} + + +inline __host__ __device__ float3 operator+(float3 a, float3 b) +{ + return make_float3(a.x + b.x, a.y + b.y, a.z + b.z); +} +inline __host__ __device__ void operator+=(float3 &a, float3 b) +{ + a.x += b.x; a.y += b.y; a.z += b.z; +} +inline __host__ __device__ float3 operator+(float3 a, float b) +{ + return make_float3(a.x + b, a.y + b, a.z + b); +} +inline __host__ __device__ void operator+=(float3 &a, float b) +{ + a.x += b; a.y += b; a.z += b; +} + +inline __host__ __device__ int3 operator+(int3 a, int3 b) +{ + return make_int3(a.x + b.x, a.y + b.y, a.z + b.z); +} +inline __host__ __device__ void operator+=(int3 &a, int3 b) +{ + a.x += b.x; a.y += b.y; a.z += b.z; +} +inline __host__ __device__ int3 operator+(int3 a, int b) +{ + return make_int3(a.x + b, a.y + b, a.z + b); +} +inline __host__ __device__ void operator+=(int3 &a, int b) +{ + a.x += b; a.y += b; a.z += b; +} + +inline __host__ __device__ uint3 operator+(uint3 a, uint3 b) +{ + return make_uint3(a.x + b.x, a.y + b.y, a.z + b.z); +} +inline __host__ __device__ void operator+=(uint3 &a, uint3 b) +{ + a.x += b.x; a.y += b.y; a.z += b.z; +} +inline __host__ __device__ uint3 operator+(uint3 a, uint b) +{ + return make_uint3(a.x + b, a.y + b, a.z + b); +} +inline __host__ __device__ void operator+=(uint3 &a, uint b) +{ + a.x += b; a.y += b; a.z += b; +} + +inline __host__ __device__ int3 operator+(int b, int3 a) +{ + return make_int3(a.x + b, a.y + b, a.z + b); +} +inline __host__ __device__ uint3 operator+(uint b, uint3 a) +{ + return make_uint3(a.x + b, a.y + b, a.z + b); +} +inline __host__ __device__ float3 operator+(float b, float3 a) +{ + return make_float3(a.x + b, a.y + b, a.z + b); +} + +inline __host__ __device__ float4 operator+(float4 a, float4 b) +{ + return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); +} +inline __host__ __device__ void operator+=(float4 &a, float4 b) +{ + a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w; +} +inline __host__ __device__ float4 operator+(float4 a, float b) +{ + return make_float4(a.x + b, a.y + b, a.z + b, a.w + b); +} +inline __host__ __device__ float4 operator+(float b, float4 a) +{ + return make_float4(a.x + b, a.y + b, a.z + b, a.w + b); +} +inline __host__ __device__ void operator+=(float4 &a, float b) +{ + a.x += b; a.y += b; a.z += b; a.w += b; +} + +inline __host__ __device__ int4 operator+(int4 a, int4 b) +{ + return make_int4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); +} +inline __host__ __device__ void operator+=(int4 &a, int4 b) +{ + a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w; +} +inline __host__ __device__ int4 operator+(int4 a, int b) +{ + return make_int4(a.x + b, a.y + b, a.z + b, a.w + b); +} +inline __host__ __device__ int4 operator+(int b, int4 a) +{ + return make_int4(a.x + b, a.y + b, a.z + b, a.w + b); +} +inline __host__ __device__ void operator+=(int4 &a, int b) +{ + a.x += b; a.y += b; a.z += b; a.w += b; +} + +inline __host__ __device__ uint4 operator+(uint4 a, uint4 b) +{ + return make_uint4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); +} +inline __host__ __device__ void operator+=(uint4 &a, uint4 b) +{ + a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w; +} +inline __host__ __device__ uint4 operator+(uint4 a, uint b) +{ + return make_uint4(a.x + b, a.y + b, a.z + b, a.w + b); +} +inline __host__ __device__ uint4 operator+(uint b, uint4 a) +{ + return make_uint4(a.x + b, a.y + b, a.z + b, a.w + b); +} +inline __host__ __device__ void operator+=(uint4 &a, uint b) +{ + a.x += b; a.y += b; a.z += b; a.w += b; +} + +//////////////////////////////////////////////////////////////////////////////// +// subtract +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float2 operator-(float2 a, float2 b) +{ + return make_float2(a.x - b.x, a.y - b.y); +} +inline __host__ __device__ void operator-=(float2 &a, float2 b) +{ + a.x -= b.x; a.y -= b.y; +} +inline __host__ __device__ float2 operator-(float2 a, float b) +{ + return make_float2(a.x - b, a.y - b); +} +inline __host__ __device__ float2 operator-(float b, float2 a) +{ + return make_float2(b - a.x, b - a.y); +} +inline __host__ __device__ void operator-=(float2 &a, float b) +{ + a.x -= b; a.y -= b; +} + +inline __host__ __device__ int2 operator-(int2 a, int2 b) +{ + return make_int2(a.x - b.x, a.y - b.y); +} +inline __host__ __device__ void operator-=(int2 &a, int2 b) +{ + a.x -= b.x; a.y -= b.y; +} +inline __host__ __device__ int2 operator-(int2 a, int b) +{ + return make_int2(a.x - b, a.y - b); +} +inline __host__ __device__ int2 operator-(int b, int2 a) +{ + return make_int2(b - a.x, b - a.y); +} +inline __host__ __device__ void operator-=(int2 &a, int b) +{ + a.x -= b; a.y -= b; +} + +inline __host__ __device__ uint2 operator-(uint2 a, uint2 b) +{ + return make_uint2(a.x - b.x, a.y - b.y); +} +inline __host__ __device__ void operator-=(uint2 &a, uint2 b) +{ + a.x -= b.x; a.y -= b.y; +} +inline __host__ __device__ uint2 operator-(uint2 a, uint b) +{ + return make_uint2(a.x - b, a.y - b); +} +inline __host__ __device__ uint2 operator-(uint b, uint2 a) +{ + return make_uint2(b - a.x, b - a.y); +} +inline __host__ __device__ void operator-=(uint2 &a, uint b) +{ + a.x -= b; a.y -= b; +} + +inline __host__ __device__ float3 operator-(float3 a, float3 b) +{ + return make_float3(a.x - b.x, a.y - b.y, a.z - b.z); +} +inline __host__ __device__ void operator-=(float3 &a, float3 b) +{ + a.x -= b.x; a.y -= b.y; a.z -= b.z; +} +inline __host__ __device__ float3 operator-(float3 a, float b) +{ + return make_float3(a.x - b, a.y - b, a.z - b); +} +inline __host__ __device__ float3 operator-(float b, float3 a) +{ + return make_float3(b - a.x, b - a.y, b - a.z); +} +inline __host__ __device__ void operator-=(float3 &a, float b) +{ + a.x -= b; a.y -= b; a.z -= b; +} + +inline __host__ __device__ int3 operator-(int3 a, int3 b) +{ + return make_int3(a.x - b.x, a.y - b.y, a.z - b.z); +} +inline __host__ __device__ void operator-=(int3 &a, int3 b) +{ + a.x -= b.x; a.y -= b.y; a.z -= b.z; +} +inline __host__ __device__ int3 operator-(int3 a, int b) +{ + return make_int3(a.x - b, a.y - b, a.z - b); +} +inline __host__ __device__ int3 operator-(int b, int3 a) +{ + return make_int3(b - a.x, b - a.y, b - a.z); +} +inline __host__ __device__ void operator-=(int3 &a, int b) +{ + a.x -= b; a.y -= b; a.z -= b; +} + +inline __host__ __device__ uint3 operator-(uint3 a, uint3 b) +{ + return make_uint3(a.x - b.x, a.y - b.y, a.z - b.z); +} +inline __host__ __device__ void operator-=(uint3 &a, uint3 b) +{ + a.x -= b.x; a.y -= b.y; a.z -= b.z; +} +inline __host__ __device__ uint3 operator-(uint3 a, uint b) +{ + return make_uint3(a.x - b, a.y - b, a.z - b); +} +inline __host__ __device__ uint3 operator-(uint b, uint3 a) +{ + return make_uint3(b - a.x, b - a.y, b - a.z); +} +inline __host__ __device__ void operator-=(uint3 &a, uint b) +{ + a.x -= b; a.y -= b; a.z -= b; +} + +inline __host__ __device__ float4 operator-(float4 a, float4 b) +{ + return make_float4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); +} +inline __host__ __device__ void operator-=(float4 &a, float4 b) +{ + a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w; +} +inline __host__ __device__ float4 operator-(float4 a, float b) +{ + return make_float4(a.x - b, a.y - b, a.z - b, a.w - b); +} +inline __host__ __device__ void operator-=(float4 &a, float b) +{ + a.x -= b; a.y -= b; a.z -= b; a.w -= b; +} + +inline __host__ __device__ int4 operator-(int4 a, int4 b) +{ + return make_int4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); +} +inline __host__ __device__ void operator-=(int4 &a, int4 b) +{ + a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w; +} +inline __host__ __device__ int4 operator-(int4 a, int b) +{ + return make_int4(a.x - b, a.y - b, a.z - b, a.w - b); +} +inline __host__ __device__ int4 operator-(int b, int4 a) +{ + return make_int4(b - a.x, b - a.y, b - a.z, b - a.w); +} +inline __host__ __device__ void operator-=(int4 &a, int b) +{ + a.x -= b; a.y -= b; a.z -= b; a.w -= b; +} + +inline __host__ __device__ uint4 operator-(uint4 a, uint4 b) +{ + return make_uint4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); +} +inline __host__ __device__ void operator-=(uint4 &a, uint4 b) +{ + a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w; +} +inline __host__ __device__ uint4 operator-(uint4 a, uint b) +{ + return make_uint4(a.x - b, a.y - b, a.z - b, a.w - b); +} +inline __host__ __device__ uint4 operator-(uint b, uint4 a) +{ + return make_uint4(b - a.x, b - a.y, b - a.z, b - a.w); +} +inline __host__ __device__ void operator-=(uint4 &a, uint b) +{ + a.x -= b; a.y -= b; a.z -= b; a.w -= b; +} + +//////////////////////////////////////////////////////////////////////////////// +// multiply +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float2 operator*(float2 a, float2 b) +{ + return make_float2(a.x * b.x, a.y * b.y); +} +inline __host__ __device__ void operator*=(float2 &a, float2 b) +{ + a.x *= b.x; a.y *= b.y; +} +inline __host__ __device__ float2 operator*(float2 a, float b) +{ + return make_float2(a.x * b, a.y * b); +} +inline __host__ __device__ float2 operator*(float b, float2 a) +{ + return make_float2(b * a.x, b * a.y); +} +inline __host__ __device__ void operator*=(float2 &a, float b) +{ + a.x *= b; a.y *= b; +} + +inline __host__ __device__ int2 operator*(int2 a, int2 b) +{ + return make_int2(a.x * b.x, a.y * b.y); +} +inline __host__ __device__ void operator*=(int2 &a, int2 b) +{ + a.x *= b.x; a.y *= b.y; +} +inline __host__ __device__ int2 operator*(int2 a, int b) +{ + return make_int2(a.x * b, a.y * b); +} +inline __host__ __device__ int2 operator*(int b, int2 a) +{ + return make_int2(b * a.x, b * a.y); +} +inline __host__ __device__ void operator*=(int2 &a, int b) +{ + a.x *= b; a.y *= b; +} + +inline __host__ __device__ uint2 operator*(uint2 a, uint2 b) +{ + return make_uint2(a.x * b.x, a.y * b.y); +} +inline __host__ __device__ void operator*=(uint2 &a, uint2 b) +{ + a.x *= b.x; a.y *= b.y; +} +inline __host__ __device__ uint2 operator*(uint2 a, uint b) +{ + return make_uint2(a.x * b, a.y * b); +} +inline __host__ __device__ uint2 operator*(uint b, uint2 a) +{ + return make_uint2(b * a.x, b * a.y); +} +inline __host__ __device__ void operator*=(uint2 &a, uint b) +{ + a.x *= b; a.y *= b; +} + +inline __host__ __device__ float3 operator*(float3 a, float3 b) +{ + return make_float3(a.x * b.x, a.y * b.y, a.z * b.z); +} +inline __host__ __device__ void operator*=(float3 &a, float3 b) +{ + a.x *= b.x; a.y *= b.y; a.z *= b.z; +} +inline __host__ __device__ float3 operator*(float3 a, float b) +{ + return make_float3(a.x * b, a.y * b, a.z * b); +} +inline __host__ __device__ float3 operator*(float b, float3 a) +{ + return make_float3(b * a.x, b * a.y, b * a.z); +} +inline __host__ __device__ void operator*=(float3 &a, float b) +{ + a.x *= b; a.y *= b; a.z *= b; +} + +inline __host__ __device__ int3 operator*(int3 a, int3 b) +{ + return make_int3(a.x * b.x, a.y * b.y, a.z * b.z); +} +inline __host__ __device__ void operator*=(int3 &a, int3 b) +{ + a.x *= b.x; a.y *= b.y; a.z *= b.z; +} +inline __host__ __device__ int3 operator*(int3 a, int b) +{ + return make_int3(a.x * b, a.y * b, a.z * b); +} +inline __host__ __device__ int3 operator*(int b, int3 a) +{ + return make_int3(b * a.x, b * a.y, b * a.z); +} +inline __host__ __device__ void operator*=(int3 &a, int b) +{ + a.x *= b; a.y *= b; a.z *= b; +} + +inline __host__ __device__ uint3 operator*(uint3 a, uint3 b) +{ + return make_uint3(a.x * b.x, a.y * b.y, a.z * b.z); +} +inline __host__ __device__ void operator*=(uint3 &a, uint3 b) +{ + a.x *= b.x; a.y *= b.y; a.z *= b.z; +} +inline __host__ __device__ uint3 operator*(uint3 a, uint b) +{ + return make_uint3(a.x * b, a.y * b, a.z * b); +} +inline __host__ __device__ uint3 operator*(uint b, uint3 a) +{ + return make_uint3(b * a.x, b * a.y, b * a.z); +} +inline __host__ __device__ void operator*=(uint3 &a, uint b) +{ + a.x *= b; a.y *= b; a.z *= b; +} + +inline __host__ __device__ float4 operator*(float4 a, float4 b) +{ + return make_float4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); +} +inline __host__ __device__ void operator*=(float4 &a, float4 b) +{ + a.x *= b.x; a.y *= b.y; a.z *= b.z; a.w *= b.w; +} +inline __host__ __device__ float4 operator*(float4 a, float b) +{ + return make_float4(a.x * b, a.y * b, a.z * b, a.w * b); +} +inline __host__ __device__ float4 operator*(float b, float4 a) +{ + return make_float4(b * a.x, b * a.y, b * a.z, b * a.w); +} +inline __host__ __device__ void operator*=(float4 &a, float b) +{ + a.x *= b; a.y *= b; a.z *= b; a.w *= b; +} + +inline __host__ __device__ int4 operator*(int4 a, int4 b) +{ + return make_int4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); +} +inline __host__ __device__ void operator*=(int4 &a, int4 b) +{ + a.x *= b.x; a.y *= b.y; a.z *= b.z; a.w *= b.w; +} +inline __host__ __device__ int4 operator*(int4 a, int b) +{ + return make_int4(a.x * b, a.y * b, a.z * b, a.w * b); +} +inline __host__ __device__ int4 operator*(int b, int4 a) +{ + return make_int4(b * a.x, b * a.y, b * a.z, b * a.w); +} +inline __host__ __device__ void operator*=(int4 &a, int b) +{ + a.x *= b; a.y *= b; a.z *= b; a.w *= b; +} + +inline __host__ __device__ uint4 operator*(uint4 a, uint4 b) +{ + return make_uint4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); +} +inline __host__ __device__ void operator*=(uint4 &a, uint4 b) +{ + a.x *= b.x; a.y *= b.y; a.z *= b.z; a.w *= b.w; +} +inline __host__ __device__ uint4 operator*(uint4 a, uint b) +{ + return make_uint4(a.x * b, a.y * b, a.z * b, a.w * b); +} +inline __host__ __device__ uint4 operator*(uint b, uint4 a) +{ + return make_uint4(b * a.x, b * a.y, b * a.z, b * a.w); +} +inline __host__ __device__ void operator*=(uint4 &a, uint b) +{ + a.x *= b; a.y *= b; a.z *= b; a.w *= b; +} + +//////////////////////////////////////////////////////////////////////////////// +// divide +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float2 operator/(float2 a, float2 b) +{ + return make_float2(a.x / b.x, a.y / b.y); +} +inline __host__ __device__ void operator/=(float2 &a, float2 b) +{ + a.x /= b.x; a.y /= b.y; +} +inline __host__ __device__ float2 operator/(float2 a, float b) +{ + return make_float2(a.x / b, a.y / b); +} +inline __host__ __device__ void operator/=(float2 &a, float b) +{ + a.x /= b; a.y /= b; +} +inline __host__ __device__ float2 operator/(float b, float2 a) +{ + return make_float2(b / a.x, b / a.y); +} + +inline __host__ __device__ float3 operator/(float3 a, float3 b) +{ + return make_float3(a.x / b.x, a.y / b.y, a.z / b.z); +} +inline __host__ __device__ void operator/=(float3 &a, float3 b) +{ + a.x /= b.x; a.y /= b.y; a.z /= b.z; +} +inline __host__ __device__ float3 operator/(float3 a, float b) +{ + return make_float3(a.x / b, a.y / b, a.z / b); +} +inline __host__ __device__ void operator/=(float3 &a, float b) +{ + a.x /= b; a.y /= b; a.z /= b; +} +inline __host__ __device__ float3 operator/(float b, float3 a) +{ + return make_float3(b / a.x, b / a.y, b / a.z); +} + +inline __host__ __device__ float4 operator/(float4 a, float4 b) +{ + return make_float4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w); +} +inline __host__ __device__ void operator/=(float4 &a, float4 b) +{ + a.x /= b.x; a.y /= b.y; a.z /= b.z; a.w /= b.w; +} +inline __host__ __device__ float4 operator/(float4 a, float b) +{ + return make_float4(a.x / b, a.y / b, a.z / b, a.w / b); +} +inline __host__ __device__ void operator/=(float4 &a, float b) +{ + a.x /= b; a.y /= b; a.z /= b; a.w /= b; +} +inline __host__ __device__ float4 operator/(float b, float4 a){ + return make_float4(b / a.x, b / a.y, b / a.z, b / a.w); +} + +//////////////////////////////////////////////////////////////////////////////// +// min +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float2 fminf(float2 a, float2 b) +{ + return make_float2(fminf(a.x,b.x), fminf(a.y,b.y)); +} +inline __host__ __device__ float3 fminf(float3 a, float3 b) +{ + return make_float3(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z)); +} +inline __host__ __device__ float4 fminf(float4 a, float4 b) +{ + return make_float4(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z), fminf(a.w,b.w)); +} + +inline __host__ __device__ int2 min(int2 a, int2 b) +{ + return make_int2(min(a.x,b.x), min(a.y,b.y)); +} +inline __host__ __device__ int3 min(int3 a, int3 b) +{ + return make_int3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z)); +} +inline __host__ __device__ int4 min(int4 a, int4 b) +{ + return make_int4(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z), min(a.w,b.w)); +} + +inline __host__ __device__ uint2 min(uint2 a, uint2 b) +{ + return make_uint2(min(a.x,b.x), min(a.y,b.y)); +} +inline __host__ __device__ uint3 min(uint3 a, uint3 b) +{ + return make_uint3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z)); +} +inline __host__ __device__ uint4 min(uint4 a, uint4 b) +{ + return make_uint4(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z), min(a.w,b.w)); +} + +//////////////////////////////////////////////////////////////////////////////// +// max +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float2 fmaxf(float2 a, float2 b) +{ + return make_float2(fmaxf(a.x,b.x), fmaxf(a.y,b.y)); +} +inline __host__ __device__ float3 fmaxf(float3 a, float3 b) +{ + return make_float3(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z)); +} +inline __host__ __device__ float4 fmaxf(float4 a, float4 b) +{ + return make_float4(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z), fmaxf(a.w,b.w)); +} + +inline __host__ __device__ int2 max(int2 a, int2 b) +{ + return make_int2(max(a.x,b.x), max(a.y,b.y)); +} +inline __host__ __device__ int3 max(int3 a, int3 b) +{ + return make_int3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z)); +} +inline __host__ __device__ int4 max(int4 a, int4 b) +{ + return make_int4(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z), max(a.w,b.w)); +} + +inline __host__ __device__ uint2 max(uint2 a, uint2 b) +{ + return make_uint2(max(a.x,b.x), max(a.y,b.y)); +} +inline __host__ __device__ uint3 max(uint3 a, uint3 b) +{ + return make_uint3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z)); +} +inline __host__ __device__ uint4 max(uint4 a, uint4 b) +{ + return make_uint4(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z), max(a.w,b.w)); +} + +//////////////////////////////////////////////////////////////////////////////// +// lerp +// - linear interpolation between a and b, based on value t in [0, 1] range +//////////////////////////////////////////////////////////////////////////////// + +inline __device__ __host__ float lerp(float a, float b, float t) +{ + return a + t*(b-a); +} +inline __device__ __host__ float2 lerp(float2 a, float2 b, float t) +{ + return a + t*(b-a); +} +inline __device__ __host__ float3 lerp(float3 a, float3 b, float t) +{ + return a + t*(b-a); +} +inline __device__ __host__ float4 lerp(float4 a, float4 b, float t) +{ + return a + t*(b-a); +} + +//////////////////////////////////////////////////////////////////////////////// +// clamp +// - clamp the value v to be in the range [a, b] +//////////////////////////////////////////////////////////////////////////////// + +inline __device__ __host__ float clamp(float f, float a, float b) +{ + return fmaxf(a, fminf(f, b)); +} +inline __device__ __host__ int clamp(int f, int a, int b) +{ + return max(a, min(f, b)); +} +inline __device__ __host__ uint clamp(uint f, uint a, uint b) +{ + return max(a, min(f, b)); +} + +inline __device__ __host__ float2 clamp(float2 v, float a, float b) +{ + return make_float2(clamp(v.x, a, b), clamp(v.y, a, b)); +} +inline __device__ __host__ float2 clamp(float2 v, float2 a, float2 b) +{ + return make_float2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y)); +} +inline __device__ __host__ float3 clamp(float3 v, float a, float b) +{ + return make_float3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b)); +} +inline __device__ __host__ float3 clamp(float3 v, float3 a, float3 b) +{ + return make_float3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z)); +} +inline __device__ __host__ float4 clamp(float4 v, float a, float b) +{ + return make_float4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b)); +} +inline __device__ __host__ float4 clamp(float4 v, float4 a, float4 b) +{ + return make_float4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w)); +} + +inline __device__ __host__ int2 clamp(int2 v, int a, int b) +{ + return make_int2(clamp(v.x, a, b), clamp(v.y, a, b)); +} +inline __device__ __host__ int2 clamp(int2 v, int2 a, int2 b) +{ + return make_int2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y)); +} +inline __device__ __host__ int3 clamp(int3 v, int a, int b) +{ + return make_int3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b)); +} +inline __device__ __host__ int3 clamp(int3 v, int3 a, int3 b) +{ + return make_int3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z)); +} +inline __device__ __host__ int4 clamp(int4 v, int a, int b) +{ + return make_int4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b)); +} +inline __device__ __host__ int4 clamp(int4 v, int4 a, int4 b) +{ + return make_int4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w)); +} + +inline __device__ __host__ uint2 clamp(uint2 v, uint a, uint b) +{ + return make_uint2(clamp(v.x, a, b), clamp(v.y, a, b)); +} +inline __device__ __host__ uint2 clamp(uint2 v, uint2 a, uint2 b) +{ + return make_uint2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y)); +} +inline __device__ __host__ uint3 clamp(uint3 v, uint a, uint b) +{ + return make_uint3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b)); +} +inline __device__ __host__ uint3 clamp(uint3 v, uint3 a, uint3 b) +{ + return make_uint3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z)); +} +inline __device__ __host__ uint4 clamp(uint4 v, uint a, uint b) +{ + return make_uint4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b)); +} +inline __device__ __host__ uint4 clamp(uint4 v, uint4 a, uint4 b) +{ + return make_uint4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w)); +} + +//////////////////////////////////////////////////////////////////////////////// +// dot product +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float dot(float2 a, float2 b) +{ + return a.x * b.x + a.y * b.y; +} +inline __host__ __device__ float dot(float3 a, float3 b) +{ + return a.x * b.x + a.y * b.y + a.z * b.z; +} +inline __host__ __device__ float dot(float4 a, float4 b) +{ + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; +} + +inline __host__ __device__ int dot(int2 a, int2 b) +{ + return a.x * b.x + a.y * b.y; +} +inline __host__ __device__ int dot(int3 a, int3 b) +{ + return a.x * b.x + a.y * b.y + a.z * b.z; +} +inline __host__ __device__ int dot(int4 a, int4 b) +{ + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; +} + +inline __host__ __device__ uint dot(uint2 a, uint2 b) +{ + return a.x * b.x + a.y * b.y; +} +inline __host__ __device__ uint dot(uint3 a, uint3 b) +{ + return a.x * b.x + a.y * b.y + a.z * b.z; +} +inline __host__ __device__ uint dot(uint4 a, uint4 b) +{ + return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; +} + +//////////////////////////////////////////////////////////////////////////////// +// length +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float length(float2 v) +{ + return sqrtf(dot(v, v)); +} +inline __host__ __device__ float length(float3 v) +{ + return sqrtf(dot(v, v)); +} +inline __host__ __device__ float length(float4 v) +{ + return sqrtf(dot(v, v)); +} + +//////////////////////////////////////////////////////////////////////////////// +// normalize +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float2 normalize(float2 v) +{ + float invLen = rsqrtf(dot(v, v)); + return v * invLen; +} +inline __host__ __device__ float3 normalize(float3 v) +{ + float invLen = rsqrtf(dot(v, v)); + return v * invLen; +} +inline __host__ __device__ float4 normalize(float4 v) +{ + float invLen = rsqrtf(dot(v, v)); + return v * invLen; +} + +//////////////////////////////////////////////////////////////////////////////// +// floor +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float2 floorf(float2 v) +{ + return make_float2(floorf(v.x), floorf(v.y)); +} +inline __host__ __device__ float3 floorf(float3 v) +{ + return make_float3(floorf(v.x), floorf(v.y), floorf(v.z)); +} +inline __host__ __device__ float4 floorf(float4 v) +{ + return make_float4(floorf(v.x), floorf(v.y), floorf(v.z), floorf(v.w)); +} + +//////////////////////////////////////////////////////////////////////////////// +// frac - returns the fractional portion of a scalar or each vector component +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float fracf(float v) +{ + return v - floorf(v); +} +inline __host__ __device__ float2 fracf(float2 v) +{ + return make_float2(fracf(v.x), fracf(v.y)); +} +inline __host__ __device__ float3 fracf(float3 v) +{ + return make_float3(fracf(v.x), fracf(v.y), fracf(v.z)); +} +inline __host__ __device__ float4 fracf(float4 v) +{ + return make_float4(fracf(v.x), fracf(v.y), fracf(v.z), fracf(v.w)); +} + +//////////////////////////////////////////////////////////////////////////////// +// fmod +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float2 fmodf(float2 a, float2 b) +{ + return make_float2(fmodf(a.x, b.x), fmodf(a.y, b.y)); +} +inline __host__ __device__ float3 fmodf(float3 a, float3 b) +{ + return make_float3(fmodf(a.x, b.x), fmodf(a.y, b.y), fmodf(a.z, b.z)); +} +inline __host__ __device__ float4 fmodf(float4 a, float4 b) +{ + return make_float4(fmodf(a.x, b.x), fmodf(a.y, b.y), fmodf(a.z, b.z), fmodf(a.w, b.w)); +} + +//////////////////////////////////////////////////////////////////////////////// +// absolute value +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float2 fabs(float2 v) +{ + return make_float2(fabs(v.x), fabs(v.y)); +} +inline __host__ __device__ float3 fabs(float3 v) +{ + return make_float3(fabs(v.x), fabs(v.y), fabs(v.z)); +} +inline __host__ __device__ float4 fabs(float4 v) +{ + return make_float4(fabs(v.x), fabs(v.y), fabs(v.z), fabs(v.w)); +} + +inline __host__ __device__ int2 abs(int2 v) +{ + return make_int2(abs(v.x), abs(v.y)); +} +inline __host__ __device__ int3 abs(int3 v) +{ + return make_int3(abs(v.x), abs(v.y), abs(v.z)); +} +inline __host__ __device__ int4 abs(int4 v) +{ + return make_int4(abs(v.x), abs(v.y), abs(v.z), abs(v.w)); +} + +//////////////////////////////////////////////////////////////////////////////// +// reflect +// - returns reflection of incident ray I around surface normal N +// - N should be normalized, reflected vector's length is equal to length of I +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float3 reflect(float3 i, float3 n) +{ + return i - 2.0f * n * dot(n,i); +} + +//////////////////////////////////////////////////////////////////////////////// +// cross product +//////////////////////////////////////////////////////////////////////////////// + +inline __host__ __device__ float3 cross(float3 a, float3 b) +{ + return make_float3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x); +} + +//////////////////////////////////////////////////////////////////////////////// +// smoothstep +// - returns 0 if x < a +// - returns 1 if x > b +// - otherwise returns smooth interpolation between 0 and 1 based on x +//////////////////////////////////////////////////////////////////////////////// + +inline __device__ __host__ float smoothstep(float a, float b, float x) +{ + float y = clamp((x - a) / (b - a), 0.0f, 1.0f); + return (y*y*(3.0f - (2.0f*y))); +} +inline __device__ __host__ float2 smoothstep(float2 a, float2 b, float2 x) +{ + float2 y = clamp((x - a) / (b - a), 0.0f, 1.0f); + return (y*y*(make_float2(3.0f) - (make_float2(2.0f)*y))); +} +inline __device__ __host__ float3 smoothstep(float3 a, float3 b, float3 x) +{ + float3 y = clamp((x - a) / (b - a), 0.0f, 1.0f); + return (y*y*(make_float3(3.0f) - (make_float3(2.0f)*y))); +} +inline __device__ __host__ float4 smoothstep(float4 a, float4 b, float4 x) +{ + float4 y = clamp((x - a) / (b - a), 0.0f, 1.0f); + return (y*y*(make_float4(3.0f) - (make_float4(2.0f)*y))); +} + +#endif diff --git a/src/cuda/common/sdk-compat/inc/error_checker.h b/src/cuda/common/sdk-compat/inc/error_checker.h new file mode 100644 index 000000000..9f6618760 --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/error_checker.h @@ -0,0 +1,61 @@ +/* + * Copyright 1993-2012 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + +/* CUda UTility Library */ + +#ifndef _ERRORCHECKER_H_ +#define _ERRORCHECKER_H_ + +// includes, system +#include +#include + +// includes, project +#include + +// typedefs +//typedef unsigned int GLuint; + +//! Class providing the handler / tester functions for errors as static members +class ErrorChecker +{ +public: + //! Check if a condition is true. + //! @note In prinicple has the same functionality as assert but allows + //! much better control this version prints an error and terminates + //! the program, no exception is thrown. + inline static void condition( bool val, const char* file, const int line); +}; + +// functions, inlined + +// includes, system +#include + +//////////////////////////////////////////////////////////////////////////////// +//! Check if a condition is true. +//! @note In prinicple has the same functionality as assert but allows much +//! better control this version prints an error and terminates the +//! program, no exception is thrown. +//////////////////////////////////////////////////////////////////////////////// +/* static */ inline void +ErrorChecker::condition( bool val, const char* file, const int line) +{ + if ( ! val) + { + std::ostringstream os; + os << "Condition failed: " << file << " in line " << line; + RUNTIME_EXCEPTION( os.str() ); + } +} + +#endif // _ERRORCHECKER_H_ + diff --git a/src/cuda/common/sdk-compat/inc/exception.h b/src/cuda/common/sdk-compat/inc/exception.h new file mode 100644 index 000000000..9aec73270 --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/exception.h @@ -0,0 +1,151 @@ +/* +* Copyright 1993-2012 NVIDIA Corporation. All rights reserved. +* +* Please refer to the NVIDIA end user license agreement (EULA) associated +* with this source code for terms and conditions that govern your use of +* this software. Any use, reproduction, disclosure, or distribution of +* this software and related documentation outside the terms of the EULA +* is strictly prohibited. +* +*/ + +/* CUda UTility Library */ +#ifndef _EXCEPTION_H_ +#define _EXCEPTION_H_ + +// includes, system +#include +#include +#include +#include + +//! Exception wrapper. +//! @param Std_Exception Exception out of namespace std for easy typing. +template +class Exception : public Std_Exception +{ +public: + + //! @brief Static construction interface + //! @return Alwayss throws ( Located_Exception) + //! @param file file in which the Exception occurs + //! @param line line in which the Exception occurs + //! @param detailed details on the code fragment causing the Exception + static void throw_it( const char* file, + const int line, + const char* detailed = "-" ); + + //! Static construction interface + //! @return Alwayss throws ( Located_Exception) + //! @param file file in which the Exception occurs + //! @param line line in which the Exception occurs + //! @param detailed details on the code fragment causing the Exception + static void throw_it( const char* file, + const int line, + const std::string& detailed); + + //! Destructor + virtual ~Exception() throw(); + +private: + + //! Constructor, default (private) + Exception(); + + //! Constructor, standard + //! @param str string returned by what() + Exception( const std::string& str); + +}; + +//////////////////////////////////////////////////////////////////////////////// +//! Exception handler function for arbitrary exceptions +//! @param ex exception to handle +//////////////////////////////////////////////////////////////////////////////// +template +inline void +handleException( const Exception_Typ& ex) +{ + std::cerr << ex.what() << std::endl; + + exit( EXIT_FAILURE); +} + +//! Convenience macros + +//! Exception caused by dynamic program behavior, e.g. file does not exist +#define RUNTIME_EXCEPTION( msg) \ + Exception::throw_it( __FILE__, __LINE__, msg) + +//! Logic exception in program, e.g. an assert failed +#define LOGIC_EXCEPTION( msg) \ + Exception::throw_it( __FILE__, __LINE__, msg) + +//! Out of range exception +#define RANGE_EXCEPTION( msg) \ + Exception::throw_it( __FILE__, __LINE__, msg) + +//////////////////////////////////////////////////////////////////////////////// +//! Implementation + +// includes, system +#include + +//////////////////////////////////////////////////////////////////////////////// +//! Static construction interface. +//! @param Exception causing code fragment (file and line) and detailed infos. +//////////////////////////////////////////////////////////////////////////////// +/*static*/ template +void +Exception:: +throw_it( const char* file, const int line, const char* detailed) +{ + std::stringstream s; + + // Quiet heavy-weight but exceptions are not for + // performance / release versions + s << "Exception in file '" << file << "' in line " << line << "\n" + << "Detailed description: " << detailed << "\n"; + + throw Exception( s.str()); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Static construction interface. +//! @param Exception causing code fragment (file and line) and detailed infos. +//////////////////////////////////////////////////////////////////////////////// +/*static*/ template +void +Exception:: +throw_it( const char* file, const int line, const std::string& msg) +{ + throw_it( file, line, msg.c_str()); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Constructor, default (private). +//////////////////////////////////////////////////////////////////////////////// +template +Exception::Exception() : + Exception("Unknown Exception.\n") +{ } + +//////////////////////////////////////////////////////////////////////////////// +//! Constructor, standard (private). +//! String returned by what(). +//////////////////////////////////////////////////////////////////////////////// +template +Exception::Exception( const std::string& s) : + Std_Exception( s) +{ } + +//////////////////////////////////////////////////////////////////////////////// +//! Destructor +//////////////////////////////////////////////////////////////////////////////// +template +Exception::~Exception() throw() { } + +// functions, exported + +#endif // #ifndef _EXCEPTION_H_ + diff --git a/src/cuda/common/sdk-compat/inc/helper_cuda.h b/src/cuda/common/sdk-compat/inc/helper_cuda.h new file mode 100644 index 000000000..059d9597a --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/helper_cuda.h @@ -0,0 +1,493 @@ +///////////////////////////////////////////////////////////////////////////// +// +// Copyright 1993-2012 NVIDIA Corporation. All rights reserved. +// +// Please refer to the NVIDIA end user license agreement (EULA) associated +// with this source code for terms and conditions that govern your use of +// this software. Any use, reproduction, disclosure, or distribution of +// this software and related documentation outside the terms of the EULA +// is strictly prohibited. +// +///////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +// These are CUDA Helper functions for initialization and error checking + +#ifndef HELPER_CUDA_H +#define HELPER_CUDA_H + +#pragma once + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +// CUDA Runtime error messages +static const char* _cudaGetErrorEnum(cudaError_t error) +{ + switch (error) + { + case cudaSuccess: return "cudaSuccess"; + case cudaErrorMissingConfiguration: return "cudaErrorMissingConfiguration"; + case cudaErrorMemoryAllocation: return "cudaErrorMemoryAllocation"; + case cudaErrorInitializationError: return "cudaErrorInitializationError"; + case cudaErrorLaunchFailure: return "cudaErrorLaunchFailure"; + case cudaErrorPriorLaunchFailure: return "cudaErrorPriorLaunchFailure"; + case cudaErrorLaunchTimeout: return "cudaErrorLaunchTimeout"; + case cudaErrorLaunchOutOfResources: return "cudaErrorLaunchOutOfResources"; + case cudaErrorInvalidDeviceFunction: return "cudaErrorInvalidDeviceFunction"; + case cudaErrorInvalidConfiguration: return "cudaErrorInvalidConfiguration"; + case cudaErrorInvalidDevice: return "cudaErrorInvalidDevice"; + case cudaErrorInvalidValue: return "cudaErrorInvalidValue"; + case cudaErrorInvalidPitchValue: return "cudaErrorInvalidPitchValue"; + case cudaErrorInvalidSymbol: return "cudaErrorInvalidSymbol"; + case cudaErrorMapBufferObjectFailed: return "cudaErrorMapBufferObjectFailed"; + case cudaErrorUnmapBufferObjectFailed: return "cudaErrorUnmapBufferObjectFailed"; + case cudaErrorInvalidHostPointer: return "cudaErrorInvalidHostPointer"; + case cudaErrorInvalidDevicePointer: return "cudaErrorInvalidDevicePointer"; + case cudaErrorInvalidTexture: return "cudaErrorInvalidTexture"; + case cudaErrorInvalidTextureBinding: return "cudaErrorInvalidTextureBinding"; + case cudaErrorInvalidChannelDescriptor: return "cudaErrorInvalidChannelDescriptor"; + case cudaErrorInvalidMemcpyDirection: return "cudaErrorInvalidMemcpyDirection"; + case cudaErrorAddressOfConstant: return "cudaErrorAddressOfConstant"; + case cudaErrorTextureFetchFailed: return "cudaErrorTextureFetchFailed"; + case cudaErrorTextureNotBound: return "cudaErrorTextureNotBound"; + case cudaErrorSynchronizationError: return "cudaErrorSynchronizationError"; + case cudaErrorInvalidFilterSetting: return "cudaErrorInvalidFilterSetting"; + case cudaErrorInvalidNormSetting: return "cudaErrorInvalidNormSetting"; + case cudaErrorMixedDeviceExecution: return "cudaErrorMixedDeviceExecution"; + case cudaErrorCudartUnloading: return "cudaErrorCudartUnloading"; + case cudaErrorUnknown: return "cudaErrorUnknown"; + case cudaErrorNotYetImplemented: return "cudaErrorNotYetImplemented"; + case cudaErrorMemoryValueTooLarge: return "cudaErrorMemoryValueTooLarge"; + case cudaErrorInvalidResourceHandle: return "cudaErrorInvalidResourceHandle"; + case cudaErrorNotReady: return "cudaErrorNotReady"; + case cudaErrorInsufficientDriver: return "cudaErrorInsufficientDriver"; + case cudaErrorSetOnActiveProcess: return "cudaErrorSetOnActiveProcess"; + case cudaErrorInvalidSurface: return "cudaErrorInvalidSurface"; + case cudaErrorNoDevice: return "cudaErrorNoDevice"; + case cudaErrorECCUncorrectable: return "cudaErrorECCUncorrectable"; + case cudaErrorSharedObjectSymbolNotFound: return "cudaErrorSharedObjectSymbolNotFound"; + case cudaErrorSharedObjectInitFailed: return "cudaErrorSharedObjectInitFailed"; + case cudaErrorUnsupportedLimit: return "cudaErrorUnsupportedLimit"; + case cudaErrorDuplicateVariableName: return "cudaErrorDuplicateVariableName"; + case cudaErrorDuplicateTextureName: return "cudaErrorDuplicateTextureName"; + case cudaErrorDuplicateSurfaceName: return "cudaErrorDuplicateSurfaceName"; + case cudaErrorDevicesUnavailable: return "cudaErrorDevicesUnavailable"; + case cudaErrorInvalidKernelImage: return "cudaErrorInvalidKernelImage"; + case cudaErrorNoKernelImageForDevice: return "cudaErrorNoKernelImageForDevice"; + case cudaErrorIncompatibleDriverContext: return "cudaErrorIncompatibleDriverContext"; + case cudaErrorPeerAccessAlreadyEnabled: return "cudaErrorPeerAccessAlreadyEnabled"; + case cudaErrorPeerAccessNotEnabled: return "cudaErrorPeerAccessNotEnabled"; + case cudaErrorDeviceAlreadyInUse: return "cudaErrorDeviceAlreadyInUse"; + case cudaErrorProfilerDisabled: return "cudaErrorProfilerDisabled"; + case cudaErrorProfilerNotInitialized: return "cudaErrorProfilerNotInitialized"; + case cudaErrorProfilerAlreadyStarted: return "cudaErrorProfilerAlreadyStarted"; + case cudaErrorProfilerAlreadyStopped: return "cudaErrorProfilerAlreadyStopped"; + case cudaErrorAssert: return "cudaErrorAssert"; + case cudaErrorTooManyPeers: return "cudaErrorTooManyPeers"; + case cudaErrorHostMemoryAlreadyRegistered: return "cudaErrorHostMemoryAlreadyRegistered"; + case cudaErrorHostMemoryNotRegistered: return "cudaErrorHostMemoryNotRegistered"; + case cudaErrorStartupFailure: return "cudaErrorStartupFailure"; + case cudaErrorApiFailureBase: return "cudaErrorApiFailureBase"; + } + return ""; +} + +// CUDA Driver API errors +static const char* _cudaGetErrorEnum(CUresult error) +{ + switch (error) + { + case CUDA_SUCCESS: return "CUDA_SUCCESS"; + case CUDA_ERROR_INVALID_VALUE: return "CUDA_ERROR_INVALID_VALUE"; + case CUDA_ERROR_OUT_OF_MEMORY: return "CUDA_ERROR_OUT_OF_MEMORY"; + case CUDA_ERROR_NOT_INITIALIZED: return "CUDA_ERROR_NOT_INITIALIZED"; + case CUDA_ERROR_DEINITIALIZED: return "CUDA_ERROR_DEINITIALIZED"; + case CUDA_ERROR_PROFILER_DISABLED: return "CUDA_ERROR_PROFILER_DISABLED"; + case CUDA_ERROR_PROFILER_NOT_INITIALIZED: return "CUDA_ERROR_PROFILER_NOT_INITIALIZED"; + case CUDA_ERROR_PROFILER_ALREADY_STARTED: return "CUDA_ERROR_PROFILER_ALREADY_STARTED"; + case CUDA_ERROR_PROFILER_ALREADY_STOPPED: return "CUDA_ERROR_PROFILER_ALREADY_STOPPED"; + case CUDA_ERROR_NO_DEVICE: return "CUDA_ERROR_NO_DEVICE"; + case CUDA_ERROR_INVALID_DEVICE: return "CUDA_ERROR_INVALID_DEVICE"; + case CUDA_ERROR_INVALID_IMAGE: return "CUDA_ERROR_INVALID_IMAGE"; + case CUDA_ERROR_INVALID_CONTEXT: return "CUDA_ERROR_INVALID_CONTEXT"; + case CUDA_ERROR_CONTEXT_ALREADY_CURRENT: return "CUDA_ERROR_CONTEXT_ALREADY_CURRENT"; + case CUDA_ERROR_MAP_FAILED: return "CUDA_ERROR_MAP_FAILED"; + case CUDA_ERROR_UNMAP_FAILED: return "CUDA_ERROR_UNMAP_FAILED"; + case CUDA_ERROR_ARRAY_IS_MAPPED: return "CUDA_ERROR_ARRAY_IS_MAPPED"; + case CUDA_ERROR_ALREADY_MAPPED: return "CUDA_ERROR_ALREADY_MAPPED"; + case CUDA_ERROR_NO_BINARY_FOR_GPU: return "CUDA_ERROR_NO_BINARY_FOR_GPU"; + case CUDA_ERROR_ALREADY_ACQUIRED: return "CUDA_ERROR_ALREADY_ACQUIRED"; + case CUDA_ERROR_NOT_MAPPED: return "CUDA_ERROR_NOT_MAPPED"; + case CUDA_ERROR_NOT_MAPPED_AS_ARRAY: return "CUDA_ERROR_NOT_MAPPED_AS_ARRAY"; + case CUDA_ERROR_NOT_MAPPED_AS_POINTER: return "CUDA_ERROR_NOT_MAPPED_AS_POINTER"; + case CUDA_ERROR_ECC_UNCORRECTABLE: return "CUDA_ERROR_ECC_UNCORRECTABLE"; + case CUDA_ERROR_UNSUPPORTED_LIMIT: return "CUDA_ERROR_UNSUPPORTED_LIMIT"; + case CUDA_ERROR_CONTEXT_ALREADY_IN_USE: return "CUDA_ERROR_CONTEXT_ALREADY_IN_USE"; + case CUDA_ERROR_INVALID_SOURCE: return "CUDA_ERROR_INVALID_SOURCE"; + case CUDA_ERROR_FILE_NOT_FOUND: return "CUDA_ERROR_FILE_NOT_FOUND"; + case CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND: return "CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND"; + case CUDA_ERROR_SHARED_OBJECT_INIT_FAILED: return "CUDA_ERROR_SHARED_OBJECT_INIT_FAILED"; + case CUDA_ERROR_OPERATING_SYSTEM: return "CUDA_ERROR_OPERATING_SYSTEM"; + case CUDA_ERROR_INVALID_HANDLE: return "CUDA_ERROR_INVALID_HANDLE"; + case CUDA_ERROR_NOT_FOUND: return "CUDA_ERROR_NOT_FOUND"; + case CUDA_ERROR_NOT_READY: return "CUDA_ERROR_NOT_READY"; + case CUDA_ERROR_LAUNCH_FAILED: return "CUDA_ERROR_LAUNCH_FAILED"; + case CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES: return "CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES"; + case CUDA_ERROR_LAUNCH_TIMEOUT: return "CUDA_ERROR_LAUNCH_TIMEOUT"; + case CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING: return "CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING"; + case CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED: return "CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED"; + case CUDA_ERROR_PEER_ACCESS_NOT_ENABLED: return "CUDA_ERROR_PEER_ACCESS_NOT_ENABLED"; + case CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE: return "CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE"; + case CUDA_ERROR_CONTEXT_IS_DESTROYED: return "CUDA_ERROR_CONTEXT_IS_DESTROYED"; + case CUDA_ERROR_ASSERT: return "CUDA_ERROR_ASSERT"; + case CUDA_ERROR_TOO_MANY_PEERS: return "CUDA_ERROR_TOO_MANY_PEERS"; + case CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED: return "CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED"; + case CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED: return "CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED"; + case CUDA_ERROR_UNKNOWN: return "CUDA_ERROR_UNKNOWN"; + } + return ""; +} + +// cuBLAS API errors +static const char* _cudaGetErrorEnum(cublasStatus_t error) +{ + switch (error) + { + case CUBLAS_STATUS_SUCCESS: return "CUBLAS_STATUS_SUCCESS"; + case CUBLAS_STATUS_NOT_INITIALIZED: return "CUBLAS_STATUS_NOT_INITIALIZED"; + case CUBLAS_STATUS_ALLOC_FAILED: return "CUBLAS_STATUS_ALLOC_FAILED"; + case CUBLAS_STATUS_INVALID_VALUE: return "CUBLAS_STATUS_INVALID_VALUE"; + case CUBLAS_STATUS_ARCH_MISMATCH: return "CUBLAS_STATUS_ARCH_MISMATCH"; + case CUBLAS_STATUS_MAPPING_ERROR: return "CUBLAS_STATUS_MAPPING_ERROR"; + case CUBLAS_STATUS_EXECUTION_FAILED: return "CUBLAS_STATUS_EXECUTION_FAILED"; + case CUBLAS_STATUS_INTERNAL_ERROR: return "CUBLAS_STATUS_INTERNAL_ERROR"; + } + return ""; +} + +// cuFFT API errors +static const char* _cudaGetErrorEnum(cufftResult error) +{ + switch (error) + { + case CUFFT_SUCCESS: return "CUFFT_SUCCESS"; + case CUFFT_INVALID_PLAN: return "CUFFT_INVALID_PLAN"; + case CUFFT_ALLOC_FAILED: return "CUFFT_ALLOC_FAILED"; + case CUFFT_INVALID_TYPE: return "CUFFT_INVALID_TYPE"; + case CUFFT_INVALID_VALUE: return "CUFFT_INVALID_VALUE"; + case CUFFT_INTERNAL_ERROR: return "CUFFT_INTERNAL_ERROR"; + case CUFFT_EXEC_FAILED: return "CUFFT_EXEC_FAILED"; + case CUFFT_SETUP_FAILED: return "CUFFT_SETUP_FAILED"; + case CUFFT_INVALID_SIZE: return "CUFFT_INVALID_SIZE"; + case CUFFT_UNALIGNED_DATA: return "CUFFT_UNALIGNED_DATA"; + } + return ""; +} + +// cuSPARSE API errors +static const char* _cudaGetErrorEnum(cusparseStatus_t error) +{ + switch (error) + { + case CUSPARSE_STATUS_SUCCESS: return "CUSPARSE_STATUS_SUCCESS"; + case CUSPARSE_STATUS_NOT_INITIALIZED: return "CUSPARSE_STATUS_NOT_INITIALIZED"; + case CUSPARSE_STATUS_ALLOC_FAILED: return "CUSPARSE_STATUS_ALLOC_FAILED"; + case CUSPARSE_STATUS_INVALID_VALUE: return "CUSPARSE_STATUS_INVALID_VALUE"; + case CUSPARSE_STATUS_ARCH_MISMATCH: return "CUSPARSE_STATUS_ARCH_MISMATCH"; + case CUSPARSE_STATUS_MAPPING_ERROR: return "CUSPARSE_STATUS_MAPPING_ERROR"; + case CUSPARSE_STATUS_EXECUTION_FAILED: return "CUSPARSE_STATUS_EXECUTION_FAILED"; + case CUSPARSE_STATUS_INTERNAL_ERROR: return "CUSPARSE_STATUS_INTERNAL_ERROR"; + case CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED:return "CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED"; + } + return ""; +} + +// cuRAND API errors +static const char* _cudaGetErrorEnum(curandStatus_t error) +{ + switch (error) + { + case CURAND_STATUS_SUCCESS: return "CURAND_STATUS_SUCCESS"; + case CURAND_STATUS_VERSION_MISMATCH: return "CURAND_STATUS_VERSION_MISMATCH"; + case CURAND_STATUS_NOT_INITIALIZED: return "CURAND_STATUS_NOT_INITIALIZED"; + case CURAND_STATUS_ALLOCATION_FAILED: return "CURAND_STATUS_ALLOCATION_FAILED"; + case CURAND_STATUS_TYPE_ERROR: return "CURAND_STATUS_TYPE_ERROR"; + case CURAND_STATUS_OUT_OF_RANGE: return "CURAND_STATUS_OUT_OF_RANGE"; + case CURAND_STATUS_LENGTH_NOT_MULTIPLE: return "CURAND_STATUS_LENGTH_NOT_MULTIPLE"; + case CURAND_STATUS_DOUBLE_PRECISION_REQUIRED: return "CURAND_STATUS_DOUBLE_PRECISION_REQUIRED"; + case CURAND_STATUS_LAUNCH_FAILURE: return "CURAND_STATUS_LAUNCH_FAILURE"; + case CURAND_STATUS_PREEXISTING_FAILURE: return "CURAND_STATUS_PREEXISTING_FAILURE"; + case CURAND_STATUS_INITIALIZATION_FAILED: return "CURAND_STATUS_INITIALIZATION_FAILED"; + case CURAND_STATUS_ARCH_MISMATCH: return "CURAND_STATUS_ARCH_MISMATCH"; + case CURAND_STATUS_INTERNAL_ERROR: return "CURAND_STATUS_INTERNAL_ERROR"; + } + return ""; +} + +// The NPP error-string overload that shipped here has been dropped: modern NPP +// renamed several of its status enumerators (NPP_BAD_ARG_ERROR and friends), and +// nothing in this tree asks for NPP error strings. + +template< typename T > +void check(T result, char const * const func, const char * const file, int const line) +{ + if (result) + { + std::stringstream ss; + std::string msg("CUDA error at "); + msg += file; + msg += ":"; + ss << line; + msg += ss.str(); + msg += " code="; + ss << static_cast(result); + msg += ss.str(); + msg += " ("; + msg += _cudaGetErrorEnum(result); + msg += ") \""; + msg += func; + msg += "\""; + //throw msg; + std::cerr << msg; + } +} + + // This will output the proper CUDA error strings in the event that a CUDA host call returns an error + #define checkCudaErrors(val) check ( (val), #val, __FILE__, __LINE__ ) + + inline void __checkCudaErrors( cudaError err, const char *file, const int line ) + { + if( cudaSuccess != err) { + fprintf(stderr, "%s(%i) : CUDA Runtime API error %d: %s.\n", + file, line, (int)err, cudaGetErrorString( err ) ); + exit(-1); + } + } + + // This will output the proper error string when calling cudaGetLastError + #define getLastCudaError(msg) __getLastCudaError (msg, __FILE__, __LINE__) + + inline void __getLastCudaError( const char *errorMessage, const char *file, const int line ) + { + cudaError_t err = cudaGetLastError(); + if( cudaSuccess != err) { + fprintf(stderr, "%s(%i) : getLastCudaError() CUDA error : %s : (%d) %s.\n", + file, line, errorMessage, (int)err, cudaGetErrorString( err ) ); + exit(-1); + } + } + +#ifndef MAX +#define MAX(a,b) (a > b ? a : b) +#endif + + // Beginning of GPU Architecture definitions + inline int _ConvertSMVer2Cores(int major, int minor) + { + // Defines for GPU Architecture types (using the SM version to determine the # of cores per SM + typedef struct { + int SM; // 0xMm (hexidecimal notation), M = SM Major version, and m = SM minor version + int Cores; + } sSMtoCores; + + sSMtoCores nGpuArchCoresPerSM[] = + { { 0x10, 8 }, // Tesla Generation (SM 1.0) G80 class + { 0x11, 8 }, // Tesla Generation (SM 1.1) G8x class + { 0x12, 8 }, // Tesla Generation (SM 1.2) G9x class + { 0x13, 8 }, // Tesla Generation (SM 1.3) GT200 class + { 0x20, 32 }, // Fermi Generation (SM 2.0) GF100 class + { 0x21, 48 }, // Fermi Generation (SM 2.1) GF10x class + { 0x30, 192}, // Fermi Generation (SM 3.0) GK10x class + { 0x32, 192}, // Kepler Generation (SM 3.2) GK10x class + { 0x35, 192}, // Kepler Generation (SM 3.5) GK11x class + { 0x37, 192}, // Kepler Generation (SM 3.7) GK21x class + { 0x50, 128}, // Maxwell Generation (SM 5.0) GM10x class + { 0x52, 128}, // Maxwell Generation (SM 5.2) GM20x class + { 0x53, 128}, // Maxwell Generation (SM 5.3) GM20x class + { 0x60, 64 }, // Pascal Generation (SM 6.0) GP100 class + { 0x61, 128}, // Pascal Generation (SM 6.1) GP10x class + { 0x62, 128}, // Pascal Generation (SM 6.2) GP10x class + { 0x70, 64 }, // Volta Generation (SM 7.0) GV100 class + { 0x72, 64 }, // Volta Generation (SM 7.2) GV10B class + { 0x75, 64 }, // Turing Generation (SM 7.5) TU10x class + { 0x80, 64 }, // Ampere Generation (SM 8.0) GA100 class + { 0x86, 128}, // Ampere Generation (SM 8.6) GA10x class + { 0x87, 128}, // Ampere Generation (SM 8.7) GA10B class + { 0x89, 128}, // Ada Generation (SM 8.9) AD10x class + { 0x90, 128}, // Hopper Generation (SM 9.0) GH100 class + { 0xa0, 128}, // Blackwell Generation (SM 10.0) GB100 class + { 0xa1, 128}, // Blackwell Generation (SM 10.1) GB10x class + { 0xa3, 128}, // Blackwell Generation (SM 10.3) GB30x class + { 0xb0, 128}, // Blackwell Generation (SM 11.0) class + { 0xc0, 128}, // Blackwell Generation (SM 12.0) GB20x class + { 0xc1, 128}, // Blackwell Generation (SM 12.1) class + { -1, -1 } + }; + + int index = 0; + while (nGpuArchCoresPerSM[index].SM != -1) { + if (nGpuArchCoresPerSM[index].SM == ((major << 4) + minor) ) { + return nGpuArchCoresPerSM[index].Cores; + } + index++; + } + printf("MapSMtoCores undefined SM %d.%d is undefined (please update to the latest SDK)!\n", major, minor); + return -1; + } + // end of GPU Architecture definitions + + // General GPU Device CUDA Initialization + inline int gpuDeviceInit(int devID) + { + int deviceCount; + checkCudaErrors(cudaGetDeviceCount(&deviceCount)); + + if (deviceCount == 0) + { + fprintf(stderr, "gpuDeviceInit() CUDA error: no devices supporting CUDA.\n"); + exit(-1); + } + + if (devID < 0) + devID = 0; + + if (devID > deviceCount-1) + { + fprintf(stderr, "\n"); + fprintf(stderr, ">> %d CUDA capable GPU device(s) detected. <<\n", deviceCount); + fprintf(stderr, ">> gpuDeviceInit (-device=%d) is not a valid GPU device. <<\n", devID); + fprintf(stderr, "\n"); + return -devID; + } + + cudaDeviceProp deviceProp; + checkCudaErrors( cudaGetDeviceProperties(&deviceProp, devID) ); + + if (deviceProp.major < 1) + { + fprintf(stderr, "gpuDeviceInit(): GPU device does not support CUDA.\n"); + exit(-1); + } + + checkCudaErrors( cudaSetDevice(devID) ); + printf("gpuDeviceInit() CUDA Device [%d]: \"%s\n", devID, deviceProp.name); + + return devID; + } + + // This function returns the best GPU (with maximum GFLOPS) + inline int gpuGetMaxGflopsDeviceId() + { + int current_device = 0, sm_per_multiproc = 0; + int max_compute_perf = 0, max_perf_device = 0; + int device_count = 0, best_SM_arch = 0; + cudaDeviceProp deviceProp; + cudaGetDeviceCount( &device_count ); + + // Find the best major SM Architecture GPU device + while (current_device < device_count) + { + cudaGetDeviceProperties( &deviceProp, current_device ); + if (deviceProp.major > 0 && deviceProp.major < 9999) + { + best_SM_arch = MAX(best_SM_arch, deviceProp.major); + } + current_device++; + } + + // Find the best CUDA capable GPU device + current_device = 0; + while( current_device < device_count ) + { + cudaGetDeviceProperties( &deviceProp, current_device ); + if (deviceProp.major == 9999 && deviceProp.minor == 9999) + { + sm_per_multiproc = 1; + } + else + { + sm_per_multiproc = _ConvertSMVer2Cores(deviceProp.major, deviceProp.minor); + } + + // cudaDeviceProp::clockRate was removed in CUDA 13 + int clockRateKHz = 0; + cudaDeviceGetAttribute(&clockRateKHz, cudaDevAttrClockRate, current_device); + int compute_perf = deviceProp.multiProcessorCount * sm_per_multiproc * clockRateKHz; + + if( compute_perf > max_compute_perf ) + { + // If we find GPU with SM major > 2, search only these + if ( best_SM_arch > 2 ) + { + // If our device==dest_SM_arch, choose this, or else pass + if (deviceProp.major == best_SM_arch) + { + max_compute_perf = compute_perf; + max_perf_device = current_device; + } + } + else + { + max_compute_perf = compute_perf; + max_perf_device = current_device; + } + } + ++current_device; + } + return max_perf_device; + } + + + // Initialization code to find the best CUDA Device + inline int findCudaDevice(int argc, const char **argv) + { + cudaDeviceProp deviceProp; + int devID = 0; + // If the command-line has a device number specified, use it + if (checkCmdLineFlag(argc, argv, "device")) + { + devID = getCmdLineArgumentInt(argc, argv, "device="); + if (devID < 0) + { + printf("Invalid command line parameter\n "); + exit(-1); + } + else + { + devID = gpuDeviceInit(devID); + if (devID < 0) + { + printf("exiting...\n"); + exit(EXIT_FAILURE); + } + } + } + else + { + // Otherwise pick the device with highest Gflops/s + devID = gpuGetMaxGflopsDeviceId(); + checkCudaErrors( cudaSetDevice( devID ) ); + checkCudaErrors( cudaGetDeviceProperties(&deviceProp, devID) ); + printf("GPU Device %d: \"%s\" with compute capability %d.%d\n\n", devID, deviceProp.name, deviceProp.major, deviceProp.minor); + } + return devID; + } +// end of CUDA Helper Functions + +#endif diff --git a/src/cuda/common/sdk-compat/inc/helper_string.h b/src/cuda/common/sdk-compat/inc/helper_string.h new file mode 100644 index 000000000..d43754d8d --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/helper_string.h @@ -0,0 +1,265 @@ +///////////////////////////////////////////////////////////////////////////// +// +// Copyright 1993-2012 NVIDIA Corporation. All rights reserved. +// +// Please refer to the NVIDIA end user license agreement (EULA) associated +// with this source code for terms and conditions that govern your use of +// this software. Any use, reproduction, disclosure, or distribution of +// this software and related documentation outside the terms of the EULA +// is strictly prohibited. +// +///////////////////////////////////////////////////////////////////////////// + +// These are helper functions for the SDK samples (string parsing, timers, etc) +#ifndef STRING_HELPER_H +#define STRING_HELPER_H + +#include +#include +#include +#include + +#ifdef _WIN32 + #ifndef STRCASECMP + #define STRCASECMP _stricmp + #endif + #ifndef STRNCASECMP + #define STRNCASECMP _strnicmp + #endif + #ifndef STRCPY + #define STRCPY(sFilePath, nLength, sPath) strcpy_s(sFilePath, nLength, sPath) + #endif + + #ifndef FOPEN + #define FOPEN(fHandle,filename,mode) fopen_s(&fHandle, filename, mode) + #endif + #ifndef FOPEN_FAIL + #define FOPEN_FAIL(result) (result != 0) + #endif + #ifndef SSCANF + #define SSCANF sscanf_s + #endif + +#else + #include + #include + + #ifndef STRCASECMP + #define STRCASECMP strcasecmp + #endif + #ifndef STRNCASECMP + #define STRNCASECMP strncasecmp + #endif + #ifndef STRCPY + #define STRCPY(sFilePath, nLength, sPath) strcpy(sFilePath, sPath) + #endif + + #ifndef FOPEN + #define FOPEN(fHandle,filename,mode) (fHandle = fopen(filename, mode)) + #endif + #ifndef FOPEN_FAIL + #define FOPEN_FAIL(result) (result == NULL) + #endif + #ifndef SSCANF + #define SSCANF sscanf + #endif +#endif + +// CUDA Utility Helper Functions +inline int stringRemoveDelimiter(char delimiter, const char *string) +{ + int string_start = 0; + while (string[string_start] == delimiter) + string_start++; + + if (string_start >= (int)strlen(string)-1) { + return 0; + } + return string_start; +} + +inline int checkCmdLineFlag(const int argc, const char **argv, const char *string_ref) +{ + bool bFound = false; + if (argc >= 1) { + for (int i=1; i < argc; i++) { + int string_start = stringRemoveDelimiter('-', argv[i]); + const char *string_argv = &argv[i][string_start]; + int length = (int)strlen(string_ref); + if (!STRNCASECMP(string_argv, string_ref, length) ) { + bFound = true; + continue; + } + } + } + return (int)bFound; +} + +inline int getCmdLineArgumentInt(const int argc, const char **argv, const char *string_ref) +{ + bool bFound = false; + int value = -1; + if (argc >= 1) { + for (int i=1; i < argc; i++) { + int string_start = stringRemoveDelimiter('-', argv[i]); + const char *string_argv = &argv[i][string_start]; + int length = (int)strlen(string_ref); + if (!STRNCASECMP(string_argv, string_ref, length) ) { + if (length+1 <= (int)strlen(string_argv)) { + int auto_inc = (string_argv[length] == '=') ? 1 : 0; + value = atoi(&string_argv[length + auto_inc]); + } else { + value = 0; + } + bFound = true; + continue; + } + } + } + if (bFound) { + return value; + } else { + return 0; + } +} + +inline bool getCmdLineArgumentString(const int argc, const char **argv, + const char *string_ref, char **string_retval) +{ + bool bFound = false; + if (argc >= 1) { + for (int i=1; i < argc; i++) { + int string_start = stringRemoveDelimiter('-', argv[i]); + char *string_argv = (char *)&argv[i][string_start]; + int length = (int)strlen(string_ref); + if (!STRNCASECMP(string_argv, string_ref, length) ) { + *string_retval = &string_argv[length+1]; + bFound = true; + continue; + } + } + } + if (!bFound) { + *string_retval = NULL; + } + return bFound; +} + +////////////////////////////////////////////////////////////////////////////// +//! Find the path for a file assuming that +//! files are found in the searchPath. +//! +//! @return the path if succeeded, otherwise 0 +//! @param filename name of the file +//! @param executable_path optional absolute path of the executable +////////////////////////////////////////////////////////////////////////////// +inline char* sdkFindFilePath(const char* filename, const char* executable_path) +{ + // defines a variable that is replaced with the name of the executable + + // Typical relative search paths to locate needed companion files (e.g. sample input data, or JIT source files) + // The origin for the relative search may be the .exe file, a .bat file launching an .exe, a browser .exe launching the .exe or .bat, etc + const char* searchPath[] = + { + "./", // same dir + "./data/", // "/data/" subdir + "./src/", // "/src/" subdir + "./src//data/", // "/src//data/" subdir + "./inc/", // "/inc/" subdir + "../", // up 1 in tree + "../data/", // up 1 in tree, "/data/" subdir + "../src/", // up 1 in tree, "/src/" subdir + "../inc/", // up 1 in tree, "/inc/" subdir + "../OpenCL/src//", // up 1 in tree, "/OpenCL/src//" subdir + "../OpenCL/src//data/", // up 1 in tree, "/OpenCL/src//data/" subdir + "../OpenCL/src//src/", // up 1 in tree, "/OpenCL/src//src/" subdir + "../OpenCL/src//inc/", // up 1 in tree, "/OpenCL/src//inc/" subdir + "../C/src//", // up 1 in tree, "/C/src//" subdir + "../C/src//data/", // up 1 in tree, "/C/src//data/" subdir + "../C/src//src/", // up 1 in tree, "/C/src//src/" subdir + "../C/src//inc/", // up 1 in tree, "/C/src//inc/" subdir + "../DirectCompute/src//", // up 1 in tree, "/DirectCompute/src//" subdir + "../DirectCompute/src//data/", // up 1 in tree, "/DirectCompute/src//data/" subdir + "../DirectCompute/src//src/", // up 1 in tree, "/DirectCompute/src//src/" subdir + "../DirectCompute/src//inc/", // up 1 in tree, "/DirectCompute/src//inc/" subdir + "../../", // up 2 in tree + "../../data/", // up 2 in tree, "/data/" subdir + "../../src/", // up 2 in tree, "/src/" subdir + "../../inc/", // up 2 in tree, "/inc/" subdir + "../../../", // up 3 in tree + "../../../src//", // up 3 in tree, "/src//" subdir + "../../../src//data/", // up 3 in tree, "/src//data/" subdir + "../../../src//src/", // up 3 in tree, "/src//src/" subdir + "../../../src//inc/", // up 3 in tree, "/src//inc/" subdir + "../../../sandbox//", // up 3 in tree, "/sandbox//" subdir + "../../../sandbox//data/", // up 3 in tree, "/sandbox//data/" subdir + "../../../sandbox//src/", // up 3 in tree, "/sandbox//src/" subdir + "../../../sandbox//inc/" // up 3 in tree, "/sandbox//inc/" subdir + }; + + // Extract the executable name + std::string executable_name; + if (executable_path != 0) + { + executable_name = std::string(executable_path); + + #ifdef _WIN32 + // Windows path delimiter + size_t delimiter_pos = executable_name.find_last_of('\\'); + executable_name.erase(0, delimiter_pos + 1); + + if (executable_name.rfind(".exe") != std::string::npos) + { + // we strip .exe, only if the .exe is found + executable_name.resize(executable_name.size() - 4); + } + #else + // Linux & OSX path delimiter + size_t delimiter_pos = executable_name.find_last_of('/'); + executable_name.erase(0,delimiter_pos+1); + #endif + } + + // Loop over all search paths and return the first hit + for( unsigned int i = 0; i < sizeof(searchPath)/sizeof(char*); ++i ) + { + std::string path(searchPath[i]); + size_t executable_name_pos = path.find(""); + + // If there is executable_name variable in the searchPath + // replace it with the value + if(executable_name_pos != std::string::npos) + { + if(executable_path != 0) + { + path.replace(executable_name_pos, strlen(""), executable_name); + + } + else + { + // Skip this path entry if no executable argument is given + continue; + } + } + + // Test if the file exists + path.append(filename); + FILE *fp; + FOPEN(fp, path.c_str(), "rb"); + if (fp != NULL) + { + fclose(fp); + // File found + // returning an allocated array here for backwards compatibility reasons + char* file_path = (char*) malloc(path.length() + 1); + STRCPY(file_path, path.length() + 1, path.c_str()); + return file_path; + } + if (fp) fclose(fp); + } + + // File not found + return 0; +} + +#endif diff --git a/src/cuda/common/sdk-compat/inc/helper_timer.h b/src/cuda/common/sdk-compat/inc/helper_timer.h new file mode 100644 index 000000000..85aff962c --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/helper_timer.h @@ -0,0 +1,460 @@ +///////////////////////////////////////////////////////////////////////////// +// +// Copyright 1993-2012 NVIDIA Corporation. All rights reserved. +// +// Please refer to the NVIDIA end user license agreement (EULA) associated +// with this source code for terms and conditions that govern your use of +// this software. Any use, reproduction, disclosure, or distribution of +// this software and related documentation outside the terms of the EULA +// is strictly prohibited. +// +///////////////////////////////////////////////////////////////////////////// + +// Helper Timer Functions (this is the inlined version) + +#ifndef HELPER_TIMER_H +#define HELPER_TIMER_H + +// includes, system +#include + +// includes, project +#include + +// Definition of the StopWatch Interface, this is used if we don't want to use the CUT functions +// But rather in a self contained class interface +class StopWatchInterface +{ +public: + StopWatchInterface() {}; + virtual ~StopWatchInterface() {}; + +public: + //! Start time measurement + virtual void start() = 0; + + //! Stop time measurement + virtual void stop() = 0; + + //! Reset time counters to zero + virtual void reset() = 0; + + //! Time in msec. after start. If the stop watch is still running (i.e. there + //! was no call to stop()) then the elapsed time is returned, otherwise the + //! time between the last start() and stop call is returned + virtual float getTime() = 0; + + //! Mean time to date based on the number of times the stopwatch has been + //! _stopped_ (ie finished sessions) and the current total time + virtual float getAverageTime() = 0; +}; + + +////////////////////////////////////////////////////////////////// +// Begin Stopwatch timer class definitions for all OS platforms // +////////////////////////////////////////////////////////////////// +#ifdef WIN32 + // includes, system + #define WINDOWS_LEAN_AND_MEAN + #include + #undef min + #undef max + + //! Windows specific implementation of StopWatch + class StopWatchWin : public StopWatchInterface + { + public: + //! Constructor, default + StopWatchWin() : + start_time(), end_time(), + diff_time(0.0f), total_time(0.0f), + running( false ), clock_sessions(0), freq(0), freq_set(false) + { + if( ! freq_set) { + // helper variable + LARGE_INTEGER temp; + + // get the tick frequency from the OS + QueryPerformanceFrequency((LARGE_INTEGER*) &temp); + + // convert to type in which it is needed + freq = ((double) temp.QuadPart) / 1000.0; + + // rememeber query + freq_set = true; + } + }; + + // Destructor + ~StopWatchWin() { }; + + public: + //! Start time measurement + inline void start(); + + //! Stop time measurement + inline void stop(); + + //! Reset time counters to zero + inline void reset(); + + //! Time in msec. after start. If the stop watch is still running (i.e. there + //! was no call to stop()) then the elapsed time is returned, otherwise the + //! time between the last start() and stop call is returned + inline float getTime(); + + //! Mean time to date based on the number of times the stopwatch has been + //! _stopped_ (ie finished sessions) and the current total time + inline float getAverageTime(); + + private: + // member variables + + //! Start of measurement + LARGE_INTEGER start_time; + //! End of measurement + LARGE_INTEGER end_time; + + //! Time difference between the last start and stop + float diff_time; + + //! TOTAL time difference between starts and stops + float total_time; + + //! flag if the stop watch is running + bool running; + + //! Number of times clock has been started + //! and stopped to allow averaging + int clock_sessions; + + //! tick frequency + double freq; + + //! flag if the frequency has been set + bool freq_set; + }; + + // functions, inlined + + //////////////////////////////////////////////////////////////////////////////// + //! Start time measurement + //////////////////////////////////////////////////////////////////////////////// + inline void + StopWatchWin::start() + { + QueryPerformanceCounter((LARGE_INTEGER*) &start_time); + running = true; + } + + //////////////////////////////////////////////////////////////////////////////// + //! Stop time measurement and increment add to the current diff_time summation + //! variable. Also increment the number of times this clock has been run. + //////////////////////////////////////////////////////////////////////////////// + inline void + StopWatchWin::stop() + { + QueryPerformanceCounter((LARGE_INTEGER*) &end_time); + diff_time = (float) + (((double) end_time.QuadPart - (double) start_time.QuadPart) / freq); + + total_time += diff_time; + clock_sessions++; + running = false; + } + + //////////////////////////////////////////////////////////////////////////////// + //! Reset the timer to 0. Does not change the timer running state but does + //! recapture this point in time as the current start time if it is running. + //////////////////////////////////////////////////////////////////////////////// + inline void + StopWatchWin::reset() + { + diff_time = 0; + total_time = 0; + clock_sessions = 0; + if( running ) + QueryPerformanceCounter((LARGE_INTEGER*) &start_time); + } + + + //////////////////////////////////////////////////////////////////////////////// + //! Time in msec. after start. If the stop watch is still running (i.e. there + //! was no call to stop()) then the elapsed time is returned added to the + //! current diff_time sum, otherwise the current summed time difference alone + //! is returned. + //////////////////////////////////////////////////////////////////////////////// + inline float + StopWatchWin::getTime() + { + // Return the TOTAL time to date + float retval = total_time; + if(running) + { + LARGE_INTEGER temp; + QueryPerformanceCounter((LARGE_INTEGER*) &temp); + retval += (float) + (((double) (temp.QuadPart - start_time.QuadPart)) / freq); + } + + return retval; + } + + //////////////////////////////////////////////////////////////////////////////// + //! Time in msec. for a single run based on the total number of COMPLETED runs + //! and the total time. + //////////////////////////////////////////////////////////////////////////////// + inline float + StopWatchWin::getAverageTime() + { + return (clock_sessions > 0) ? (total_time/clock_sessions) : 0.0f; + } +#else + // Declarations for Stopwatch on Linux and Mac OSX + // includes, system + #include + #include + + //! Windows specific implementation of StopWatch + class StopWatchLinux : public StopWatchInterface + { + public: + //! Constructor, default + StopWatchLinux() : + start_time(), diff_time( 0.0), total_time(0.0), + running( false ), clock_sessions(0) + { }; + + // Destructor + virtual ~StopWatchLinux() + { }; + + public: + //! Start time measurement + inline void start(); + + //! Stop time measurement + inline void stop(); + + //! Reset time counters to zero + inline void reset(); + + //! Time in msec. after start. If the stop watch is still running (i.e. there + //! was no call to stop()) then the elapsed time is returned, otherwise the + //! time between the last start() and stop call is returned + inline float getTime(); + + //! Mean time to date based on the number of times the stopwatch has been + //! _stopped_ (ie finished sessions) and the current total time + inline float getAverageTime(); + + private: + + // helper functions + + //! Get difference between start time and current time + inline float getDiffTime(); + + private: + + // member variables + + //! Start of measurement + struct timeval start_time; + + //! Time difference between the last start and stop + float diff_time; + + //! TOTAL time difference between starts and stops + float total_time; + + //! flag if the stop watch is running + bool running; + + //! Number of times clock has been started + //! and stopped to allow averaging + int clock_sessions; + }; + + // functions, inlined + + //////////////////////////////////////////////////////////////////////////////// + //! Start time measurement + //////////////////////////////////////////////////////////////////////////////// + inline void + StopWatchLinux::start() { + gettimeofday( &start_time, 0); + running = true; + } + + //////////////////////////////////////////////////////////////////////////////// + //! Stop time measurement and increment add to the current diff_time summation + //! variable. Also increment the number of times this clock has been run. + //////////////////////////////////////////////////////////////////////////////// + inline void + StopWatchLinux::stop() { + diff_time = getDiffTime(); + total_time += diff_time; + running = false; + clock_sessions++; + } + + //////////////////////////////////////////////////////////////////////////////// + //! Reset the timer to 0. Does not change the timer running state but does + //! recapture this point in time as the current start time if it is running. + //////////////////////////////////////////////////////////////////////////////// + inline void + StopWatchLinux::reset() + { + diff_time = 0; + total_time = 0; + clock_sessions = 0; + if( running ) + gettimeofday( &start_time, 0); + } + + //////////////////////////////////////////////////////////////////////////////// + //! Time in msec. after start. If the stop watch is still running (i.e. there + //! was no call to stop()) then the elapsed time is returned added to the + //! current diff_time sum, otherwise the current summed time difference alone + //! is returned. + //////////////////////////////////////////////////////////////////////////////// + inline float + StopWatchLinux::getTime() + { + // Return the TOTAL time to date + float retval = total_time; + if( running) { + retval += getDiffTime(); + } + + return retval; + } + + //////////////////////////////////////////////////////////////////////////////// + //! Time in msec. for a single run based on the total number of COMPLETED runs + //! and the total time. + //////////////////////////////////////////////////////////////////////////////// + inline float + StopWatchLinux::getAverageTime() + { + return (clock_sessions > 0) ? (total_time/clock_sessions) : 0.0f; + } + //////////////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////////////// + inline float + StopWatchLinux::getDiffTime() + { + struct timeval t_time; + gettimeofday( &t_time, 0); + + // time difference in milli-seconds + return (float) (1000.0 * ( t_time.tv_sec - start_time.tv_sec) + + (0.001 * (t_time.tv_usec - start_time.tv_usec)) ); + } +#endif // _WIN32 + +//////////////////////////////////////////////////////////////////////////////// +//! Timer functionality exported + +//////////////////////////////////////////////////////////////////////////////// +//! Create a new timer +//! @return true if a time has been created, otherwise false +//! @param name of the new timer, 0 if the creation failed +//////////////////////////////////////////////////////////////////////////////// +inline bool +sdkCreateTimer( StopWatchInterface **timer_interface ) +{ + //printf("sdkCreateTimer called object %08x\n", (void *)*timer_interface); +#ifdef _WIN32 + *timer_interface = (StopWatchInterface *)new StopWatchWin(); +#else + *timer_interface = (StopWatchInterface *)new StopWatchLinux(); +#endif + return (*timer_interface != NULL) ? true : false; +} + + +//////////////////////////////////////////////////////////////////////////////// +//! Delete a timer +//! @return true if a time has been deleted, otherwise false +//! @param name of the timer to delete +//////////////////////////////////////////////////////////////////////////////// +inline bool +sdkDeleteTimer( StopWatchInterface **timer_interface ) +{ + //printf("sdkDeleteTimer called object %08x\n", (void *)*timer_interface); + if (*timer_interface) delete *timer_interface; + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Start the time with name \a name +//! @param name name of the timer to start +//////////////////////////////////////////////////////////////////////////////// +inline bool +sdkStartTimer( StopWatchInterface **timer_interface ) +{ + //printf("sdkStartTimer called object %08x\n", (void *)*timer_interface); + if (*timer_interface) (*timer_interface)->start(); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Stop the time with name \a name. Does not reset. +//! @param name name of the timer to stop +//////////////////////////////////////////////////////////////////////////////// +inline bool +sdkStopTimer( StopWatchInterface **timer_interface ) +{ + // printf("sdkStopTimer called object %08x\n", (void *)*timer_interface); + if (*timer_interface) (*timer_interface)->stop(); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Resets the timer's counter. +//! @param name name of the timer to reset. +//////////////////////////////////////////////////////////////////////////////// +inline bool +sdkResetTimer( StopWatchInterface **timer_interface ) +{ + // printf("sdkResetTimer called object %08x\n", (void *)*timer_interface); + if (*timer_interface) (*timer_interface)->reset(); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Return the average time for timer execution as the total time +//! for the timer dividied by the number of completed (stopped) runs the timer +//! has made. +//! Excludes the current running time if the timer is currently running. +//! @param name name of the timer to return the time of +//////////////////////////////////////////////////////////////////////////////// +inline float +sdkGetAverageTimerValue( StopWatchInterface **timer_interface ) +{ +// printf("sdkGetAverageTimerValue called object %08x\n", (void *)*timer_interface); + if (*timer_interface) + return (*timer_interface)->getAverageTime(); + else + return 0.0f; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Total execution time for the timer over all runs since the last reset +//! or timer creation. +//! @param name name of the timer to obtain the value of. +//////////////////////////////////////////////////////////////////////////////// +inline float +sdkGetTimerValue( StopWatchInterface **timer_interface ) +{ + // printf("sdkGetTimerValue called object %08x\n", (void *)*timer_interface); + if (*timer_interface) + return (*timer_interface)->getTime(); + else + return 0.0f; +} + +#endif // HELPER_TIMER_H diff --git a/src/cuda/common/sdk-compat/inc/multithreading.h b/src/cuda/common/sdk-compat/inc/multithreading.h new file mode 100644 index 000000000..f70533bc8 --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/multithreading.h @@ -0,0 +1,60 @@ +/* + * Copyright 1993-2012 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + +#ifndef MULTITHREADING_H +#define MULTITHREADING_H + + +//Simple portable thread library. + +#if _WIN32 + //Windows threads. + #include + + typedef HANDLE CUTThread; + typedef unsigned (WINAPI *CUT_THREADROUTINE)(void *); + + #define CUT_THREADPROC unsigned WINAPI + #define CUT_THREADEND return 0 + +#else + //POSIX threads. + #include + + typedef pthread_t CUTThread; + typedef void *(*CUT_THREADROUTINE)(void *); + + #define CUT_THREADPROC void + #define CUT_THREADEND +#endif + + +#ifdef __cplusplus + extern "C" { +#endif + +//Create thread. +CUTThread cutStartThread(CUT_THREADROUTINE, void *data); + +//Wait for thread to finish. +void cutEndThread(CUTThread thread); + +//Destroy thread. +void cutDestroyThread(CUTThread thread); + +//Wait for multiple threads. +void cutWaitForThreads(const CUTThread *threads, int num); + +#ifdef __cplusplus +} //extern "C" +#endif + +#endif //MULTITHREADING_H diff --git a/src/cuda/common/sdk-compat/inc/shrQATest.h b/src/cuda/common/sdk-compat/inc/shrQATest.h new file mode 100644 index 000000000..9081a566e --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/shrQATest.h @@ -0,0 +1,238 @@ +/* +* Copyright 1993-2010 NVIDIA Corporation. All rights reserved. +* +* Please refer to the NVIDIA end user license agreement (EULA) associated +* with this source code for terms and conditions that govern your use of +* this software. Any use, reproduction, disclosure, or distribution of +* this software and related documentation outside the terms of the EULA +* is strictly prohibited. +* +*/ + +#ifndef SHR_QATEST_H +#define SHR_QATEST_H + +// ********************************************************************* +// Generic utilities for NVIDIA GPU Computing SDK +// ********************************************************************* + +// OS dependent includes +#ifdef _WIN32 + #pragma message ("Note: including windows.h") + #pragma message ("Note: including math.h") + #pragma message ("Note: including assert.h") + #pragma message ("Note: including time.h") + +// Headers needed for Windows + #include + #include +#else + // Headers needed for Linux + #include + #include + #include + #include + #include + #include + #include + #include + #include +#endif + +#ifndef STRCASECMP +#ifdef _WIN32 +#define STRCASECMP _stricmp +#else +#define STRCASECMP strcasecmp +#endif +#endif + +#ifndef STRNCASECMP +#ifdef _WIN32 +#define STRNCASECMP _strnicmp +#else +#define STRNCASECMP strncasecmp +#endif +#endif + + +// Standardized QA Start/Finish for CUDA SDK tests +#define shrQAStart(a, b) __shrQAStart(a, b) +#define shrQAFinish(a, b, c) __shrQAFinish(a, b, c) +#define shrQAFinish2(a, b, c, d) __shrQAFinish2(a, b, c, d) + +inline int findExeNameStart(const char *exec_name) +{ + int exename_start = (int)strlen(exec_name); + + while( (exename_start > 0) && + (exec_name[exename_start] != '\\') && + (exec_name[exename_start] != '/') ) + { + exename_start--; + } + if (exec_name[exename_start] == '\\' || + exec_name[exename_start] == '/') + { + return exename_start+1; + } else { + return exename_start; + } +} + +inline int __shrQAStart(int argc, char **argv) +{ + bool bQATest = false; + // First clear the output buffer + fflush(stdout); + fflush(stdout); + + for (int i=1; i < argc; i++) { + int string_start = 0; + while (argv[i][string_start] == '-') + string_start++; + char *string_argv = &argv[i][string_start]; + + if (!STRCASECMP(string_argv, "qatest")) { + bQATest = true; + } + } + + // We don't want to print the entire path, so we search for the first + int exename_start = findExeNameStart(argv[0]); + if (bQATest) { + fprintf(stdout, "&&&& RUNNING %s", &(argv[0][exename_start])); + for (int i=1; i < argc; i++) fprintf(stdout, " %s", argv[i]); + fprintf(stdout, "\n"); + } else { + fprintf(stdout, "[%s] starting...\n", &(argv[0][exename_start])); + } + fflush(stdout); + printf("\n"); fflush(stdout); + return exename_start; +} + +enum eQAstatus { + QA_FAILED = 0, + QA_PASSED = 1, + QA_WAIVED = 2 +}; + +inline void __ExitInTime(int seconds) +{ + fprintf(stdout, "> exiting in %d seconds: ", seconds); + fflush(stdout); + time_t t; + int count; + for (t=time(0)+seconds, count=seconds; time(0) < t; count--) { + fprintf(stdout, "%d...", count); +#ifdef WIN32 + Sleep(1000); +#else + sleep(1); +#endif + } + fprintf(stdout,"done!\n\n"); + fflush(stdout); +} + + +inline void __shrQAFinish(int argc, const char **argv, int iStatus) +{ + // By default QATest is disabled and NoPrompt is Enabled (times out at seconds passed into __ExitInTime() ) + bool bQATest = false, bNoPrompt = true, bQuitInTime = true; + const char *sStatus[] = { "FAILED", "PASSED", "WAIVED", NULL }; + + for (int i=1; i < argc; i++) { + int string_start = 0; + while (argv[i][string_start] == '-') + string_start++; + + const char *string_argv = &argv[i][string_start]; + if (!STRCASECMP(string_argv, "qatest")) { + bQATest = true; + } + // For SDK individual samples that don't specify -noprompt or -prompt, + // a 3 second delay will happen before exiting, giving a user time to view results + if (!STRCASECMP(string_argv, "noprompt") || !STRCASECMP(string_argv, "help")) { + bNoPrompt = true; + bQuitInTime = false; + } + if (!STRCASECMP(string_argv, "prompt")) { + bNoPrompt = false; + bQuitInTime = false; + } + } + + int exename_start = findExeNameStart(argv[0]); + if (bQATest) { + fprintf(stdout, "&&&& %s %s", sStatus[iStatus], &(argv[0][exename_start])); + for (int i=1; i < argc; i++) fprintf(stdout, " %s", argv[i]); + fprintf(stdout, "\n"); + } else { + fprintf(stdout, "[%s] test results...\n%s\n", &(argv[0][exename_start]), sStatus[iStatus]); + } + fflush(stdout); + printf("\n"); fflush(stdout); + if (bQuitInTime) { + __ExitInTime(3); + } else { + if (!bNoPrompt) { + fprintf(stdout, "\nPress to exit...\n"); + fflush(stdout); + getchar(); + } + } +} + +inline void __shrQAFinish2(bool bQATest, int argc, const char **argv, int iStatus) +{ + bool bQuitInTime = true; + const char *sStatus[] = { "FAILED", "PASSED", "WAIVED", NULL }; + + for (int i=1; i < argc; i++) { + int string_start = 0; + while (argv[i][string_start] == '-') + string_start++; + + const char *string_argv = &argv[i][string_start]; + // For SDK individual samples that don't specify -noprompt or -prompt, + // a 3 second delay will happen before exiting, giving a user time to view results + if (!STRCASECMP(string_argv, "noprompt") || !STRCASECMP(string_argv, "help")) { + bQuitInTime = false; + } + if (!STRCASECMP(string_argv, "prompt")) { + bQuitInTime = false; + } + } + + int exename_start = findExeNameStart(argv[0]); + if (bQATest) { + fprintf(stdout, "&&&& %s %s", sStatus[iStatus], &(argv[0][exename_start])); + for (int i=1; i < argc; i++) fprintf(stdout, " %s", argv[i]); + fprintf(stdout, "\n"); + } else { + fprintf(stdout, "[%s] test results...\n%s\n", &(argv[0][exename_start]), sStatus[iStatus]); + } + fflush(stdout); + + if (bQuitInTime) { + __ExitInTime(3); + } +} + +inline void shrQAFinishExit(int argc, const char **argv, int iStatus) +{ + __shrQAFinish(argc, argv, iStatus); + + exit(iStatus ? EXIT_SUCCESS : EXIT_FAILURE); +} + +inline void shrQAFinishExit2(bool bQAtest, int argc, const char **argv, int iStatus) +{ + __shrQAFinish2(bQAtest, argc, argv, iStatus); + + exit(iStatus ? EXIT_SUCCESS : EXIT_FAILURE); +} + +#endif diff --git a/src/cuda/common/sdk-compat/inc/shrUtils.h b/src/cuda/common/sdk-compat/inc/shrUtils.h new file mode 100644 index 000000000..4643b3531 --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/shrUtils.h @@ -0,0 +1,642 @@ +/* +* Copyright 1993-2010 NVIDIA Corporation. All rights reserved. +* +* Please refer to the NVIDIA end user license agreement (EULA) associated +* with this source code for terms and conditions that govern your use of +* this software. Any use, reproduction, disclosure, or distribution of +* this software and related documentation outside the terms of the EULA +* is strictly prohibited. +* +*/ + +#ifndef SHR_UTILS_H +#define SHR_UTILS_H + +// ********************************************************************* +// Generic utilities for NVIDIA GPU Computing SDK +// ********************************************************************* + +// reminders for output window and build log +#ifdef _WIN32 + #pragma message ("Note: including windows.h") + #pragma message ("Note: including math.h") + #pragma message ("Note: including assert.h") +#endif + +// OS dependent includes +#ifdef _WIN32 + // Headers needed for Windows + #include +#else + // Headers needed for Linux + #include + #include + #include + #include + #include + #include + #include +#endif + +// Other headers needed for both Windows and Linux +#include +#include +#include +#include +#include + +// Un-comment the following #define to enable profiling code in SDK apps +//#define GPU_PROFILING + +// Beginning of GPU Architecture definitions +inline int ConvertSMVer2Cores(int major, int minor) +{ + // Defines for GPU Architecture types (using the SM version to determine the # of cores per SM + typedef struct { + int SM; // 0xMm (hexidecimal notation), M = SM Major version, and m = SM minor version + int Cores; + } sSMtoCores; + + sSMtoCores nGpuArchCoresPerSM[] = + { { 0x10, 8 }, // Tesla Generation (SM 1.0) G80 class + { 0x11, 8 }, // Tesla Generation (SM 1.1) G8x class + { 0x12, 8 }, // Tesla Generation (SM 1.2) G9x class + { 0x13, 8 }, // Tesla Generation (SM 1.3) GT200 class + { 0x20, 32 }, // Fermi Generation (SM 2.0) GF100 class + { 0x21, 48 }, // Fermi Generation (SM 2.1) GF10x class + { 0x30, 192}, // Fermi Generation (SM 3.0) GK10x class + { -1, -1 } + }; + + int index = 0; + while (nGpuArchCoresPerSM[index].SM != -1) { + if (nGpuArchCoresPerSM[index].SM == ((major << 4) + minor) ) { + return nGpuArchCoresPerSM[index].Cores; + } + index++; + } + printf("MapSMtoCores SM %d.%d is undefined (please update to the latest SDK)!\n", major, minor); + return -1; +} +// end of GPU Architecture definitions + + +// Defines and enum for use with logging functions +// ********************************************************************* +#define DEFAULTLOGFILE "SdkConsoleLog.txt" +#define MASTERLOGFILE "SdkMasterLog.csv" +enum LOGMODES +{ + LOGCONSOLE = 1, // bit to signal "log to console" + LOGFILE = 2, // bit to signal "log to file" + LOGBOTH = 3, // convenience union of first 2 bits to signal "log to both" + APPENDMODE = 4, // bit to set "file append" mode instead of "replace mode" on open + MASTER = 8, // bit to signal master .csv log output + ERRORMSG = 16, // bit to signal "pre-pend Error" + CLOSELOG = 32 // bit to close log file, if open, after any requested file write +}; +#define HDASHLINE "-----------------------------------------------------------\n" + +// Standardized boolean +enum shrBOOL +{ + shrFALSE = 0, + shrTRUE = 1 +}; + +// Standardized MAX, MIN and CLAMP +#define MAX(a, b) ((a > b) ? a : b) +#define MIN(a, b) ((a < b) ? a : b) +#define CLAMP(a, b, c) MIN(MAX(a, b), c) // double sided clip of input a +#define TOPCLAMP(a, b) (a < b ? a:b) // single top side clip of input a + +// Error and Exit Handling Macros... +// ********************************************************************* +// Full error handling macro with Cleanup() callback (if supplied)... +// (Companion Inline Function lower on page) +#define shrCheckErrorEX(a, b, c) __shrCheckErrorEX(a, b, c, __FILE__ , __LINE__) + +// Short version without Cleanup() callback pointer +// Both Input (a) and Reference (b) are specified as args +#define shrCheckError(a, b) shrCheckErrorEX(a, b, 0) + +// Standardized Exit Macro for leaving main()... extended version +// (Companion Inline Function lower on page) +#define shrExitEX(a, b, c) __shrExitEX(a, b, c) + +// Standardized Exit Macro for leaving main()... short version +// (Companion Inline Function lower on page) +#define shrEXIT(a, b) __shrExitEX(a, b, EXIT_SUCCESS) + +// Simple argument checker macro +#define ARGCHECK(a) if((a) != shrTRUE)return shrFALSE + +// Define for user-customized error handling +#define STDERROR "file %s, line %i\n\n" , __FILE__ , __LINE__ + +// Function to deallocate memory allocated within shrUtils +// ********************************************************************* +extern "C" void shrFree(void* ptr); + +// ********************************************************************* +// Helper function to log standardized information to Console, to File or to both +//! Examples: shrLogEx(LOGBOTH, 0, "Function A\n"); +//! : shrLogEx(LOGBOTH | ERRORMSG, ciErrNum, STDERROR); +//! +//! Automatically opens file and stores handle if needed and not done yet +//! Closes file and nulls handle on request +//! +//! @param 0 iLogMode: LOGCONSOLE, LOGFILE, LOGBOTH, APPENDMODE, MASTER, ERRORMSG, CLOSELOG. +//! LOGFILE and LOGBOTH may be | 'd with APPENDMODE to select file append mode instead of overwrite mode +//! LOGFILE and LOGBOTH may be | 'd with CLOSELOG to "write and close" +//! First 3 options may be | 'd with MASTER to enable independent write to master data log file +//! First 3 options may be | 'd with ERRORMSG to start line with standard error message +//! @param 2 dValue: +//! Positive val = double value for time in secs to be formatted to 6 decimals. +//! Negative val is an error code and this give error preformatting. +//! @param 3 cFormatString: String with formatting specifiers like printf or fprintf. +//! ALL printf flags, width, precision and type specifiers are supported with this exception: +//! Wide char type specifiers intended for wprintf (%S and %C) are NOT supported +//! Single byte char type specifiers (%s and %c) ARE supported +//! @param 4... variable args: like printf or fprintf. Must match format specifer type above. +//! @return 0 if OK, negative value on error or if error occurs or was passed in. +// ********************************************************************* +extern "C" int shrLogEx(int iLogMode, int iErrNum, const char* cFormatString, ...); + +// Short version of shrLogEx defaulting to shrLogEx(LOGBOTH, 0, +// ********************************************************************* +extern "C" int shrLog(const char* cFormatString, ...); + +// ********************************************************************* +// Delta timer function for up to 3 independent timers using host high performance counters +// Maintains state for 3 independent counters +//! Example: double dElapsedTime = shrDeltaTime(0); +//! +//! @param 0 iCounterID: Which timer to check/reset. (0, 1, 2) +//! @return delta time of specified counter since last call in seconds. Otherwise -9999.0 if error +// ********************************************************************* +extern "C" double shrDeltaT(int iCounterID); + +// Optional LogFileNameOverride function +// ********************************************************************* +extern "C" void shrSetLogFileName (const char* cOverRideName); + +// Helper function to init data arrays +// ********************************************************************* +extern "C" void shrFillArray(float* pfData, int iSize); + +// Helper function to print data arrays +// ********************************************************************* +extern "C" void shrPrintArray(float* pfData, int iSize); + +//////////////////////////////////////////////////////////////////////////// +//! Find the path for a filename +//! @return the path if succeeded, otherwise 0 +//! @param filename name of the file +//! @param executablePath optional absolute path of the executable +//////////////////////////////////////////////////////////////////////////// +extern "C" char* shrFindFilePath(const char* filename, const char* executablePath); + +//////////////////////////////////////////////////////////////////////////// +//! Read file \filename containing single precision floating point data +//! @return shrTRUE if reading the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//! @note If a NULL pointer is passed to this function and it is initialized +//! within shrUtils, then free() has to be used to deallocate the memory +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrReadFilef( const char* filename, float** data, unsigned int* len, + bool verbose = false); + +//////////////////////////////////////////////////////////////////////////// +//! Read file \filename containing double precision floating point data +//! @return shrTRUE if reading the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//! @note If a NULL pointer is passed to this function and it is +//! @note If a NULL pointer is passed to this function and it is initialized +//! within shrUtils, then free() has to be used to deallocate the memory +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrReadFiled( const char* filename, double** data, unsigned int* len, + bool verbose = false); + +//////////////////////////////////////////////////////////////////////////// +//! Read file \filename containing integer data +//! @return shrTRUE if reading the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//! @note If a NULL pointer is passed to this function and it is +//! @note If a NULL pointer is passed to this function and it is initialized +//! within shrUtils, then free() has to be used to deallocate the memory +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrReadFilei( const char* filename, int** data, unsigned int* len, bool verbose = false); + +//////////////////////////////////////////////////////////////////////////// +//! Read file \filename containing unsigned integer data +//! @return shrTRUE if reading the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//! @note If a NULL pointer is passed to this function and it is +//! @note If a NULL pointer is passed to this function and it is initialized +//! within shrUtils, then free() has to be used to deallocate the memory +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrReadFileui( const char* filename, unsigned int** data, + unsigned int* len, bool verbose = false); + +//////////////////////////////////////////////////////////////////////////// +//! Read file \filename containing char / byte data +//! @return shrTRUE if reading the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//! @note If a NULL pointer is passed to this function and it is +//! @note If a NULL pointer is passed to this function and it is initialized +//! within shrUtils, then free() has to be used to deallocate the memory +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrReadFileb( const char* filename, char** data, unsigned int* len, + bool verbose = false); + +//////////////////////////////////////////////////////////////////////////// +//! Read file \filename containing unsigned char / byte data +//! @return shrTRUE if reading the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//! @note If a NULL pointer is passed to this function and it is +//! @note If a NULL pointer is passed to this function and it is initialized +//! within shrUtils, then free() has to be used to deallocate the memory +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrReadFileub( const char* filename, unsigned char** data, + unsigned int* len, bool verbose = false); + +//////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename containing single precision floating point +//! data +//! @return shrTRUE if writing the file succeeded, otherwise shrFALSE +//! @param filename name of the file to write +//! @param data pointer to data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrWriteFilef( const char* filename, const float* data, unsigned int len, + const float epsilon, bool verbose = false); + +//////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename containing double precision floating point +//! data +//! @return shrTRUE if writing the file succeeded, otherwise shrFALSE +//! @param filename name of the file to write +//! @param data pointer to data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrWriteFiled( const char* filename, const float* data, unsigned int len, + const double epsilon, bool verbose = false); + +//////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename containing integer data +//! @return shrTRUE if writing the file succeeded, otherwise shrFALSE +//! @param filename name of the file to write +//! @param data pointer to data to write +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrWriteFilei( const char* filename, const int* data, unsigned int len, + bool verbose = false); + +//////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename containing unsigned integer data +//! @return shrTRUE if writing the file succeeded, otherwise shrFALSE +//! @param filename name of the file to write +//! @param data pointer to data to write +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrWriteFileui( const char* filename, const unsigned int* data, + unsigned int len, bool verbose = false); + +//////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename containing char / byte data +//! @return shrTRUE if writing the file succeeded, otherwise shrFALSE +//! @param filename name of the file to write +//! @param data pointer to data to write +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrWriteFileb( const char* filename, const char* data, unsigned int len, + bool verbose = false); + +//////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename containing unsigned char / byte data +//! @return shrTRUE if writing the file succeeded, otherwise shrFALSE +//! @param filename name of the file to write +//! @param data pointer to data to write +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrWriteFileub( const char* filename, const unsigned char* data, + unsigned int len, bool verbose = false); + +//////////////////////////////////////////////////////////////////////////// +//! Load PPM image file (with unsigned char as data element type), padding +//! 4th component +//! @return shrTRUE if reading the file succeeded, otherwise shrFALSE +//! @param file name of the image file +//! @param OutData handle to the data read +//! @param w width of the image +//! @param h height of the image +//! +//! Note: If *OutData is NULL this function allocates buffer that must be freed by caller +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrLoadPPM4ub(const char* file, unsigned char** OutData, + unsigned int *w, unsigned int *h); + +//////////////////////////////////////////////////////////////////////////// +//! Save PPM image file (with unsigned char as data element type, padded to +//! 4 bytes) +//! @return shrTRUE if saving the file succeeded, otherwise shrFALSE +//! @param file name of the image file +//! @param data handle to the data read +//! @param w width of the image +//! @param h height of the image +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrSavePPM4ub( const char* file, unsigned char *data, + unsigned int w, unsigned int h); + +//////////////////////////////////////////////////////////////////////////////// +//! Save PGM image file (with unsigned char as data element type) +//! @return shrTRUE if saving the file succeeded, otherwise shrFALSE +//! @param file name of the image file +//! @param data handle to the data read +//! @param w width of the image +//! @param h height of the image +//////////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrSavePGMub( const char* file, unsigned char *data, + unsigned int w, unsigned int h); + +//////////////////////////////////////////////////////////////////////////// +//! Load PGM image file (with unsigned char as data element type) +//! @return shrTRUE if saving the file succeeded, otherwise shrFALSE +//! @param file name of the image file +//! @param data handle to the data read +//! @param w width of the image +//! @param h height of the image +//! @note If a NULL pointer is passed to this function and it is initialized +//! within shrUtils, then free() has to be used to deallocate the memory +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrLoadPGMub( const char* file, unsigned char** data, + unsigned int *w,unsigned int *h); + +//////////////////////////////////////////////////////////////////////////// +// Command line arguments: General notes +// * All command line arguments begin with '--' followed by the token; +// token and value are seperated by '='; example --samples=50 +// * Arrays have the form --model=[one.obj,two.obj,three.obj] +// (without whitespaces) +//////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////// +//! Check if command line argument \a flag-name is given +//! @return shrTRUE if command line argument \a flag_name has been given, +//! otherwise shrFALSE +//! @param argc argc as passed to main() +//! @param argv argv as passed to main() +//! @param flag_name name of command line flag +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrCheckCmdLineFlag( const int argc, const char** argv, + const char* flag_name); + +//////////////////////////////////////////////////////////////////////////// +//! Get the value of a command line argument of type int +//! @return shrTRUE if command line argument \a arg_name has been given and +//! is of the requested type, otherwise shrFALSE +//! @param argc argc as passed to main() +//! @param argv argv as passed to main() +//! @param arg_name name of the command line argument +//! @param val value of the command line argument +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrGetCmdLineArgumenti( const int argc, const char** argv, + const char* arg_name, int* val); + +//////////////////////////////////////////////////////////////////////////// +//! Get the value of a command line argument of type unsigned int +//! @return shrTRUE if command line argument \a arg_name has been given and +//! is of the requested type, otherwise shrFALSE +//! @param argc argc as passed to main() +//! @param argv argv as passed to main() +//! @param arg_name name of the command line argument +//! @param val value of the command line argument +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrGetCmdLineArgumentu( const int argc, const char** argv, + const char* arg_name, unsigned int* val); + +//////////////////////////////////////////////////////////////////////////// +//! Get the value of a command line argument of type float +//! @return shrTRUE if command line argument \a arg_name has been given and +//! is of the requested type, otherwise shrFALSE +//! @param argc argc as passed to main() +//! @param argv argv as passed to main() +//! @param arg_name name of the command line argument +//! @param val value of the command line argument +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrGetCmdLineArgumentf( const int argc, const char** argv, + const char* arg_name, float* val); + +//////////////////////////////////////////////////////////////////////////// +//! Get the value of a command line argument of type string +//! @return shrTRUE if command line argument \a arg_name has been given and +//! is of the requested type, otherwise shrFALSE +//! @param argc argc as passed to main() +//! @param argv argv as passed to main() +//! @param arg_name name of the command line argument +//! @param val value of the command line argument +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrGetCmdLineArgumentstr( const int argc, const char** argv, + const char* arg_name, char** val); + +//////////////////////////////////////////////////////////////////////////// +//! Get the value of a command line argument list those element are strings +//! @return shrTRUE if command line argument \a arg_name has been given and +//! is of the requested type, otherwise shrFALSE +//! @param argc argc as passed to main() +//! @param argv argv as passed to main() +//! @param arg_name name of the command line argument +//! @param val command line argument list +//! @param len length of the list / number of elements +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrGetCmdLineArgumentListstr( const int argc, const char** argv, + const char* arg_name, char** val, + unsigned int* len); + +//////////////////////////////////////////////////////////////////////////// +//! Compare two float arrays +//! @return shrTRUEif \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrComparef( const float* reference, const float* data, + const unsigned int len); + +//////////////////////////////////////////////////////////////////////////// +//! Compare two integer arrays +//! @return shrTRUEif \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrComparei( const int* reference, const int* data, + const unsigned int len ); + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two unsigned integer arrays, with epsilon and threshold +//! @return shrTRUEif \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param threshold tolerance % # of comparison errors (0.15f = 15%) +//////////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrCompareuit( const unsigned int* reference, const unsigned int* data, + const unsigned int len, const float epsilon, const float threshold ); + +//////////////////////////////////////////////////////////////////////////// +//! Compare two unsigned char arrays +//! @return shrTRUEif \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrCompareub( const unsigned char* reference, const unsigned char* data, + const unsigned int len ); + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two integers with a tolernance for # of byte errors +//! @return shrTRUEif \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +//! @param threshold tolerance % # of comparison errors (0.15f = 15%) +//////////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrCompareubt( const unsigned char* reference, const unsigned char* data, + const unsigned int len, const float epsilon, const float threshold ); + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two integer arrays witha n epsilon tolerance for equality +//! @return shrTRUEif \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +//////////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrCompareube( const unsigned char* reference, const unsigned char* data, + const unsigned int len, const float epsilon ); + +//////////////////////////////////////////////////////////////////////////// +//! Compare two float arrays with an epsilon tolerance for equality +//! @return shrTRUEif \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrComparefe( const float* reference, const float* data, + const unsigned int len, const float epsilon ); + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two float arrays with an epsilon tolerance for equality and a +//! threshold for # pixel errors +//! @return shrTRUEif \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +//////////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrComparefet( const float* reference, const float* data, + const unsigned int len, const float epsilon, const float threshold ); + +//////////////////////////////////////////////////////////////////////////// +//! Compare two float arrays using L2-norm with an epsilon tolerance for +//! equality +//! @return shrTRUEif \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +//////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrCompareL2fe( const float* reference, const float* data, + const unsigned int len, const float epsilon ); + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two PPM image files with an epsilon tolerance for equality +//! @return shrTRUEif \a reference and \a data are identical, otherwise shrFALSE +//! @param src_file filename for the image to be compared +//! @param data filename for the reference data / gold image +//! @param epsilon epsilon to use for the comparison +//! @param threshold threshold of pixels that can still mismatch to pass (i.e. 0.15f = 15% must pass) +//! $param verboseErrors output details of image mismatch to std::err +//////////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrComparePPM( const char *src_file, const char *ref_file, const float epsilon, const float threshold); + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two PGM image files with an epsilon tolerance for equality +//! @return shrTRUEif \a reference and \a data are identical, otherwise shrFALSE +//! @param src_file filename for the image to be compared +//! @param data filename for the reference data / gold image +//! @param epsilon epsilon to use for the comparison +//! @param threshold threshold of pixels that can still mismatch to pass (i.e. 0.15f = 15% must pass) +//! $param verboseErrors output details of image mismatch to std::err +//////////////////////////////////////////////////////////////////////////////// +extern "C" shrBOOL shrComparePGM( const char *src_file, const char *ref_file, const float epsilon, const float threshold); + +extern "C" unsigned char* shrLoadRawFile(const char* filename, size_t size); + +extern "C" size_t shrRoundUp(int group_size, int global_size); + +// companion inline function for error checking and exit on error WITH Cleanup Callback (if supplied) +// ********************************************************************* +inline void __shrCheckErrorEX(int iSample, int iReference, void (*pCleanup)(int), const char* cFile, const int iLine) +{ + if (iReference != iSample) + { + shrLogEx(LOGBOTH | ERRORMSG, iSample, "line %i , in file %s !!!\n\n" , iLine, cFile); + if (pCleanup != NULL) + { + pCleanup(EXIT_FAILURE); + } + else + { + shrLogEx(LOGBOTH | CLOSELOG, 0, "Exiting...\n"); + exit(EXIT_FAILURE); + } + } +} + +// Standardized Exit +// ********************************************************************* +inline void __shrExitEX(int argc, const char** argv, int iExitCode) +{ +#ifdef WIN32 + if (!shrCheckCmdLineFlag(argc, argv, "noprompt") && !shrCheckCmdLineFlag(argc, argv, "qatest")) +#else + if (shrCheckCmdLineFlag(argc, argv, "prompt") && !shrCheckCmdLineFlag(argc, argv, "qatest")) +#endif + { + shrLogEx(LOGBOTH | CLOSELOG, 0, "\nPress to Quit...\n"); + getchar(); + } + else + { + shrLogEx(LOGBOTH | CLOSELOG, 0, "%s Exiting...\n", argv[0]); + } + fflush(stderr); + exit(iExitCode); +} + +#endif diff --git a/src/cuda/common/sdk-compat/inc/stopwatch.h b/src/cuda/common/sdk-compat/inc/stopwatch.h new file mode 100644 index 000000000..c40e92fe2 --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/stopwatch.h @@ -0,0 +1,45 @@ +/* + * Copyright 1993-2012 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + +/* CUda UTility Library */ + +#ifndef _STOPWATCH_H_ +#define _STOPWATCH_H_ + +// stop watch base class +#include + +// include OS specific policy +#ifdef _WIN32 +# include +typedef StopWatchWin OSStopWatch; +#else +# include +typedef StopWatchLinux OSStopWatch; +#endif + +// concrete stop watch type +typedef StopWatchBase StopWatchC; + +namespace StopWatch +{ +//! Create a stop watch +const unsigned int create(); + +//! Get a handle to the stop watch with the name \a name +StopWatchC& get( const unsigned int& name); + +// Delete the stop watch with the name \a name +void destroy( const unsigned int& name); +} // end namespace, stopwatch + +#endif // _STOPWATCH_H_ + diff --git a/src/cuda/common/sdk-compat/inc/stopwatch_base.h b/src/cuda/common/sdk-compat/inc/stopwatch_base.h new file mode 100644 index 000000000..da2ad5d6a --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/stopwatch_base.h @@ -0,0 +1,76 @@ +/* + * Copyright 1993-2012 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + +/* CUda UTility Library */ + +#ifndef _STOPWATCH_BASE_H_ +#define _STOPWATCH_BASE_H_ + +// includes, system +#include + +//! Simple stop watch +template +class StopWatchBase : public OSPolicy +{ +public: + + // generic, specialized type + typedef StopWatchBase SelfType; + // generic, specialized type pointer + typedef StopWatchBase* SelfTypePtr; + + //! global index for all stop watches + static std::vector< SelfTypePtr > swatches; + +public: + + //! Constructor, default + StopWatchBase(); + + // Destructor + ~StopWatchBase(); + +public: + + //! Start time measurement + inline void start(); + + //! Stop time measurement + inline void stop(); + + //! Reset time counters to zero + inline void reset(); + + //! Time in msec. after start. If the stop watch is still running (i.e. there + //! was no call to stop()) then the elapsed time is returned, otherwise the + //! time between the last start() and stop call is returned + inline float getTime(); + + //! Mean time to date based on the number of times the stopwatch has been + //! _stopped_ (ie finished sessions) and the current total time + inline float getAverageTime(); + +private: + + //! Constructor, copy (not implemented) + StopWatchBase( const StopWatchBase&); + + //! Assignment operator (not implemented) + StopWatchBase& operator=( const StopWatchBase&); +}; + +// include, implementation +#include + + +#endif // _STOPWATCH_BASE_H_ + diff --git a/src/cuda/common/sdk-compat/inc/stopwatch_base.inl b/src/cuda/common/sdk-compat/inc/stopwatch_base.inl new file mode 100644 index 000000000..ad5c29a70 --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/stopwatch_base.inl @@ -0,0 +1,81 @@ +/* +* Copyright 1993-2010 NVIDIA Corporation. All rights reserved. +* +* Please refer to the NVIDIA end user license agreement (EULA) associated +* with this source code for terms and conditions that govern your use of +* this software. Any use, reproduction, disclosure, or distribution of +* this software and related documentation outside the terms of the EULA +* is strictly prohibited. +* +*/ + +/* CUda UTility Library */ + +//////////////////////////////////////////////////////////////////////////////// +//! Constructor, default +//////////////////////////////////////////////////////////////////////////////// +template +StopWatchBase::StopWatchBase() : +OSPolicy() +{ } + +//////////////////////////////////////////////////////////////////////////////// +//! Destructor +//////////////////////////////////////////////////////////////////////////////// +template +StopWatchBase::~StopWatchBase() { } + +/////////////////////////////////////////////////////////////////////////////// +//! Start time measurement +//////////////////////////////////////////////////////////////////////////////// +template +inline void +StopWatchBase::start() +{ + OSPolicy::start(); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Stop time measurement +//////////////////////////////////////////////////////////////////////////////// +template +inline void +StopWatchBase::stop() +{ + OSPolicy::stop(); +} + + +//////////////////////////////////////////////////////////////////////////////// +//! Reset the timer to 0. Does not change the timer running state but does +//! recapture this point in time as the current start time if it is running. +//////////////////////////////////////////////////////////////////////////////// +template +inline void +StopWatchBase::reset() +{ + OSPolicy::reset(); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Time in msec. after start. If the stop watch is still running (i.e. there +//! was no call to stop()) then the elapsed time is returned, otherwise the +//! time between the last start() and stop call is returned +//////////////////////////////////////////////////////////////////////////////// +template +inline float +StopWatchBase::getTime() +{ + return OSPolicy::getTime(); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Time in msec. for a single run based on the total number of COMPLETED runs +//! and the total time. +//////////////////////////////////////////////////////////////////////////////// +template +inline float +StopWatchBase::getAverageTime() +{ + return OSPolicy::getAverageTime(); +} diff --git a/src/cuda/common/sdk-compat/inc/stopwatch_linux.h b/src/cuda/common/sdk-compat/inc/stopwatch_linux.h new file mode 100644 index 000000000..e2536cc6b --- /dev/null +++ b/src/cuda/common/sdk-compat/inc/stopwatch_linux.h @@ -0,0 +1,165 @@ +/* + * Copyright 1993-2012 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + +/* CUda UTility Library */ + +#ifndef _STOPWATCH_LINUX_H_ +#define _STOPWATCH_LINUX_H_ + +// includes, system +#include +#include + +//! Windows specific implementation of StopWatch +class StopWatchLinux +{ +protected: + + //! Constructor, default + StopWatchLinux(); + + // Destructor + ~StopWatchLinux(); + +public: + + //! Start time measurement + inline void start(); + + //! Stop time measurement + inline void stop(); + + //! Reset time counters to zero + inline void reset(); + + //! Time in msec. after start. If the stop watch is still running (i.e. there + //! was no call to stop()) then the elapsed time is returned, otherwise the + //! time between the last start() and stop call is returned + inline const float getTime() const; + + //! Mean time to date based on the number of times the stopwatch has been + //! _stopped_ (ie finished sessions) and the current total time + inline const float getAverageTime() const; + +private: + + // helper functions + + //! Get difference between start time and current time + inline float getDiffTime() const; + +private: + + // member variables + + //! Start of measurement + struct timeval start_time; + + //! Time difference between the last start and stop + float diff_time; + + //! TOTAL time difference between starts and stops + float total_time; + + //! flag if the stop watch is running + bool running; + + //! Number of times clock has been started + //! and stopped to allow averaging + int clock_sessions; +}; + +// functions, inlined + +//////////////////////////////////////////////////////////////////////////////// +//! Start time measurement +//////////////////////////////////////////////////////////////////////////////// +inline void +StopWatchLinux::start() { + + gettimeofday( &start_time, 0); + running = true; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Stop time measurement and increment add to the current diff_time summation +//! variable. Also increment the number of times this clock has been run. +//////////////////////////////////////////////////////////////////////////////// +inline void +StopWatchLinux::stop() { + + diff_time = getDiffTime(); + total_time += diff_time; + running = false; + clock_sessions++; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Reset the timer to 0. Does not change the timer running state but does +//! recapture this point in time as the current start time if it is running. +//////////////////////////////////////////////////////////////////////////////// +inline void +StopWatchLinux::reset() +{ + diff_time = 0; + total_time = 0; + clock_sessions = 0; + if( running ) + gettimeofday( &start_time, 0); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Time in msec. after start. If the stop watch is still running (i.e. there +//! was no call to stop()) then the elapsed time is returned added to the +//! current diff_time sum, otherwise the current summed time difference alone +//! is returned. +//////////////////////////////////////////////////////////////////////////////// +inline const float +StopWatchLinux::getTime() const +{ + // Return the TOTAL time to date + float retval = total_time; + if( running) { + + retval += getDiffTime(); + } + + return retval; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Time in msec. for a single run based on the total number of COMPLETED runs +//! and the total time. +//////////////////////////////////////////////////////////////////////////////// +inline const float +StopWatchLinux::getAverageTime() const +{ + return (clock_sessions > 0) ? (total_time/clock_sessions) : 0.0f; +} + + + +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +inline float +StopWatchLinux::getDiffTime() const +{ + struct timeval t_time; + gettimeofday( &t_time, 0); + + // time difference in milli-seconds + return (float) (1000.0 * ( t_time.tv_sec - start_time.tv_sec) + + (0.001 * (t_time.tv_usec - start_time.tv_usec)) ); +} + +#endif // _STOPWATCH_LINUX_H_ + diff --git a/src/cuda/common/sdk-compat/src/bank_checker.cpp b/src/cuda/common/sdk-compat/src/bank_checker.cpp new file mode 100644 index 000000000..556d9e010 --- /dev/null +++ b/src/cuda/common/sdk-compat/src/bank_checker.cpp @@ -0,0 +1,262 @@ +/* + * Copyright 1993-2010 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + +/* Helper to check for bank conflicts */ + +// includes, files +#include + +// includes, system +#include +#include + +//////////////////////////////////////////////////////////////////////////////// +// Static member variables + +/*static*/ BankChecker BankChecker::bank_checker; +/*static*/ std::map< unsigned int, std::map > + BankChecker::AccessLocation::thread_access; + +/*static*/ const unsigned int BankChecker::AccessLocation::invalid = std::numeric_limits::max(); +/*static*/ const unsigned int BankChecker::AccessInfo::invalid = std::numeric_limits::max(); + +//////////////////////////////////////////////////////////////////////////////// +//! Constructor (private) +//////////////////////////////////////////////////////////////////////////////// +BankChecker::BankChecker() : + access_data(), + last_ltid( warp_size - 1), + total_num_conflicts( 0), + is_active( false) +{ } + +//////////////////////////////////////////////////////////////////////////////// +//! Destructor +//////////////////////////////////////////////////////////////////////////////// +BankChecker::~BankChecker() +{ + if( is_active) { + + std::cout << "Total number of bank conflicts: " << total_num_conflicts + << std::endl; + } +} + +//////////////////////////////////////////////////////////////////////////////// +//! Get a handle to the instance of this class +//////////////////////////////////////////////////////////////////////////////// +/*static*/ BankChecker* const +BankChecker::getHandle() +{ + return &bank_checker; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Side effect of shared memory access +//! Side effect of shared memory access +//! @param tidx thread id in x dimension of block +//! @param tidy thread id in y dimension of block +//! @param tidz thread id in z dimension of block +//! @param bdimx block size in x dimension +//! @param bdimy block size in y dimension +//! @param bdimz block size in z dimension +//! @param file name of the source file where the access takes place +//! @param line line in the source file where the access takes place +//! @param aname name of the array which is accessed +//! @param index index into the array +//////////////////////////////////////////////////////////////////////////////// +void BankChecker:: +access( unsigned int tidx, unsigned int tidy, unsigned int tidz, + unsigned int bdimx, unsigned int bdimy, unsigned int bdimz, + const char* file, const int line, const std::string& aname, + const int index) +{ + is_active = true; + + // linearized thread id + unsigned int ltid = getLtid( tidx, tidy, tidz, bdimx, bdimy, bdimz); + + // reset state if new warp + if( 0 == (ltid & (warp_size - 1))) + { + // double check to handle multiple shared mem accesses in one line + if( last_ltid != 0) + { + reset(); + } + } + + AccessLocation loc( file, line, aname, ltid); + AccessInfo info( ltid, tidx, tidy, tidz, index); + access_data[loc][(index % warp_size)].push_back( info); + + if( 15 == (ltid & (warp_size - 1))) + { + analyse( access_data. find( loc)); + } + + last_ltid = (ltid % warp_size); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Get the linearized thread id for a thread +//! @return linear thread id +//! @param tidx thread id in x dimension of block +//! @param tidy thread id in y dimension of block +//! @param tidz thread id in z dimension of block +//! @param bdimx block size in x dimension +//! @param bdimy block size in y dimension +//! @param bdimz block size in z dimension +//////////////////////////////////////////////////////////////////////////////// +unsigned int BankChecker:: +getLtid( unsigned int tidx, unsigned int tidy, unsigned int tidz, + unsigned int bdimx, unsigned int bdimy, unsigned int /*bdimz*/ ) +{ + return tidx + (tidy * bdimx) + tidz * (bdimx * bdimy); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Reset internal state after processing a warp +//////////////////////////////////////////////////////////////////////////////// +void BankChecker:: +reset() +{ + access_data.clear(); + AccessLocation::thread_access.clear(); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Reset internal state after processing a warp +//////////////////////////////////////////////////////////////////////////////// +void BankChecker:: +analyse( const AccessDataCIter& iter_loc) +{ + // do for all indices which have been accessed at this location + for( IndexAInfoListCIter iter_index = iter_loc->second.begin(); + iter_index != iter_loc->second.end(); + ++iter_index ) + { + // check if index has been accessed more than once + if( (*iter_index).second.size() > 1) + { + + bool differences = false; + unsigned int theindex = 0; + + // Check if all simultaneous bank accesses actually access the + // same index and hence are not really conflicts + for( AccessInfoListCIter iter = (*iter_index).second.begin(); + iter != (*iter_index).second.end(); + ++iter) + { + if( iter == (*iter_index).second.begin() ) + { + theindex = iter->getIndex(); + } + else + { + if( iter->getIndex() != theindex ) + { + differences = true; + break; + } + } + } + + // If we see different indices and therefore real conflicts + // then output this information + if( differences ) + { + ++total_num_conflicts; + + // print out meta information of the access + std::cerr << "\"" << iter_loc->first.getFile() << "\"" + << ", line " << iter_loc->first.getLine() + << ", access " << iter_loc->first.getNumAccessLine() + << ", bank " << iter_index->first + << " ::\n"; + + // print out meta information of all threds which have accessed the + // index + for( AccessInfoListCIter iter = (*iter_index).second.begin(); + iter != (*iter_index).second.end(); + ++iter) + { + std::cerr << iter->getInfo() << '\n'; + } + } + } + } +} + +//////////////////////////////////////////////////////////////////////////////// +// helper classes + +//////////////////////////////////////////////////////////////////////////////// +//! Constructor, default +//////////////////////////////////////////////////////////////////////////////// +BankChecker::AccessLocation::AccessLocation() : + file(), + line( invalid), + num_access_line( invalid), + array_name() +{ + std::cerr<< "Warning: Default constructor of AcccessLocation()." << std::endl; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Destructor +//////////////////////////////////////////////////////////////////////////////// +BankChecker::AccessLocation::~AccessLocation() { } + +//////////////////////////////////////////////////////////////////////////////// +//! Constructor, default +//////////////////////////////////////////////////////////////////////////////// +BankChecker::AccessInfo:: +AccessInfo() : + ltid( invalid), + tidx( invalid), + tidy( invalid), + tidz( invalid) +{ + std::cerr << "Warning: Default constructor of AccessInfo()." << std::endl; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Destructor +//////////////////////////////////////////////////////////////////////////////// +BankChecker::AccessInfo::~AccessInfo() { } + +//////////////////////////////////////////////////////////////////////////////// +// Provide infos as string +//////////////////////////////////////////////////////////////////////////////// +const std::string +BankChecker::AccessInfo:: +getInfo() const +{ + std::ostringstream oss; + oss << "threadIdx.x = " << tidx + << " threadIdx.y = " << tidy + << " threadIdx.z = " << tidz + << " :: index = " << index; + + return oss.str(); +} + +//////////////////////////////////////////////////////////////////////////////// +// Return index +//////////////////////////////////////////////////////////////////////////////// +const unsigned int +BankChecker::AccessInfo:: +getIndex() const +{ + return index; +} diff --git a/src/cuda/common/sdk-compat/src/cmd_arg_reader.cpp b/src/cuda/common/sdk-compat/src/cmd_arg_reader.cpp new file mode 100644 index 000000000..fef65a57e --- /dev/null +++ b/src/cuda/common/sdk-compat/src/cmd_arg_reader.cpp @@ -0,0 +1,152 @@ +/* + * Copyright 1993-2010 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + +/* CUda UTility Library */ + +// includes, file +#include + +// includes, system +#include + +// internal unnamed namespace + +namespace +{ + // types, internal (class, enum, struct, union, typedef) + + // variables, internal + +} // namespace { + +// variables, exported + +/*static*/ CmdArgReader* CmdArgReader::self; +/*static*/ char** CmdArgReader::rargv; +/*static*/ int CmdArgReader::rargc; + +// functions, exported + +//////////////////////////////////////////////////////////////////////////////// +//! Public construction interface +//! @return a handle to the class instance +//! @param argc number of command line arguments (as given to main()) +//! @param argv command line argument string (as given to main()) +//////////////////////////////////////////////////////////////////////////////// +/*static*/ void +CmdArgReader::init( const int argc, const char** argv) +{ + if ( NULL != self) + { + return; + } + + // command line arguments + if (( 0 == argc) || ( 0 == argv)) + { + LOGIC_EXCEPTION( "No command line arguments given."); + } + + self = new CmdArgReader(); + + self->createArgsMaps( argc, argv); + + rargc = argc; + rargv = const_cast( argv); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Constructor, default +//////////////////////////////////////////////////////////////////////////////// +CmdArgReader::CmdArgReader() : + args(), + unprocessed(), + iter(), + iter_unprocessed() +{ } + +//////////////////////////////////////////////////////////////////////////////// +//! Destructor +//////////////////////////////////////////////////////////////////////////////// +CmdArgReader::~CmdArgReader() +{ + for( iter = args.begin(); iter != args.end(); ++iter) + { + if( *(iter->second.first) == typeid( int)) + { + delete static_cast( iter->second.second); + break; + } + else if( *(iter->second.first) == typeid( bool)) + { + delete static_cast( iter->second.second); + break; + } + else if( *(iter->second.first) == typeid( std::string)) + { + delete static_cast( iter->second.second); + break; + } + else if( *(iter->second.first) == typeid( std::vector< std::string>) ) + { + delete static_cast< std::vector< std::string>* >( iter->second.second); + break; + } + else if( *(iter->second.first) == typeid( std::vector) ) + { + delete static_cast< std::vector* >( iter->second.second); + break; + } + } +} + +//////////////////////////////////////////////////////////////////////////////// +//! Read args as token value pair into map for better processing (Even the +//! values remain strings until the parameter values is requested by the +//! program.) +//! @param argc the argument count (as given to 'main') +//! @param argv the char* array containing the command line arguments +//////////////////////////////////////////////////////////////////////////////// +void +CmdArgReader::createArgsMaps( const int argc, const char** argv) { + + std::string token; + std::string val_str; + + std::map< std::string, std::string> args; + + std::string::size_type pos; + std::string arg; + for( int i=1; i + CUTBoolean + loadPGMt( const char* file, T** data, unsigned int *w, unsigned int *h) + { + unsigned char* idata = NULL; + unsigned int channels; + if( CUTTrue != loadPPM(file, &idata, w, h, &channels)) + { + return CUTFalse; + } + + unsigned int size = *w * *h * channels; + + // initialize mem if necessary + // the correct size is checked / set in loadPGMc() + if( NULL == *data) + { + *data = (T*) malloc( sizeof(T) * size); + } + + // copy and cast data + std::transform( idata, idata + size, *data, ConverterFromUByte()); + + free( idata); + + return CUTTrue; + } + + ////////////////////////////////////////////////////////////////////////////// + //! Write / Save PPM or PGM file + //! @note Internal usage only + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + ////////////////////////////////////////////////////////////////////////////// + CUTBoolean + savePPM( const char* file, unsigned char *data, + unsigned int w, unsigned int h, unsigned int channels) + { + CUT_CONDITION( NULL != data); + CUT_CONDITION( w > 0); + CUT_CONDITION( h > 0); + + std::fstream fh( file, std::fstream::out | std::fstream::binary ); + if( fh.bad()) + { + std::cerr << "savePPM() : Opening file failed." << std::endl; + return CUTFalse; + } + + if (channels == 1) + { + fh << "P5\n"; + } + else if (channels == 3) { + fh << "P6\n"; + } + else { + std::cerr << "savePPM() : Invalid number of channels." << std::endl; + return CUTFalse; + } + + fh << w << "\n" << h << "\n" << 0xff << std::endl; + + for( unsigned int i = 0; (i < (w*h*channels)) && fh.good(); ++i) + { + fh << data[i]; + } + fh.flush(); + + if( fh.bad()) + { + std::cerr << "savePPM() : Writing data failed." << std::endl; + return CUTFalse; + } + fh.close(); + + return CUTTrue; + } + + ////////////////////////////////////////////////////////////////////////////// + //! Generic PGM file writer for input data of type T + //! @note Internal usage only + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + ////////////////////////////////////////////////////////////////////////////// + template + CUTBoolean + savePGMt( const char* file, T *data, unsigned int w, unsigned int h) + { + unsigned int size = w * h; + unsigned char* idata = + (unsigned char*) malloc( sizeof(unsigned char) * size); + + std::transform( data, data + size, idata, ConverterToUByte()); + + // write file + CUTBoolean result = savePPM(file, idata, w, h, 1); + + // cleanup + free( idata); + + return result; + } + + ////////////////////////////////////////////////////////////////////////////// + //! Generic PPM file writer for input data of type T + //! @note Internal usage only + //! @param file name of the image file + //! @param data handle to the data read + //! @param w width of the image + //! @param h height of the image + ////////////////////////////////////////////////////////////////////////////// + template + CUTBoolean + savePPMt( const char* file, T *data, unsigned int w, unsigned int h) + { + unsigned int size = w * h * 3; + unsigned char* idata = (unsigned char*) malloc( sizeof(unsigned char) * size); + + std::transform( data, data + size, idata, ConverterToUByte()); + + // write file + CUTBoolean result = savePPM(file, idata, w, h, 3); + + // cleanup + free( idata); + + return result; + } + + ////////////////////////////////////////////////////////////////////////////// + //! Compare two arrays of arbitrary type + //! @return true if \a reference and \a data are identical, otherwise false + //! @param reference handle to the reference data / gold image + //! @param data handle to the computed data + //! @param len number of elements in reference and data + //! @param epsilon epsilon to use for the comparison + ////////////////////////////////////////////////////////////////////////////// + template + CUTBoolean + compareData( const T* reference, const T* data, const unsigned int len, + const S epsilon, const float threshold) + { + CUT_CONDITION( epsilon >= 0); + + bool result = true; + unsigned int error_count = 0; + + for( unsigned int i = 0; i < len; ++i) { + + T diff = reference[i] - data[i]; + bool comp = (diff <= epsilon) && (diff >= -epsilon); + result &= comp; + + error_count += !comp; + +#ifdef _DEBUG + if( ! comp) + { + std::cerr << "ERROR, i = " << i << ",\t " + << reference[i] << " / " + << data[i] + << " (reference / data)\n"; + } +#endif + } + + if (threshold == 0.0f) { + return (result) ? CUTTrue : CUTFalse; + } else { + if (error_count) { + printf("%4.2f(%%) of bytes mismatched (count=%d)\n", (float)error_count*100/(float)len, error_count); + } + + return (len*threshold > error_count) ? CUTTrue : CUTFalse; + } + } + + ////////////////////////////////////////////////////////////////////////////// + //! Compare two arrays of arbitrary type + //! @return true if \a reference and \a data are identical, otherwise false + //! @param reference handle to the reference data / gold image + //! @param data handle to the computed data + //! @param len number of elements in reference and data + //! @param epsilon epsilon to use for the comparison + ////////////////////////////////////////////////////////////////////////////// + template + CUTBoolean + compareDataAsFloat( const T* reference, const T* data, const unsigned int len, + const S epsilon) + { + CUT_CONDITION( epsilon >= 0); + + // If we set epsilon to be 0, let's set a minimum threshold + float max_error = max( (float)epsilon, MIN_EPSILON_ERROR ); + int error_count = 0; + bool result = true; + + for( unsigned int i = 0; i < len; ++i) { + float diff = fabs((float)reference[i] - (float)data[i]); + bool comp = (diff < max_error); + result &= comp; + + if( ! comp) + { + error_count++; +#ifdef _DEBUG + if (error_count < 50) { + printf("\n ERROR(epsilon=%4.3f), i=%d, (ref)0x%02x / (data)0x%02x / (diff)%d\n", max_error, i, reference[i], data[i], (unsigned int)diff); + } +#endif + } + } + if (error_count) { + printf("total # of errors = %d\n", error_count); + } + return (error_count == 0) ? CUTTrue : CUTFalse; + } + + ////////////////////////////////////////////////////////////////////////////// + //! Compare two arrays of arbitrary type + //! @return true if \a reference and \a data are identical, otherwise false + //! @param reference handle to the reference data / gold image + //! @param data handle to the computed data + //! @param len number of elements in reference and data + //! @param epsilon epsilon to use for the comparison + //! @param epsilon threshold % of (# of bytes) for pass/fail + ////////////////////////////////////////////////////////////////////////////// + template + CUTBoolean + compareDataAsFloatThreshold( const T* reference, const T* data, const unsigned int len, + const S epsilon, const float threshold) + { + CUT_CONDITION( epsilon >= 0); + + // If we set epsilon to be 0, let's set a minimum threshold + float max_error = max( (float)epsilon, MIN_EPSILON_ERROR ); + int error_count = 0; + bool result = true; + + for( unsigned int i = 0; i < len; ++i) { + float diff = fabs((float)reference[i] - (float)data[i]); + bool comp = (diff < max_error); + result &= comp; + + if( ! comp) + { + error_count++; +#ifdef _DEBUG + if (error_count < 50) { + printf("\n ERROR(epsilon=%4.3f), i=%d, (ref)0x%02x / (data)0x%02x / (diff)%d\n", max_error, i, reference[i], data[i], (unsigned int)diff); + } +#endif + } + } + + if (threshold == 0.0f) { + if (error_count) { + printf("total # of errors = %d\n", error_count); + } + return (error_count == 0) ? CUTTrue : CUTFalse; + } else { + + if (error_count) { + printf("%4.2f(%%) of bytes mismatched (count=%d)\n", (float)error_count*100/(float)len, error_count); + } + + return ((len*threshold > error_count) ? CUTTrue : CUTFalse); + } + } + + ////////////////////////////////////////////////////////////////////////////// + //! Read file \filename and return the data + //! @return CUTTrue if reading the file succeeded, otherwise false + //! @param filename name of the source file + //! @param data uninitialized pointer, returned initialized and pointing to + //! the data read + //! @param len number of data elements in data, -1 on error + ////////////////////////////////////////////////////////////////////////////// + template + CUTBoolean + cutReadFile( const char* filename, T** data, unsigned int* len, bool verbose) + { + // check input arguments + CUT_CONDITION( NULL != filename); + CUT_CONDITION( NULL != len); + + // intermediate storage for the data read + std::vector data_read; + + // open file for reading + std::fstream fh( filename, std::fstream::in); + // check if filestream is valid + if( ! fh.good()) + { + if (verbose) + std::cerr << "cutReadFile() : Opening file failed." << std::endl; + return CUTFalse; + } + + // read all data elements + T token; + while( fh.good()) + { + fh >> token; + data_read.push_back( token); + } + + // the last element is read twice + data_read.pop_back(); + + // check if reading result is consistent + if( ! fh.eof()) + { + if (verbose) + std::cerr << "WARNING : readData() : reading file might have failed." + << std::endl; + } + + fh.close(); + + // check if the given handle is already initialized + if( NULL != *data) + { + if( *len != data_read.size()) + { + std::cerr << "cutReadFile() : Initialized memory given but " + << "size mismatch with signal read " + << "(data read / data init = " << (unsigned int)data_read.size() + << " / " << *len << ")" << std::endl; + + return CUTFalse; + } + } + else + { + // allocate storage for the data read + *data = (T*) malloc( sizeof(T) * data_read.size()); + // store signal size + *len = static_cast( data_read.size()); + } + + // copy data + memcpy( *data, &data_read.front(), sizeof(T) * data_read.size()); + + return CUTTrue; + } + + ////////////////////////////////////////////////////////////////////////////// + //! Write a data file \filename + //! @return CUTTrue if writing the file succeeded, otherwise CUTFalse + //! @param filename name of the source file + //! @param data data to write + //! @param len number of data elements in data, -1 on error + //! @param epsilon epsilon for comparison + ////////////////////////////////////////////////////////////////////////////// + template + CUTBoolean + cutWriteFile( const char* filename, const T* data, unsigned int len, + const T epsilon, bool verbose) + { + CUT_CONDITION( NULL != filename); + CUT_CONDITION( NULL != data); + + // open file for writing + std::fstream fh( filename, std::fstream::out); + // check if filestream is valid + if( ! fh.good()) + { + if (verbose) + std::cerr << "cutWriteFile() : Opening file failed." << std::endl; + return CUTFalse; + } + + // first write epsilon + fh << "# " << epsilon << "\n"; + + // write data + for( unsigned int i = 0; (i < len) && (fh.good()); ++i) + { + fh << data[i] << ' '; + } + + // Check if writing succeeded + if( ! fh.good()) + { + if (verbose) + std::cerr << "cutWriteFile() : Writing file failed." << std::endl; + return CUTFalse; + } + + // file ends with nl + fh << std::endl; + + return CUTTrue; + } + +} // end, namespace unnamed +////////////////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////// +//! Deallocate memory allocated within Cutil +//! @param pointer to memory +////////////////////////////////////////////////////////////////////////////// +void CUTIL_API +cutFree( void* ptr) { + if( NULL != ptr) free( ptr); +} + +////////////////////////////////////////////////////////////////////////////// +//! Find the path for a file assuming that +//! files are either in data/ or in ../../../src//data/. +//! +//! @return the path if succeeded, otherwise 0 +//! @param filename name of the file +//! @param executable_path optional absolute path of the executable +////////////////////////////////////////////////////////////////////////////// +char* CUTIL_API +cutFindFilePath(const char* filename, const char* executable_path) +{ + // search in data/ + if (filename == 0) + return 0; + size_t filename_len = strlen(filename); + const char data_folder[] = "data/"; + size_t data_folder_len = strlen(data_folder); + char* file_path = + (char*) malloc( sizeof(char) * (data_folder_len + filename_len + 1)); + strcpy(file_path, data_folder); + strcat(file_path, filename); + size_t file_path_len = strlen(file_path); + file_path[file_path_len] = '\0'; + std::fstream fh0(file_path, std::fstream::in); + if (fh0.good()) + return file_path; + free( file_path); + + // search in ../../../src//data/ + if (executable_path == 0) + return 0; + size_t executable_path_len = strlen(executable_path); + const char* exe; + for (exe = executable_path + executable_path_len - 1; + exe >= executable_path; --exe) + if (*exe == '/' || *exe == '\\') + break; + if (exe < executable_path) + exe = executable_path; + else + ++exe; + size_t executable_len = strlen(exe); + size_t executable_dir_len = executable_path_len - executable_len; + const char projects_relative_path[] = "../../../src/"; + size_t projects_relative_path_len = strlen(projects_relative_path); + file_path = + (char*) malloc( sizeof(char) * (executable_path_len + + projects_relative_path_len + 1 + data_folder_len + filename_len + 1)); + strncpy(file_path, executable_path, executable_dir_len); + file_path[executable_dir_len] = '\0'; + strcat(file_path, projects_relative_path); + strcat(file_path, exe); + file_path_len = strlen(file_path); + if (*(file_path + file_path_len - 1) == 'e' && + *(file_path + file_path_len - 2) == 'x' && + *(file_path + file_path_len - 3) == 'e' && + *(file_path + file_path_len - 4) == '.') { + *(file_path + file_path_len - 4) = '/'; + *(file_path + file_path_len - 3) = '\0'; + } + else { + *(file_path + file_path_len - 0) = '/'; + *(file_path + file_path_len + 1) = '\0'; + } + strcat(file_path, data_folder); + strcat(file_path, filename); + file_path_len = strlen(file_path); + file_path[file_path_len] = '\0'; + std::fstream fh1(file_path, std::fstream::in); + if (fh1.good()) + return file_path; + free( file_path); + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Read file \filename containg single precision floating point data +//! @return CUTTrue if reading the file succeeded, otherwise false +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutReadFilef( const char* filename, float** data, unsigned int* len, bool verbose) +{ + return cutReadFile( filename, data, len, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Read file \filename containg double precision floating point data +//! @return CUTTrue if reading the file succeeded, otherwise false +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutReadFiled( const char* filename, double** data, unsigned int* len, bool verbose) +{ + return cutReadFile( filename, data, len, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Read file \filename containg integer data +//! @return CUTTrue if reading the file succeeded, otherwise false +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutReadFilei( const char* filename, int** data, unsigned int* len, bool verbose) +{ + return cutReadFile( filename, data, len, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Read file \filename containg unsigned integer data +//! @return CUTTrue if reading the file succeeded, otherwise false +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutReadFileui( const char* filename, unsigned int** data, unsigned int* len, bool verbose) +{ + return cutReadFile( filename, data, len, verbose); +} + + +//////////////////////////////////////////////////////////////////////////////// +//! Read file \filename containg char / byte data +//! @return CUTTrue if reading the file succeeded, otherwise false +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutReadFileb( const char* filename, char** data, unsigned int* len, bool verbose) +{ + return cutReadFile( filename, data, len, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Read file \filename containg unsigned char / byte data +//! @return CUTTrue if reading the file succeeded, otherwise false +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutReadFileub( const char* filename, unsigned char** data, unsigned int* len, bool verbose) +{ + return cutReadFile( filename, data, len, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for single precision floating point data +//! @return CUTTrue if writing the file succeeded, otherwise CUTFalse +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutWriteFilef( const char* filename, const float* data, unsigned int len, + const float epsilon, bool verbose) +{ + return cutWriteFile( filename, data, len, epsilon, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for double precision floating point data +//! @return CUTTrue if writing the file succeeded, otherwise CUTFalse +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutWriteFiled( const char* filename, const double* data, unsigned int len, + const double epsilon, bool verbose) +{ + return cutWriteFile( filename, data, len, epsilon, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for integer data +//! @return CUTTrue if writing the file succeeded, otherwise CUTFalse +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutWriteFilei( const char* filename, const int* data, unsigned int len, bool verbose) +{ + return cutWriteFile( filename, data, len, 0, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for unsigned integer data +//! @return CUTTrue if writing the file succeeded, otherwise CUTFalse +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutWriteFileui( const char* filename,const unsigned int* data,unsigned int len, bool verbose) +{ + return cutWriteFile( filename, data, len, static_cast(0), verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for byte / char data +//! @return CUTTrue if writing the file succeeded, otherwise CUTFalse +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutWriteFileb( const char* filename, const char* data, unsigned int len, bool verbose) +{ + return cutWriteFile( filename, data, len, static_cast(0), verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for byte / char data +//! @return CUTTrue if writing the file succeeded, otherwise CUTFalse +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutWriteFileub( const char* filename, const unsigned char* data, + unsigned int len, bool verbose) +{ + return cutWriteFile( filename, data, len, static_cast(0), verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for unsigned byte / char data +//! @return CUTTrue if writing the file succeeded, otherwise CUTFalse +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutWriteFileb( const char* filename,const unsigned char* data,unsigned int len, bool verbose) +{ + return cutWriteFile( filename, data, len, static_cast(0), verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Load PGM image file (with unsigned char as data element type) +//! @return CUTTrue if reading the file succeeded, otherwise false +//! @param file name of the image file +//! @param data handle to the data read +//! @param w width of the image +//! @param h height of the image +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutLoadPGMub( const char* file, unsigned char** data, + unsigned int *w,unsigned int *h) +{ + unsigned int channels; + return loadPPM( file, data, w, h, &channels); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Load PPM image file (with unsigned char as data element type) +//! @return CUTTrue if reading the file succeeded, otherwise false +//! @param file name of the image file +//! @param data handle to the data read +//! @param w width of the image +//! @param h height of the image +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutLoadPPMub( const char* file, unsigned char** data, + unsigned int *w,unsigned int *h) +{ + unsigned int channels; + return loadPPM( file, data, w, h, &channels); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Load PPM image file (with unsigned char as data element type), padding 4th component +//! @return CUTTrue if reading the file succeeded, otherwise false +//! @param file name of the image file +//! @param data handle to the data read +//! @param w width of the image +//! @param h height of the image +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutLoadPPM4ub( const char* file, unsigned char** data, + unsigned int *w,unsigned int *h) +{ + unsigned char *idata = 0; + unsigned int channels; + + if (loadPPM( file, &idata, w, h, &channels)) { + // pad 4th component + int size = *w * *h; + // keep the original pointer + unsigned char* idata_orig = idata; + *data = (unsigned char*) malloc( sizeof(unsigned char) * size * 4); + unsigned char *ptr = *data; + for(int i=0; i( arg_name); + if( NULL != v) + { + // assign value + *val = *v; + ret_val = CUTTrue; + } + else { + // fail safe + val = NULL; + } + } + catch( const std::exception& /*ex*/) + { + std::cerr << "Error when parsing command line argument string." << std::endl; + } + + return ret_val; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Get the value of a command line argument of type float +//! @return CUTTrue if command line argument \a arg_name has been given and +//! is of the requested type, otherwise CUTFalse +//! @param argc argc as passed to main() +//! @param argv argv as passed to main() +//! @param arg_name name of the command line argument +//! @param val value of the command line argument +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutGetCmdLineArgumentf( const int argc, const char** argv, + const char* arg_name, float* val) +{ + CUTBoolean ret_val = CUTFalse; + + try + { + // initialize + CmdArgReader::init( argc, argv); + + // access argument + const float* v = CmdArgReader::getArg( arg_name); + if( NULL != v) + { + // assign value + *val = *v; + ret_val = CUTTrue; + } + else { + // fail safe + val = NULL; + } + } + catch( const std::exception& /*ex*/) + { + std::cerr << "Error when parsing command line argument string." << std::endl; + } + + return ret_val; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Get the value of a command line argument of type string +//! @return CUTTrue if command line argument \a arg_name has been given and +//! is of the requested type, otherwise CUTFalse +//! @param argc argc as passed to main() +//! @param argv argv as passed to main() +//! @param arg_name name of the command line argument +//! @param val value of the command line argument +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutGetCmdLineArgumentstr( const int argc, const char** argv, + const char* arg_name, char** val) +{ + CUTBoolean ret_val = CUTFalse; + + try + { + // initialize + CmdArgReader::init( argc, argv); + + // access argument + const std::string* v = CmdArgReader::getArg( arg_name); + if( NULL != v) + { + + // allocate memory for the string + *val = (char*) malloc( sizeof(char) * (v->length() + 1)); + // copy from string to c_str + strcpy( *val, v->c_str()); + ret_val = CUTTrue; + } + else { + // fail safe + *val = NULL; + } + } + catch( const std::exception& /*ex*/) + { + std::cerr << "Error when parsing command line argument string."<< + std::endl; + } + + return ret_val; + +} + +//////////////////////////////////////////////////////////////////////////////// +//! Extended assert +//! @return CUTTrue if the condition \a val holds, otherwise CUTFalse +//! @param val condition to test +//! @param file __FILE__ macro +//! @param line __LINE__ macro +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutCheckCondition( int val, const char* file, const int line) +{ + CUTBoolean ret_val = CUTTrue; + + try + { + // check for error + ErrorChecker::condition( (0 == val) ? false : true, file, line); + } + catch( const std::exception& ex) + { + // print where the exception occured + std::cerr << ex.what() << std::endl; + ret_val = CUTFalse; + } + + return ret_val; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two float arrays +//! @return CUTTrue if \a reference and \a data are identical, +//! otherwise CUTFalse +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutComparef( const float* reference, const float* data, + const unsigned int len ) +{ + const float epsilon = 0.0; + return compareData( reference, data, len, epsilon, 0.0f ); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two integer arrays +//! @return CUTTrue if \a reference and \a data are identical, +//! otherwise CUTFalse +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutComparei( const int* reference, const int* data, + const unsigned int len ) +{ + const int epsilon = 0; + return compareData( reference, data, len, epsilon, 0.0f); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two unsigned integer arrays, with epsilon and threshold +//! @return CUTTrue if \a reference and \a data are identical, +//! otherwise CUTFalse +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutCompareuit( const unsigned int* reference, const unsigned int* data, + const unsigned int len, const float epsilon, const float threshold ) +{ +// const int epsilon = 0; + return compareData( reference, data, len, epsilon, threshold ); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two integer arrays +//! @return CUTTrue if \a reference and \a data are identical, +//! otherwise CUTFalse +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutCompareub( const unsigned char* reference, const unsigned char* data, + const unsigned int len ) +{ + const int epsilon = 0; + return compareData( reference, data, len, epsilon, 0.0f); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two integer arrays (inc Threshold for # of pixel we can have errors) +//! @return CUTTrue if \a reference and \a data are identical, +//! otherwise CUTFalse +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutCompareubt( const unsigned char* reference, const unsigned char* data, + const unsigned int len, const float epsilon, const float threshold ) +{ + return compareDataAsFloatThreshold( reference, data, len, epsilon, threshold ); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two integer arrays +//! @return CUTTrue if \a reference and \a data are identical, +//! otherwise CUTFalse +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutCompareube( const unsigned char* reference, const unsigned char* data, + const unsigned int len, const float epsilon ) +{ + return compareDataAsFloat( reference, data, len, epsilon ); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two float arrays with an epsilon tolerance for equality +//! @return CUTTrue if \a reference and \a data are identical, +//! otherwise CUTFalse +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutComparefe( const float* reference, const float* data, + const unsigned int len, const float epsilon ) +{ + return compareData( reference, data, len, epsilon, 0.0f); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two float arrays with an epsilon tolerance for equality and a +//! threshold for # pixel errors +//! @return CUTTrue if \a reference and \a data are identical, +//! otherwise CUTFalse +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutComparefet( const float* reference, const float* data, + const unsigned int len, const float epsilon, const float threshold ) +{ + return compareDataAsFloatThreshold( reference, data, len, epsilon, threshold ); +} + + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two float arrays using L2-norm with an epsilon tolerance for equality +//! @return CUTTrue if \a reference and \a data are identical, +//! otherwise CUTFalse +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +//////////////////////////////////////////////////////////////////////////////// +CUTBoolean CUTIL_API +cutCompareL2fe( const float* reference, const float* data, + const unsigned int len, const float epsilon ) +{ + CUT_CONDITION( epsilon >= 0); + + float error = 0; + float ref = 0; + + for( unsigned int i = 0; i < len; ++i) { + + float diff = reference[i] - data[i]; + error += diff * diff; + ref += reference[i] * reference[i]; + } + + float normRef = sqrtf(ref); + if (fabs(ref) < 1e-7) { +#ifdef _DEBUG + std::cerr << "ERROR, reference l2-norm is 0\n"; +#endif + return CUTFalse; + } + float normError = sqrtf(error); + error = normError / normRef; + bool result = error < epsilon; +#ifdef _DEBUG + if( ! result) + { + std::cerr << "ERROR, l2-norm error " + << error << " is greater than epsilon " << epsilon << "\n"; + } +#endif + + return result ? CUTTrue : CUTFalse; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two PPM image files with an epsilon tolerance for equality +//! @return CUTTrue if \a reference and \a data are identical, +//! otherwise CUTFalse +//! @param src_file filename for the image to be compared +//! @param data filename for the reference data / gold image +//! @param epsilon epsilon to use for the comparison +//! @param threshold threshold of pixels that can still mismatch to pass (i.e. 0.15f = 15% must pass) +//! @param verboseErrors output details of image mismatch to std::cerr +//////////////////////////////////////////////////////////////////////////////// + +DLL_MAPPING +CUTBoolean CUTIL_API +cutComparePPM( const char *src_file, const char *ref_file, + const float epsilon, const float threshold, bool verboseErrors ) +{ + unsigned char *src_data, *ref_data; + unsigned long error_count = 0; + unsigned int ref_width, ref_height; + unsigned int src_width, src_height; + + if (src_file == NULL || ref_file == NULL) { + if(verboseErrors) std::cerr << "PPMvsPPM: src_file or ref_file is NULL. Aborting comparison\n"; + return CUTFalse; + } + + if(verboseErrors) { + std::cerr << "> Compare (a)rendered: <" << src_file << ">\n"; + std::cerr << "> (b)reference: <" << ref_file << ">\n"; + } + + if (cutLoadPPM4ub(ref_file, &ref_data, &ref_width, &ref_height) != CUTTrue) + { + if(verboseErrors) std::cerr << "PPMvsPPM: unable to load ref image file: "<< ref_file << "\n"; + return CUTFalse; + } + + if (cutLoadPPM4ub(src_file, &src_data, &src_width, &src_height) != CUTTrue) + { + std::cerr << "PPMvsPPM: unable to load src image file: " << src_file << "\n"; + return CUTFalse; + } + + if(src_height != ref_height || src_width != ref_width) + { + if(verboseErrors) std::cerr << "PPMvsPPM: source and ref size mismatch (" << src_width << + "," << src_height << ")vs(" << ref_width << "," << ref_height << ")\n"; + +// src_height = min(src_height, ref_height); +// src_width = min(src_width , ref_width ); +// return CUTFalse; + } + + if(verboseErrors) std::cerr << "PPMvsPPM: comparing images size (" << src_width << + "," << src_height << ") epsilon(" << epsilon << "), threshold(" << threshold*100 << "%)\n"; +// if (cutCompareube( ref_data, src_data, src_width*src_height*4, epsilon ) == CUTFalse) + if (cutCompareubt( ref_data, src_data, src_width*src_height*4, epsilon, threshold ) == CUTFalse) + { + error_count=1; + } + + if (error_count == 0) + { + if(verboseErrors) std::cerr << " OK\n\n"; + } else + { + if(verboseErrors) std::cerr << " FAILURE! "<access( tidx, tidy, tidz, + bdimx, bdimy, bdimz, + file, line, aname, index ); +} + diff --git a/src/cuda/common/sdk-compat/src/multithreading.cpp b/src/cuda/common/sdk-compat/src/multithreading.cpp new file mode 100644 index 000000000..f5756cf6b --- /dev/null +++ b/src/cuda/common/sdk-compat/src/multithreading.cpp @@ -0,0 +1,66 @@ +/* + * Copyright 1993-2010 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + + + +#include + +#if _WIN32 + //Create thread + CUTThread cutStartThread(CUT_THREADROUTINE func, void *data){ + return CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, data, 0, NULL); + } + + //Wait for thread to finish + void cutEndThread(CUTThread thread){ + WaitForSingleObject(thread, INFINITE); + CloseHandle(thread); + } + + //Destroy thread + void cutDestroyThread(CUTThread thread){ + TerminateThread(thread, 0); + CloseHandle(thread); + } + + //Wait for multiple threads + void cutWaitForThreads(const CUTThread * threads, int num){ + WaitForMultipleObjects(num, threads, true, INFINITE); + + for(int i = 0; i < num; i++) + CloseHandle(threads[i]); + } + +#else + //Create thread + CUTThread cutStartThread(CUT_THREADROUTINE func, void * data){ + pthread_t thread; + pthread_create(&thread, NULL, func, data); + return thread; + } + + //Wait for thread to finish + void cutEndThread(CUTThread thread){ + pthread_join(thread, NULL); + } + + //Destroy thread + void cutDestroyThread(CUTThread thread){ + pthread_cancel(thread); + } + + //Wait for multiple threads + void cutWaitForThreads(const CUTThread * threads, int num){ + for(int i = 0; i < num; i++) + cutEndThread(threads[i]); + } + +#endif diff --git a/src/cuda/common/sdk-compat/src/shrUtils.cpp b/src/cuda/common/sdk-compat/src/shrUtils.cpp new file mode 100644 index 000000000..e8c2c5da5 --- /dev/null +++ b/src/cuda/common/sdk-compat/src/shrUtils.cpp @@ -0,0 +1,1925 @@ +/* + * Copyright 1993-2010 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + +// ********************************************************************* +// Generic Utilities for NVIDIA GPU Computing SDK +// ********************************************************************* + +// includes +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; + +// size of PGM file header +const unsigned int PGMHeaderSize = 0x40; +#define MIN_EPSILON_ERROR 1e-3f + +// Deallocate memory allocated within shrUtils +// ********************************************************************* +void shrFree(void* ptr) +{ + if( NULL != ptr) free( ptr); +} + +// Helper function to init data arrays +// ********************************************************************* +void shrFillArray(float* pfData, int iSize) +{ + int i; + const float fScale = 1.0f / (float)RAND_MAX; + for (i = 0; i < iSize; ++i) + { + pfData[i] = fScale * rand(); + } +} + +// Helper function to print data arrays +// ********************************************************************* +void shrPrintArray(float* pfData, int iSize) +{ + int i; + for (i = 0; i < iSize; ++i) + { + shrLog("%d: %.3f\n", i, pfData[i]); + } +} + +// Helper function to return precision delta time for 3 counters since last call based upon host high performance counter +// ********************************************************************* +double shrDeltaT(int iCounterID = 0) +{ + // local var for computation of microseconds since last call + double DeltaT; + + #ifdef _WIN32 // Windows version of precision host timer + + // Variables that need to retain state between calls + static LARGE_INTEGER liOldCount[3] = { {0, 0}, {0, 0}, {0, 0} }; + + // locals for new count, new freq and new time delta + LARGE_INTEGER liNewCount, liFreq; + if (QueryPerformanceFrequency(&liFreq)) + { + // Get new counter reading + QueryPerformanceCounter(&liNewCount); + + if (iCounterID >= 0 && iCounterID <= 2) + { + // Calculate time difference for timer 0. (zero when called the first time) + DeltaT = liOldCount[iCounterID].LowPart ? (((double)liNewCount.QuadPart - (double)liOldCount[iCounterID].QuadPart) / (double)liFreq.QuadPart) : 0.0; + // Reset old count to new + liOldCount[iCounterID] = liNewCount; + } + else + { + // Requested counter ID out of range + DeltaT = -9999.0; + } + + // Returns time difference in seconds sunce the last call + return DeltaT; + } + else + { + // No high resolution performance counter + return -9999.0; + } + #elif defined(UNIX) // Linux version of precision host timer. See http://www.informit.com/articles/article.aspx?p=23618&seqNum=8 + static struct timeval _NewTime; // new wall clock time (struct representation in seconds and microseconds) + static struct timeval _OldTime[3]; // old wall clock timers 0, 1, 2 (struct representation in seconds and microseconds) + + // Get new counter reading + gettimeofday(&_NewTime, NULL); + + if (iCounterID >= 0 && iCounterID <= 2) + { + // Calculate time difference for timer (iCounterID). (zero when called the first time) + DeltaT = ((double)_NewTime.tv_sec + 1.0e-6 * (double)_NewTime.tv_usec) - ((double)_OldTime[iCounterID].tv_sec + 1.0e-6 * (double)_OldTime[iCounterID].tv_usec); + // Reset old timer (iCounterID) to new timer + _OldTime[iCounterID].tv_sec = _NewTime.tv_sec; + _OldTime[iCounterID].tv_usec = _NewTime.tv_usec; + } + else + { + // Requested counterID is out of rangewith respect to available counters + DeltaT = -9999.0; + } + + // Returns time difference in seconds sunce the last call + return DeltaT; + + #elif defined (__APPLE__) || defined (MACOSX) + static time_t _NewTime; + static time_t _OldTime[3]; + + _NewTime = clock(); + + if (iCounterID >= 0 && iCounterID <= 2) + { + // Calculate time difference for timer (iCounterID). (zero when called the first time) + DeltaT = double(_NewTime-_OldTime[iCounterID])/CLOCKS_PER_SEC; + + // Reset old time (iCounterID) to the new one + _OldTime[iCounterID].tv_sec = _NewTime.tv_sec; + _OldTime[iCounterID].tv_usec = _NewTime.tv_usec; + } + else + { + // Requested counter ID out of range + DeltaT = -9999.0; + } + return DeltaT; + #else + printf("shrDeltaT returning early\n"); + #endif +} + +// Optional LogFileName Override function +// ********************************************************************* +char* cLogFilePathAndName = NULL; +void shrSetLogFileName (const char* cOverRideName) +{ + if( cLogFilePathAndName != NULL ) { + free(cLogFilePathAndName); + } + cLogFilePathAndName = (char*) malloc(strlen(cOverRideName) + 1); + #ifdef WIN32 + strcpy_s(cLogFilePathAndName, strlen(cOverRideName) + 1, cOverRideName); + #else + strcpy(cLogFilePathAndName, cOverRideName); + #endif + return; +} + +// Function to log standardized information to console, file or both +// ********************************************************************* +static int shrLogV(int iLogMode, int iErrNum, const char* cFormatString, va_list vaArgList) +{ + static FILE* pFileStream0 = NULL; + static FILE* pFileStream1 = NULL; + size_t szNumWritten = 0; + char cFileMode [3]; + + // if the sample log file is closed and the call includes a "write-to-file", open file for writing + if ((pFileStream0 == NULL) && (iLogMode & LOGFILE)) + { + // if the default filename has not been overriden, set to default + if (cLogFilePathAndName == NULL) + { + shrSetLogFileName(DEFAULTLOGFILE); + } + + #ifdef _WIN32 // Windows version + // set the file mode + if (iLogMode & APPENDMODE) // append to prexisting file contents + { + sprintf_s (cFileMode, 3, "a+"); + } + else // replace prexisting file contents + { + sprintf_s (cFileMode, 3, "w"); + } + + // open the individual sample log file in the requested mode + errno_t err = fopen_s(&pFileStream0, cLogFilePathAndName, cFileMode); + + // if error on attempt to open, be sure the file is null or close it, then return negative error code + if (err != 0) + { + if (pFileStream0) + { + fclose (pFileStream0); + } + iLogMode = LOGCONSOLE; // if we can't open a file, we will still output to the console window + } + #else // Linux & Mac version + // set the file mode + if (iLogMode & APPENDMODE) // append to prexisting file contents + { + sprintf (cFileMode, "a+"); + } + else // replace prexisting file contents + { + sprintf (cFileMode, "w"); + } + + // open the file in the requested mode + if ((pFileStream0 = fopen(cLogFilePathAndName, cFileMode)) == 0) + { + // if error on attempt to open, be sure the file is null or close it, then return negative error code + if (pFileStream0) + { + fclose (pFileStream0); + } + iLogMode = LOGCONSOLE; // if we can't open a file, we will still output to the console window + } + #endif + } + + // if the master log file is closed and the call incudes a "write-to-file" and MASTER, open master logfile file for writing + if ((pFileStream1 == NULL) && (iLogMode & LOGFILE) && (iLogMode & MASTER)) + { + #ifdef _WIN32 // Windows version + // open the master log file in append mode + errno_t err = fopen_s(&pFileStream1, MASTERLOGFILE, "a+"); + + // if error on attempt to open, be sure the file is null or close it, then return negative error code + if (err != 0) + { + if (pFileStream1) + { + fclose (pFileStream1); + pFileStream1 = NULL; + } + iLogMode = LOGCONSOLE; // Force to LOGCONSOLE only since the file stream is invalid +// return -err; + } + #else // Linux & Mac version + + // open the file in the requested mode + if ((pFileStream1 = fopen(MASTERLOGFILE, "a+")) == 0) + { + // if error on attempt to open, be sure the file is null or close it, then return negative error code + if (pFileStream1) + { + fclose (pFileStream1); + pFileStream1 = NULL; + } + iLogMode = LOGCONSOLE; // Force to LOGCONSOLE only since the file stream is invalid +// return -1; + } + #endif + + // If master log file length has become excessive, empty/reopen + if (iLogMode != LOGCONSOLE) + { + fseek(pFileStream1, 0L, SEEK_END); + if (ftell(pFileStream1) > 50000L) + { + fclose (pFileStream1); + #ifdef _WIN32 // Windows version + fopen_s(&pFileStream1, MASTERLOGFILE, "w"); + #else + pFileStream1 = fopen(MASTERLOGFILE, "w"); + #endif + } + } + } + + // Handle special Error Message code + if (iLogMode & ERRORMSG) + { + // print string to console if flagged + if (iLogMode & LOGCONSOLE) + { + szNumWritten = printf ("\n !!! Error # %i at ", iErrNum); // console + } + // print string to file if flagged + if (iLogMode & LOGFILE) + { + szNumWritten = fprintf (pFileStream0, "\n !!! Error # %i at ", iErrNum); // sample log file + } + } + + // Vars used for variable argument processing + const char* pStr; + const char* cArg; + int iArg; + double dArg; + unsigned int uiArg; + std::string sFormatSpec; + const std::string sFormatChars = " -+#0123456789.dioufnpcsXxEeGgAa"; + const std::string sTypeChars = "dioufnpcsXxEeGgAa"; + char cType = 'c'; + + // Start at the head of the string and scan to the null at the end + for (pStr = cFormatString; *pStr; ++pStr) + { + // Check if the current character is not a formatting specifier ('%') + if (*pStr != '%') + { + // character is not '%', so print it verbatim to console and/or files as flagged + if (iLogMode & LOGCONSOLE) + { + szNumWritten = putc(*pStr, stdout); // console + } + if (iLogMode & LOGFILE) + { + szNumWritten = putc(*pStr, pFileStream0); // sample log file + if (iLogMode & MASTER) + { + szNumWritten = putc(*pStr, pFileStream1); // master log file + } + } + } + else + { + // character is '%', so skip over it and read the full format specifier for the argument + ++pStr; + sFormatSpec = '%'; + + // special handling for string of %%%% + bool bRepeater = (*pStr == '%'); + if (bRepeater) + { + cType = '%'; + } + + // chars after the '%' are part of format if on list of constants... scan until that isn't true or NULL is found + while (pStr && ((sFormatChars.find(*pStr) != string::npos) || bRepeater)) + { + sFormatSpec += *pStr; + + // If the char is a type specifier, trap it and stop scanning + // (a type specifier char is always the last in the format except for string of %%%) + if (sTypeChars.find(*pStr) != string::npos) + { + cType = *pStr; + break; + } + + // Special handling for string of %%% + // If a string of %%% was started and then it ends, break (There won't be a typical type specifier) + if (bRepeater && (*pStr != '%')) + { + break; + } + + pStr++; + } + + // Now handle the arg according to type + switch (cType) + { + case '%': // special handling for string of %%%% + { + if (iLogMode & LOGCONSOLE) + { + szNumWritten = printf(sFormatSpec.c_str()); // console + } + if (iLogMode & LOGFILE) + { + szNumWritten = fprintf (pFileStream0, sFormatSpec.c_str()); // sample log file + if (iLogMode & MASTER) + { + szNumWritten = fprintf(pFileStream1, sFormatSpec.c_str()); // master log file + } + } + continue; + } + case 'c': // single byte char + case 's': // string of single byte chars + { + // Set cArg as the next value in list and print to console and/or files if flagged + cArg = va_arg(vaArgList, char*); + if (iLogMode & LOGCONSOLE) + { + szNumWritten = printf(sFormatSpec.c_str(), cArg); // console + } + if (iLogMode & LOGFILE) + { + szNumWritten = fprintf (pFileStream0, sFormatSpec.c_str(), cArg); // sample log file + if (iLogMode & MASTER) + { + szNumWritten = fprintf(pFileStream1, sFormatSpec.c_str(), cArg); // master log file + } + } + continue; + } + case 'd': // signed decimal integer + case 'i': // signed decimal integer + { + // set iArg as the next value in list and print to console and/or files if flagged + iArg = va_arg(vaArgList, int); + if (iLogMode & LOGCONSOLE) + { + szNumWritten = printf(sFormatSpec.c_str(), iArg); // console + } + if (iLogMode & LOGFILE) + { + szNumWritten = fprintf (pFileStream0, sFormatSpec.c_str(), iArg); // sample log file + if (iLogMode & MASTER) + { + szNumWritten = fprintf(pFileStream1, sFormatSpec.c_str(), iArg); // master log file + } + } + continue; + } + case 'u': // unsigned decimal integer + case 'o': // unsigned octal integer + case 'x': // unsigned hexadecimal integer using "abcdef" + case 'X': // unsigned hexadecimal integer using "ABCDEF" + { + // set uiArg as the next value in list and print to console and/or files if flagged + uiArg = va_arg(vaArgList, unsigned int); + if (iLogMode & LOGCONSOLE) + { + szNumWritten = printf(sFormatSpec.c_str(), uiArg); // console + } + if (iLogMode & LOGFILE) + { + szNumWritten = fprintf (pFileStream0, sFormatSpec.c_str(), uiArg); // sample log file + if (iLogMode & MASTER) + { + szNumWritten = fprintf(pFileStream1, sFormatSpec.c_str(), uiArg); // master log file + } + } + continue; + } + case 'f': // float/double + case 'e': // scientific double/float + case 'E': // scientific double/float + case 'g': // scientific double/float + case 'G': // scientific double/float + case 'a': // signed hexadecimal double precision float + case 'A': // signed hexadecimal double precision float + { + // set dArg as the next value in list and print to console and/or files if flagged + dArg = va_arg(vaArgList, double); + if (iLogMode & LOGCONSOLE) + { + szNumWritten = printf(sFormatSpec.c_str(), dArg); // console + } + if (iLogMode & LOGFILE) + { + szNumWritten = fprintf (pFileStream0, sFormatSpec.c_str(), dArg); // sample log file + if (iLogMode & MASTER) + { + szNumWritten = fprintf(pFileStream1, sFormatSpec.c_str(), dArg); // master log file + } + } + continue; + } + default: + { + // print arg of unknown/unsupported type to console and/or file if flagged + if (iLogMode & LOGCONSOLE) // console + { + szNumWritten = putc(*pStr, stdout); + } + if (iLogMode & LOGFILE) + { + szNumWritten = putc(*pStr, pFileStream0); // sample log file + if (iLogMode & MASTER) + { + szNumWritten = putc(*pStr, pFileStream1); // master log file + } + } + } + } + } + } + + // end the sample log with a horizontal line if closing + if (iLogMode & CLOSELOG) + { + if (iLogMode & LOGCONSOLE) + { + printf(HDASHLINE); + } + if (iLogMode & LOGFILE) + { + fprintf(pFileStream0, HDASHLINE); + } + } + + // flush console and/or file buffers if updated + if (iLogMode & LOGCONSOLE) + { + fflush(stdout); + } + if (iLogMode & LOGFILE) + { + fflush (pFileStream0); + + // if the master log file has been updated, flush it too + if (iLogMode & MASTER) + { + fflush (pFileStream1); + } + } + + // If the log file is open and the caller requests "close file", then close and NULL file handle + if ((pFileStream0) && (iLogMode & CLOSELOG)) + { + fclose (pFileStream0); + pFileStream0 = NULL; + } + if ((pFileStream1) && (iLogMode & CLOSELOG)) + { + fclose (pFileStream1); + pFileStream1 = NULL; + } + + // return error code or OK + if (iLogMode & ERRORMSG) + { + return iErrNum; + } + else + { + return 0; + } +} + +// Function to log standardized information to console, file or both +// ********************************************************************* +int shrLogEx(int iLogMode = LOGCONSOLE, int iErrNum = 0, const char* cFormatString = "", ...) +{ + va_list vaArgList; + + // Prepare variable agument list + va_start(vaArgList, cFormatString); + int ret = shrLogV(iLogMode, iErrNum, cFormatString, vaArgList); + + // end variable argument handler + va_end(vaArgList); + + return ret; +} + +// Function to log standardized information to console, file or both +// ********************************************************************* +int shrLog(const char* cFormatString = "", ...) +{ + va_list vaArgList; + + // Prepare variable agument list + va_start(vaArgList, cFormatString); + int ret = shrLogV(LOGBOTH, 0, cFormatString, vaArgList); + + // end variable argument handler + va_end(vaArgList); + + return ret; +} + +////////////////////////////////////////////////////////////////////////////// +//! Find the path for a file assuming that +//! files are found in the searchPath. +//! +//! @return the path if succeeded, otherwise 0 +//! @param filename name of the file +//! @param executable_path optional absolute path of the executable +////////////////////////////////////////////////////////////////////////////// +char* shrFindFilePath(const char* filename, const char* executable_path) +{ + // defines a variable that is replaced with the name of the executable + + // Typical relative search paths to locate needed companion files (e.g. sample input data, or JIT source files) + // The origin for the relative search may be the .exe file, a .bat file launching an .exe, a browser .exe launching the .exe or .bat, etc + const char* searchPath[] = + { + "./", // same dir + "./data/", // "/data/" subdir + "./src/", // "/src/" subdir + "./src//data/", // "/src//data/" subdir + "./inc/", // "/inc/" subdir + "../", // up 1 in tree + "../data/", // up 1 in tree, "/data/" subdir + "../src/", // up 1 in tree, "/src/" subdir + "../inc/", // up 1 in tree, "/inc/" subdir + "../OpenCL/src//", // up 1 in tree, "/OpenCL/src//" subdir + "../OpenCL/src//data/", // up 1 in tree, "/OpenCL/src//data/" subdir + "../OpenCL/src//src/", // up 1 in tree, "/OpenCL/src//src/" subdir + "../OpenCL/src//inc/", // up 1 in tree, "/OpenCL/src//inc/" subdir + "../C/src//", // up 1 in tree, "/C/src//" subdir + "../C/src//data/", // up 1 in tree, "/C/src//data/" subdir + "../C/src//src/", // up 1 in tree, "/C/src//src/" subdir + "../C/src//inc/", // up 1 in tree, "/C/src//inc/" subdir + "../DirectCompute/src//", // up 1 in tree, "/DirectCompute/src//" subdir + "../DirectCompute/src//data/", // up 1 in tree, "/DirectCompute/src//data/" subdir + "../DirectCompute/src//src/", // up 1 in tree, "/DirectCompute/src//src/" subdir + "../DirectCompute/src//inc/", // up 1 in tree, "/DirectCompute/src//inc/" subdir + "../../", // up 2 in tree + "../../data/", // up 2 in tree, "/data/" subdir + "../../src/", // up 2 in tree, "/src/" subdir + "../../inc/", // up 2 in tree, "/inc/" subdir + "../../../", // up 3 in tree + "../../../src//", // up 3 in tree, "/src//" subdir + "../../../src//data/", // up 3 in tree, "/src//data/" subdir + "../../../src//src/", // up 3 in tree, "/src//src/" subdir + "../../../src//inc/", // up 3 in tree, "/src//inc/" subdir + "../../../sandbox//", // up 3 in tree, "/sandbox//" subdir + "../../../sandbox//data/", // up 3 in tree, "/sandbox//data/" subdir + "../../../sandbox//src/", // up 3 in tree, "/sandbox//src/" subdir + "../../../sandbox//inc/" // up 3 in tree, "/sandbox//inc/" subdir + }; + + // Extract the executable name + std::string executable_name; + if (executable_path != 0) + { + executable_name = std::string(executable_path); + + #ifdef _WIN32 + // Windows path delimiter + size_t delimiter_pos = executable_name.find_last_of('\\'); + executable_name.erase(0, delimiter_pos + 1); + + if (executable_name.rfind(".exe") != string::npos) + { + // we strip .exe, only if the .exe is found + executable_name.resize(executable_name.size() - 4); + } + #else + // Linux & OSX path delimiter + size_t delimiter_pos = executable_name.find_last_of('/'); + executable_name.erase(0,delimiter_pos+1); + #endif + + } + + // Loop over all search paths and return the first hit + for( unsigned int i = 0; i < sizeof(searchPath)/sizeof(char*); ++i ) + { + std::string path(searchPath[i]); + size_t executable_name_pos = path.find(""); + + // If there is executable_name variable in the searchPath + // replace it with the value + if(executable_name_pos != std::string::npos) + { + if(executable_path != 0) + { + path.replace(executable_name_pos, strlen(""), executable_name); + + } + else + { + // Skip this path entry if no executable argument is given + continue; + } + } + + // Test if the file exists + path.append(filename); + std::fstream fh(path.c_str(), std::fstream::in); + if (fh.good()) + { + // File found + // returning an allocated array here for backwards compatibility reasons + char* file_path = (char*) malloc(path.length() + 1); + #ifdef _WIN32 + strcpy_s(file_path, path.length() + 1, path.c_str()); + #else + strcpy(file_path, path.c_str()); + #endif + return file_path; + } + } + + // File not found + return 0; +} + +////////////////////////////////////////////////////////////////////////////// +//! Read file \filename and return the data +//! @return shrTRUE if reading the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +////////////////////////////////////////////////////////////////////////////// +template +shrBOOL +shrReadFile( const char* filename, T** data, unsigned int* len, bool verbose) +{ + // check input arguments + ARGCHECK(NULL != filename); + ARGCHECK(NULL != len); + + // intermediate storage for the data read + std::vector data_read; + + // open file for reading + std::fstream fh( filename, std::fstream::in); + // check if filestream is valid + if(!fh.good()) + { + if (verbose) + std::cerr << "shrReadFile() : Opening file failed." << std::endl; + return shrFALSE; + } + + // read all data elements + T token; + while( fh.good()) + { + fh >> token; + data_read.push_back( token); + } + + // the last element is read twice + data_read.pop_back(); + + // check if reading result is consistent + if( ! fh.eof()) + { + if (verbose) + std::cerr << "WARNING : readData() : reading file might have failed." + << std::endl; + } + + fh.close(); + + // check if the given handle is already initialized + if( NULL != *data) + { + if( *len != data_read.size()) + { + std::cerr << "shrReadFile() : Initialized memory given but " + << "size mismatch with signal read " + << "(data read / data init = " << (unsigned int)data_read.size() + << " / " << *len << ")" << std::endl; + + return shrFALSE; + } + } + else + { + // allocate storage for the data read + *data = (T*) malloc( sizeof(T) * data_read.size()); + // store signal size + *len = static_cast( data_read.size()); + } + + // copy data + memcpy( *data, &data_read.front(), sizeof(T) * data_read.size()); + + return shrTRUE; +} + +////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename +//! @return shrTRUE if writing the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +////////////////////////////////////////////////////////////////////////////// +template +shrBOOL +shrWriteFile( const char* filename, const T* data, unsigned int len, + const T epsilon, bool verbose) +{ + ARGCHECK(NULL != filename); + ARGCHECK(NULL != data); + + // open file for writing + std::fstream fh( filename, std::fstream::out); + // check if filestream is valid + if(!fh.good()) + { + if (verbose) + std::cerr << "shrWriteFile() : Opening file failed." << std::endl; + return shrFALSE; + } + + // first write epsilon + fh << "# " << epsilon << "\n"; + + // write data + for( unsigned int i = 0; (i < len) && (fh.good()); ++i) + { + fh << data[i] << ' '; + } + + // Check if writing succeeded + if( ! fh.good()) + { + if (verbose) + std::cerr << "shrWriteFile() : Writing file failed." << std::endl; + return shrFALSE; + } + + // file ends with nl + fh << std::endl; + + return shrTRUE; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Read file \filename containg single precision floating point data +//! @return shrTRUEif reading the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrReadFilef( const char* filename, float** data, unsigned int* len, bool verbose) +{ + return shrReadFile( filename, data, len, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Read file \filename containg double precision floating point data +//! @return shrTRUEif reading the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrReadFiled( const char* filename, double** data, unsigned int* len, bool verbose) +{ + return shrReadFile( filename, data, len, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Read file \filename containg integer data +//! @return shrTRUEif reading the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrReadFilei( const char* filename, int** data, unsigned int* len, bool verbose) +{ + return shrReadFile( filename, data, len, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Read file \filename containg unsigned integer data +//! @return shrTRUEif reading the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrReadFileui( const char* filename, unsigned int** data, unsigned int* len, bool verbose) +{ + return shrReadFile( filename, data, len, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Read file \filename containg char / byte data +//! @return shrTRUEif reading the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrReadFileb( const char* filename, char** data, unsigned int* len, bool verbose) +{ + return shrReadFile( filename, data, len, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Read file \filename containg unsigned char / byte data +//! @return shrTRUEif reading the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data uninitialized pointer, returned initialized and pointing to +//! the data read +//! @param len number of data elements in data, -1 on error +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrReadFileub( const char* filename, unsigned char** data, unsigned int* len, bool verbose) +{ + return shrReadFile( filename, data, len, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for single precision floating point data +//! @return shrTRUEif writing the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrWriteFilef( const char* filename, const float* data, unsigned int len, + const float epsilon, bool verbose) +{ + return shrWriteFile( filename, data, len, epsilon, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for double precision floating point data +//! @return shrTRUEif writing the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrWriteFiled( const char* filename, const double* data, unsigned int len, + const double epsilon, bool verbose) +{ + return shrWriteFile( filename, data, len, epsilon, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for integer data +//! @return shrTRUEif writing the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrWriteFilei( const char* filename, const int* data, unsigned int len, bool verbose) +{ + return shrWriteFile( filename, data, len, 0, verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for unsigned integer data +//! @return shrTRUEif writing the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrWriteFileui( const char* filename,const unsigned int* data,unsigned int len, bool verbose) +{ + return shrWriteFile( filename, data, len, static_cast(0), verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for byte / char data +//! @return shrTRUEif writing the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrWriteFileb( const char* filename, const char* data, unsigned int len, bool verbose) +{ + return shrWriteFile( filename, data, len, static_cast(0), verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for byte / char data +//! @return shrTRUEif writing the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrWriteFileub( const char* filename, const unsigned char* data, + unsigned int len, bool verbose) +{ + return shrWriteFile( filename, data, len, static_cast(0), verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Write a data file \filename for unsigned byte / char data +//! @return shrTRUEif writing the file succeeded, otherwise shrFALSE +//! @param filename name of the source file +//! @param data data to write +//! @param len number of data elements in data, -1 on error +//! @param epsilon epsilon for comparison +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrWriteFileb( const char* filename,const unsigned char* data,unsigned int len, bool verbose) +{ + return shrWriteFile( filename, data, len, static_cast(0), verbose); +} + +////////////////////////////////////////////////////////////////////////////// +//! Load PGM or PPM file +//! @note if data == NULL then the necessary memory is allocated in the +//! function and w and h are initialized to the size of the image +//! @return shrTRUE if the file loading succeeded, otherwise shrFALSE +//! @param file name of the file to load +//! @param data handle to the memory for the image file data +//! @param w width of the image +//! @param h height of the image +//! @param channels number of channels in image +////////////////////////////////////////////////////////////////////////////// +shrBOOL loadPPM(const char* file, unsigned char** data, + unsigned int *w, unsigned int *h, unsigned int *channels) +{ + FILE* fp = 0; + + #ifdef _WIN32 + // open the file for binary read + errno_t err; + if ((err = fopen_s(&fp, file, "rb")) != 0) + #else + // open the file for binary read + if ((fp = fopen(file, "rb")) == 0) + #endif + { + // if error on attempt to open, be sure the file is null or close it, then return negative error code + if (fp) + { + fclose (fp); + } + std::cerr << "loadPPM() : Failed to open file: " << file << std::endl; + return shrFALSE; + } + + // check header + char header[PGMHeaderSize]; + if ((fgets( header, PGMHeaderSize, fp) == NULL) && ferror(fp)) + { + if (fp) + { + fclose (fp); + } + std::cerr << "loadPPM() : File is not a valid PPM or PGM image" << std::endl; + *channels = 0; + return shrFALSE; + } + + if (strncmp(header, "P5", 2) == 0) + { + *channels = 1; + } + else if (strncmp(header, "P6", 2) == 0) + { + *channels = 3; + } + else + { + std::cerr << "loadPPM() : File is not a PPM or PGM image" << std::endl; + *channels = 0; + return shrFALSE; + } + + // parse header, read maxval, width and height + unsigned int width = 0; + unsigned int height = 0; + unsigned int maxval = 0; + unsigned int i = 0; + while(i < 3) + { + if ((fgets(header, PGMHeaderSize, fp) == NULL) && ferror(fp)) + { + if (fp) + { + fclose (fp); + } + std::cerr << "loadPPM() : File is not a valid PPM or PGM image" << std::endl; + return shrFALSE; + } + if(header[0] == '#') continue; + + #ifdef _WIN32 + if(i == 0) + { + i += sscanf_s(header, "%u %u %u", &width, &height, &maxval); + } + else if (i == 1) + { + i += sscanf_s(header, "%u %u", &height, &maxval); + } + else if (i == 2) + { + i += sscanf_s(header, "%u", &maxval); + } + #else + if(i == 0) + { + i += sscanf(header, "%u %u %u", &width, &height, &maxval); + } + else if (i == 1) + { + i += sscanf(header, "%u %u", &height, &maxval); + } + else if (i == 2) + { + i += sscanf(header, "%u", &maxval); + } + #endif + } + + // check if given handle for the data is initialized + if(NULL != *data) + { + if (*w != width || *h != height) + { + fclose(fp); + std::cerr << "loadPPM() : Invalid image dimensions." << std::endl; + return shrFALSE; + } + } + else + { + *data = (unsigned char*)malloc( sizeof(unsigned char) * width * height * *channels); + *w = width; + *h = height; + } + + // read and close file + if (fread(*data, sizeof(unsigned char), width * height * *channels, fp) != width * height * *channels) + { + fclose(fp); + std::cerr << "loadPPM() : Invalid image." << std::endl; + return shrFALSE; + } + fclose(fp); + + return shrTRUE; +} + +////////////////////////////////////////////////////////////////////////////// +//! Write / Save PPM or PGM file +//! @note Internal usage only +//! @param file name of the image file +//! @param data handle to the data read +//! @param w width of the image +//! @param h height of the image +////////////////////////////////////////////////////////////////////////////// +shrBOOL savePPM( const char* file, unsigned char *data, + unsigned int w, unsigned int h, unsigned int channels) +{ + ARGCHECK(NULL != data); + ARGCHECK(w > 0); + ARGCHECK(h > 0); + + std::fstream fh( file, std::fstream::out | std::fstream::binary ); + if( fh.bad()) + { + std::cerr << "savePPM() : Opening file failed." << std::endl; + return shrFALSE; + } + + if (channels == 1) + { + fh << "P5\n"; + } + else if (channels == 3) { + fh << "P6\n"; + } + else { + std::cerr << "savePPM() : Invalid number of channels." << std::endl; + return shrFALSE; + } + + fh << w << "\n" << h << "\n" << 0xff << std::endl; + + for( unsigned int i = 0; (i < (w*h*channels)) && fh.good(); ++i) + { + fh << data[i]; + } + fh.flush(); + + if( fh.bad()) + { + std::cerr << "savePPM() : Writing data failed." << std::endl; + return shrFALSE; + } + fh.close(); + + return shrTRUE; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Load PPM image file (with unsigned char as data element type), padding 4th component +//! @return shrTrue if reading the file succeeded, otherwise shrFALSE +//! @param file name of the image file +//! @param data handle to the data read +//! @param w width of the image +//! @param h height of the image +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrLoadPPM4ub( const char* file, unsigned char** OutData, + unsigned int *w, unsigned int *h) +{ + // Load file data into a temporary buffer with automatic allocation + unsigned char* cLocalData = 0; + unsigned int channels; + shrBOOL bLoadOK = loadPPM(file, &cLocalData, w, h, &channels); // this allocates cLocalData, which must be freed later + + // If the data loaded OK from file to temporary buffer, then go ahead with padding and transfer + if (shrTRUE == bLoadOK) + { + // if the receiving buffer is null, allocate it... caller must free this + int size = *w * *h; + if (*OutData == NULL) + { + *OutData = (unsigned char*)malloc(sizeof(unsigned char) * size * 4); + } + + // temp pointers for incrementing + unsigned char* cTemp = cLocalData; + unsigned char* cOutPtr = *OutData; + + // transfer data, padding 4th element + for(int i=0; i( arg_name); + if( NULL != v) + { + // assign value + *val = *v; + ret_val = shrTRUE; + } + else { + // fail safe + val = NULL; + } + } + catch( const std::exception& /*ex*/) + { + std::cerr << "Error when parsing command line argument string." << std::endl; + } + + return ret_val; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Get the value of a command line argument of type unsigned int +//! @return shrTRUE if command line argument \a arg_name has been given and +//! is of the requested type, otherwise shrFALSE +//! @param argc argc as passed to main() +//! @param argv argv as passed to main() +//! @param arg_name name of the command line argument +//! @param val value of the command line argument +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrGetCmdLineArgumentu( const int argc, const char** argv, + const char* arg_name, unsigned int* val) +{ + shrBOOL ret_val = shrFALSE; + + try + { + // initialize + CmdArgReader::init( argc, argv); + + // access argument + const int* v = CmdArgReader::getArg( arg_name); + if( NULL != v) + { + // assign value + *val = *v; + ret_val = shrTRUE; + } + else { + // fail safe + val = NULL; + } + } + catch( const std::exception& /*ex*/) + { + std::cerr << "Error when parsing command line argument string." << std::endl; + } + + return ret_val; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Get the value of a command line argument of type float +//! @return shrTRUE if command line argument \a arg_name has been given and +//! is of the requested type, otherwise shrFALSE +//! @param argc argc as passed to main() +//! @param argv argv as passed to main() +//! @param arg_name name of the command line argument +//! @param val value of the command line argument +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrGetCmdLineArgumentf( const int argc, const char** argv, + const char* arg_name, float* val) +{ + shrBOOL ret_val = shrFALSE; + + try + { + // initialize + CmdArgReader::init( argc, argv); + + // access argument + const float* v = CmdArgReader::getArg( arg_name); + if( NULL != v) + { + // assign value + *val = *v; + ret_val = shrTRUE; + } + else { + // fail safe + val = NULL; + } + } + catch( const std::exception& /*ex*/) + { + std::cerr << "Error when parsing command line argument string." << std::endl; + } + + return ret_val; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Get the value of a command line argument of type string +//! @return shrTRUE if command line argument \a arg_name has been given and +//! is of the requested type, otherwise shrFALSE +//! @param argc argc as passed to main() +//! @param argv argv as passed to main() +//! @param arg_name name of the command line argument +//! @param val value of the command line argument +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrGetCmdLineArgumentstr( const int argc, const char** argv, + const char* arg_name, char** val) +{ + shrBOOL ret_val = shrFALSE; + + try + { + // initialize + CmdArgReader::init( argc, argv); + + // access argument + const std::string* v = CmdArgReader::getArg( arg_name); + if( NULL != v) + { + + // allocate memory for the string + *val = (char*)malloc(sizeof(char) * (v->length() + 1)); + + // copy from string to c_str + #ifdef WIN32 + strcpy_s(*val, v->length() + 1, v->c_str()); + #else + strcpy(*val, v->c_str()); + #endif + ret_val = shrTRUE; + } + else { + // fail safe + *val = NULL; + } + } + catch( const std::exception& /*ex*/) + { + std::cerr << "Error when parsing command line argument string."<< + std::endl; + } + + return ret_val; + +} + +////////////////////////////////////////////////////////////////////////////// +//! Compare two arrays of arbitrary type +//! @return shrTRUE if \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +////////////////////////////////////////////////////////////////////////////// +template +shrBOOL +compareData( const T* reference, const T* data, const unsigned int len, + const S epsilon, const float threshold) +{ + ARGCHECK( epsilon >= 0); + + bool result = true; + unsigned int error_count = 0; + + for( unsigned int i = 0; i < len; ++i) { + + T diff = reference[i] - data[i]; + bool comp = (diff <= epsilon) && (diff >= -epsilon); + result &= comp; + + error_count += !comp; + +#ifdef _DEBUG + if( ! comp) + { + std::cerr << "ERROR, i = " << i << ",\t " + << reference[i] << " / " + << data[i] + << " (reference / data)\n"; + } +#endif + } + + if (threshold == 0.0f) { + return (result) ? shrTRUE : shrFALSE; + } else { + return (len*threshold > error_count) ? shrTRUE : shrFALSE; + } +} + +////////////////////////////////////////////////////////////////////////////// +//! Compare two arrays of arbitrary type +//! @return shrTRUE if \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +////////////////////////////////////////////////////////////////////////////// +template +shrBOOL +compareDataAsFloat( const T* reference, const T* data, const unsigned int len, + const S epsilon) +{ + ARGCHECK(epsilon >= 0); + + // If we set epsilon to be 0, let's set a minimum threshold + float max_error = MAX( (float)epsilon, MIN_EPSILON_ERROR ); + int error_count = 0; + bool result = true; + + for( unsigned int i = 0; i < len; ++i) { + float diff = fabs((float)reference[i] - (float)data[i]); + bool comp = (diff < max_error); + result &= comp; + + if( ! comp) + { + error_count++; +#ifdef _DEBUG + if (error_count < 50) { + shrLog("\n ERROR(epsilon=%4.3f), i=%d, (ref)0x%02x / (data)0x%02x / (diff)%d\n", max_error, i, reference[i], data[i], (unsigned int)diff); + } +#endif + } + } + if (error_count) { + shrLog("\n Total # of errors = %d\n", error_count); + } + return (error_count == 0) ? shrTRUE : shrFALSE; +} + +////////////////////////////////////////////////////////////////////////////// +//! Compare two arrays of arbitrary type +//! @return shrTRUE if \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +//! @param epsilon threshold % of (# of bytes) for pass/fail +////////////////////////////////////////////////////////////////////////////// +template +shrBOOL +compareDataAsFloatThreshold( const T* reference, const T* data, const unsigned int len, + const S epsilon, const float threshold) +{ + ARGCHECK(epsilon >= 0); + + // If we set epsilon to be 0, let's set a minimum threshold + float max_error = MAX( (float)epsilon, MIN_EPSILON_ERROR); + int error_count = 0; + bool result = true; + + for( unsigned int i = 0; i < len; ++i) { + float diff = fabs((float)reference[i] - (float)data[i]); + bool comp = (diff < max_error); + result &= comp; + + if( ! comp) + { + error_count++; +#ifdef _DEBUG + if (error_count < 50) { + shrLog("\n ERROR(epsilon=%4.3f), i=%d, (ref)0x%02x / (data)0x%02x / (diff)%d\n", max_error, i, reference[i], data[i], (unsigned int)diff); + } +#endif + } + } + + if (threshold == 0.0f) { + if (error_count) { + shrLog("\n Total # of errors = %d\n", error_count); + } + return (error_count == 0) ? shrTRUE : shrFALSE; + } else { + + if (error_count) { + shrLog("\n %.2f(%%) of bytes mismatched (count=%d)\n", (float)error_count*100/(float)len, error_count); + } + + return ((len*threshold > error_count) ? shrTRUE : shrFALSE); + } +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two float arrays +//! @return shrTRUE if \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrComparef( const float* reference, const float* data, + const unsigned int len ) +{ + const float epsilon = 0.0; + return compareData( reference, data, len, epsilon, 0.0f ); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two integer arrays +//! @return shrTRUE if \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrComparei( const int* reference, const int* data, + const unsigned int len ) +{ + const int epsilon = 0; + return compareData( reference, data, len, epsilon, 0.0f); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two unsigned integer arrays, with epsilon and threshold +//! @return shrTRUE if \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrCompareuit( const unsigned int* reference, const unsigned int* data, + const unsigned int len, const float epsilon, const float threshold ) +{ + return compareDataAsFloatThreshold( reference, data, len, epsilon, threshold ); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two integer arrays +//! @return shrTRUE if \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrCompareub( const unsigned char* reference, const unsigned char* data, + const unsigned int len ) +{ + const int epsilon = 0; + return compareData( reference, data, len, epsilon, 0.0f); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two integer arrays (inc Threshold for # of pixel we can have errors) +//! @return shrTRUE if \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrCompareubt( const unsigned char* reference, const unsigned char* data, + const unsigned int len, const float epsilon, const float threshold ) +{ + return compareDataAsFloatThreshold( reference, data, len, epsilon, threshold ); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two integer arrays +//! @return shrTRUE if \a reference and \a data are identical, +//! otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrCompareube( const unsigned char* reference, const unsigned char* data, + const unsigned int len, const float epsilon ) +{ + return compareDataAsFloat( reference, data, len, epsilon ); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two float arrays with an epsilon tolerance for equality +//! @return shrTRUE if \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrComparefe( const float* reference, const float* data, + const unsigned int len, const float epsilon ) +{ + return compareData( reference, data, len, epsilon, 0.0f); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two float arrays with an epsilon tolerance for equality and a +//! threshold for # pixel errors +//! @return shrTRUE if \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrComparefet( const float* reference, const float* data, + const unsigned int len, const float epsilon, const float threshold ) +{ + return compareDataAsFloatThreshold( reference, data, len, epsilon, threshold ); +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two float arrays using L2-norm with an epsilon tolerance for equality +//! @return shrTRUE if \a reference and \a data are identical, otherwise shrFALSE +//! @param reference handle to the reference data / gold image +//! @param data handle to the computed data +//! @param len number of elements in reference and data +//! @param epsilon epsilon to use for the comparison +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrCompareL2fe( const float* reference, const float* data, + const unsigned int len, const float epsilon ) +{ + ARGCHECK(epsilon >= 0); + + float error = 0; + float ref = 0; + + for( unsigned int i = 0; i < len; ++i) { + + float diff = reference[i] - data[i]; + error += diff * diff; + ref += reference[i] * reference[i]; + } + + float normRef = sqrtf(ref); + if (fabs(ref) < 1e-7) { +#ifdef _DEBUG + std::cerr << "ERROR, reference l2-norm is 0\n"; +#endif + return shrFALSE; + } + float normError = sqrtf(error); + error = normError / normRef; + bool result = error < epsilon; +#ifdef _DEBUG + if( ! result) + { + std::cerr << "ERROR, l2-norm error " + << error << " is greater than epsilon " << epsilon << "\n"; + } +#endif + + return result ? shrTRUE : shrFALSE; +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two PPM image files with an epsilon tolerance for equality +//! @return shrTRUE if \a reference and \a data are identical, otherwise shrFALSE +//! @param src_file filename for the image to be compared +//! @param data filename for the reference data / gold image +//! @param epsilon epsilon to use for the comparison +//! @param threshold threshold of pixels that can still mismatch to pass (i.e. 0.15f = 15% must pass) +//! @param verboseErrors output details of image mismatch to std::cerr +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrComparePPM( const char *src_file, const char *ref_file, const float epsilon, const float threshold) +{ + unsigned char* src_data = NULL; + unsigned char* ref_data = NULL; + unsigned long error_count = 0; + unsigned int ref_width, ref_height; + unsigned int src_width, src_height; + + // Check sample and reference file pointers + if (src_file == NULL || ref_file == NULL) { + shrLog("\n> shrComparePGM: src_file or ref_file is NULL\n Aborting comparison !!!\n\n"); + return shrFALSE; + } + shrLog("\n> shrComparePPM:\n (a)rendered: <%s>\n (b)reference: <%s>\n", src_file, ref_file); + + // Load the ref image file + if (shrLoadPPM4ub(ref_file, &ref_data, &ref_width, &ref_height) != shrTRUE) + { + shrLog("\n Unable to load ref image file: %s\n Aborting comparison !!!\n\n", ref_file); + return shrFALSE; + } + + // Load the sample image file + if (shrLoadPPM4ub(src_file, &src_data, &src_width, &src_height) != shrTRUE) + { + shrLog("\n Unable to load src image file: %s\n Aborting comparison !!!\n\n", src_file); + return shrFALSE; + } + + // check to see if image dimensions match + if(src_height != ref_height || src_width != ref_width) + { + shrLog("\n Source and ref size mismatch (%u x %u) vs (%u x %u)\n Aborting Comparison !!!\n\n ", + src_width, src_height, ref_width, ref_height); + return shrFALSE; + } + + // compare the images + if (shrCompareubt(ref_data, src_data, src_width*src_height*4, epsilon, threshold ) == shrFALSE) + { + error_count=1; + } + + shrLog(" Images %s\n\n", (error_count == 0) ? "Match" : "Don't Match !!!"); + return (error_count == 0) ? shrTRUE : shrFALSE; // returns true if all pixels pass +} + +//////////////////////////////////////////////////////////////////////////////// +//! Compare two PGM image files with an epsilon tolerance for equality +//! @return shrTRUE if \a reference and \a data are identical, otherwise shrFALSE +//! @param src_file filename for the image to be compared +//! @param data filename for the reference data / gold image +//! @param epsilon epsilon to use for the comparison +//! @param threshold threshold of pixels that can still mismatch to pass (i.e. 0.15f = 15% must pass) +//////////////////////////////////////////////////////////////////////////////// +shrBOOL shrComparePGM( const char *src_file, const char *ref_file, const float epsilon, const float threshold) +{ + unsigned char* src_data = NULL; + unsigned char* ref_data = NULL; + unsigned long error_count = 0; + unsigned int ref_width, ref_height; + unsigned int src_width, src_height; + + // Check sample and reference file pointers + if (src_file == NULL || ref_file == NULL) { + shrLog("\n> shrComparePGM: src_file or ref_file is NULL\n Aborting comparison !!!\n\n"); + return shrFALSE; + } + shrLog("\n> shrComparePGM:\n (a)rendered: <%s>\n (b)reference: <%s>\n", src_file, ref_file); + + // Load the ref image file + if (shrLoadPPM4ub(ref_file, &ref_data, &ref_width, &ref_height) != shrTRUE) + { + shrLog("\n Unable to load ref image file: %s\n Aborting comparison !!!\n\n", ref_file); + return shrFALSE; + } + + // Load the sample image file + if (shrLoadPPM4ub(src_file, &src_data, &src_width, &src_height) != shrTRUE) + { + shrLog("\n Unable to load src image file: %s\n Aborting comparison !!!\n\n", src_file); + return shrFALSE; + } + + // check to see if image dimensions match + if(src_height != ref_height || src_width != ref_width) + { + shrLog("\n Source and ref size mismatch (%u x %u) vs (%u x %u)\n Aborting Comparison !!!\n\n ", + src_width, src_height, ref_width, ref_height); + return shrFALSE; + } + + // compare the images + if (shrCompareubt(ref_data, src_data, src_width*src_height*4, epsilon, threshold ) == shrFALSE) + { + error_count=1; + } + + shrLog(" Images %s\n\n", (error_count == 0) ? "Match" : "Don't Match !!!"); + return (error_count == 0) ? shrTRUE : shrFALSE; // returns true if all pixels pass +} + +// Load raw data from disk +unsigned char* shrLoadRawFile(const char* filename, size_t size) +{ + FILE *fp = NULL; + #ifdef WIN32 + errno_t err; + if ((err = fopen_s(&fp, filename, "rb")) != 0) + #else + if ((fp = fopen(filename, "rb")) == NULL) + #endif + { + shrLog(" Error opening file '%s' !!!\n", filename); + return 0; + } + + unsigned char* data = (unsigned char*)malloc(size); + size_t read = fread(data, 1, size, fp); + fclose(fp); + + shrLog(" Read '%s', %d bytes\n", filename, read); + + return data; +} + +// Round Up Division function +size_t shrRoundUp(int group_size, int global_size) +{ + int r = global_size % group_size; + if(r == 0) + { + return global_size; + } else + { + return global_size + group_size - r; + } +} diff --git a/src/cuda/common/sdk-compat/src/stopwatch.cpp b/src/cuda/common/sdk-compat/src/stopwatch.cpp new file mode 100644 index 000000000..634016777 --- /dev/null +++ b/src/cuda/common/sdk-compat/src/stopwatch.cpp @@ -0,0 +1,110 @@ +/* + * Copyright 1993-2010 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + +/* CUda UTility Library */ + +#include + +// includes, file +#include + +// includes, project +#include + +//////////////////////////////////////////////////////////////////////////////// +// static variables + +//! global index for all stop watches +#ifdef _WIN32 +/*static*/ std::vector< StopWatchC* > StopWatchC::swatches; +#else +template +/*static*/ std::vector< StopWatchBase* > +StopWatchBase:: swatches; +#endif + + +// namespace, unnamed +namespace +{ + // convenience typedef + typedef std::vector< StopWatchC* >::size_type swatches_size_type; + + ////////////////////////////////////////////////////////////////////////////// + //! Translate stop watch name to index + ////////////////////////////////////////////////////////////////////////////// + swatches_size_type + nameToIndex( const unsigned int& name) + { + +#ifdef _DEBUG + const swatches_size_type pos = name - 1; + if( (pos >= StopWatchC::swatches.size()) + || ( NULL == StopWatchC::swatches[pos])) + { + RUNTIME_EXCEPTION( "No StopWatch with the requested name exist."); + } + + return pos; +#else + return name - 1; +#endif + } + +} // end namespace, unnamed + +// Stop watch +namespace StopWatch +{ + ////////////////////////////////////////////////////////////////////////////// + //! Create a stop watch + ////////////////////////////////////////////////////////////////////////////// + const unsigned int + create() + { + // create new stopwatch + StopWatchC* swatch = new StopWatchC(); + if( NULL == swatch) + { + return 0; + } + + // store new stop watch + StopWatchC::swatches.push_back( swatch); + + // return the handle to the new stop watch + return (unsigned int) StopWatchC::swatches.size(); + } + + ////////////////////////////////////////////////////////////////////////////// + // Get a handle to the stop watch with the name \a name + ////////////////////////////////////////////////////////////////////////////// + StopWatchC& + get( const unsigned int& name) + { + return *(StopWatchC::swatches[nameToIndex( name)]); + } + + ////////////////////////////////////////////////////////////////////////////// + // Delete the stop watch with the name \a name + ////////////////////////////////////////////////////////////////////////////// + void + destroy( const unsigned int& name) + { + // get index into global memory + swatches_size_type pos = nameToIndex( name); + // delete stop watch + delete StopWatchC::swatches[pos]; + // invalidate storage + StopWatchC::swatches[pos] = NULL; + } + +} // end namespace, StopWatch diff --git a/src/cuda/common/sdk-compat/src/stopwatch_linux.cpp b/src/cuda/common/sdk-compat/src/stopwatch_linux.cpp new file mode 100644 index 000000000..1324b1348 --- /dev/null +++ b/src/cuda/common/sdk-compat/src/stopwatch_linux.cpp @@ -0,0 +1,33 @@ +/* + * Copyright 1993-2010 NVIDIA Corporation. All rights reserved. + * + * Please refer to the NVIDIA end user license agreement (EULA) associated + * with this source code for terms and conditions that govern your use of + * this software. Any use, reproduction, disclosure, or distribution of + * this software and related documentation outside the terms of the EULA + * is strictly prohibited. + * + */ + +/* CUda UTility Library */ + +// includes, file +#include + + +//////////////////////////////////////////////////////////////////////////////// +//! Constructor, default +//////////////////////////////////////////////////////////////////////////////// +StopWatchLinux::StopWatchLinux() : + start_time(), + diff_time( 0.0), + total_time(0.0), + running( false), + clock_sessions(0) +{ } + +//////////////////////////////////////////////////////////////////////////////// +// Destructor +//////////////////////////////////////////////////////////////////////////////// +StopWatchLinux::~StopWatchLinux() { } + diff --git a/src/cuda/cub/experimental/defunct/example_coo_spmv.cu b/src/cuda/cub/experimental/defunct/example_coo_spmv.cu index 6b33e1f70..9c0f3c913 100644 --- a/src/cuda/cub/experimental/defunct/example_coo_spmv.cu +++ b/src/cuda/cub/experimental/defunct/example_coo_spmv.cu @@ -870,7 +870,7 @@ void TestDevice( } // Force any kernel stdio to screen - CubDebugExit(cudaThreadSynchronize()); + CubDebugExit(cudaDeviceSynchronize()); fflush(stdout); // Display timing diff --git a/src/cuda/cub/test/test_grid_barrier.cu b/src/cuda/cub/test/test_grid_barrier.cu index e6e3b8125..6c4adb960 100644 --- a/src/cuda/cub/test/test_grid_barrier.cu +++ b/src/cuda/cub/test/test_grid_barrier.cu @@ -139,7 +139,7 @@ int main(int argc, char** argv) Kernel<<>>(global_barrier, iterations); gpu_timer.Stop(); - retval = CubDebug(cudaThreadSynchronize()); + retval = CubDebug(cudaDeviceSynchronize()); // Output timing results float avg_elapsed = gpu_timer.ElapsedMillis() / float(iterations); diff --git a/src/cuda/cuda-samples b/src/cuda/cuda-samples index db3eea239..a4526d522 160000 --- a/src/cuda/cuda-samples +++ b/src/cuda/cuda-samples @@ -1 +1 @@ -Subproject commit db3eea23946bca2e90a75eca2b5b3e07158a9e11 +Subproject commit a4526d52290b667cbc46b4a9830fbaad35be1ec2 diff --git a/src/cuda/cudnn/mnist/Makefile b/src/cuda/cudnn/mnist/Makefile index d21dd80ee..85fa71ac7 100644 --- a/src/cuda/cudnn/mnist/Makefile +++ b/src/cuda/cudnn/mnist/Makefile @@ -146,8 +146,10 @@ LIBRARIES := ################################################################################ # Gencode arguments -GENCODE_FLAGS= -SMS = 70 +# Let the environment (setup_environment) supply the arch list; SMS is only a +# fallback. sm_70 was removed in CUDA 13. +GENCODE_FLAGS ?= +SMS ?= 75 ifeq ($(SMS),) $(info >>> WARNING - no SM architectures have been specified - waiving sample <<<) diff --git a/src/cuda/cudnn/mnist/error_util.h b/src/cuda/cudnn/mnist/error_util.h index 71527216e..0632b0fd2 100644 --- a/src/cuda/cudnn/mnist/error_util.h +++ b/src/cuda/cudnn/mnist/error_util.h @@ -95,11 +95,15 @@ static void showDevices( void ) for (int i=0; i< totalDevices; i++) { struct cudaDeviceProp prop; checkCudaErrors(cudaGetDeviceProperties( &prop, i )); + // clockRate/memoryClockRate were removed from cudaDeviceProp in CUDA 13 + int smClock = 0, memClock = 0; + cudaDeviceGetAttribute(&smClock, cudaDevAttrClockRate, i); + cudaDeviceGetAttribute(&memClock, cudaDevAttrMemoryClockRate, i); printf( "device %d : sms %2d Capabilities %d.%d, SmClock %.1f Mhz, MemSize (Mb) %d, MemClock %.1f Mhz, Ecc=%d, boardGroupID=%d\n", i, prop.multiProcessorCount, prop.major, prop.minor, - (float)prop.clockRate*1e-3, + (float)smClock*1e-3, (int)(prop.totalGlobalMem/(1024*1024)), - (float)prop.memoryClockRate*1e-3, + (float)memClock*1e-3, prop.ECCEnabled, prop.multiGpuBoardGroupID); } diff --git a/src/cuda/cudnn/mnist/mnistCUDNN.cpp b/src/cuda/cudnn/mnist/mnistCUDNN.cpp index ebe985df1..72c6e8024 100644 --- a/src/cuda/cudnn/mnist/mnistCUDNN.cpp +++ b/src/cuda/cudnn/mnist/mnistCUDNN.cpp @@ -124,7 +124,7 @@ void readAllocMemcpy(const char* fname, int size, value_type** data_h, value_typ readBinaryFile(fname, size, *data_h); int size_b = size*sizeof(value_type); - checkCudaErrors( cudaMalloc(data_d, size_b) ); + checkCudaErrors( cudaMalloc((void**)data_d, size_b) ); checkCudaErrors( cudaMemcpy(*data_d, *data_h, size_b, cudaMemcpyHostToDevice) ); @@ -281,7 +281,7 @@ void Layer_t::readAllocInit(const char* fname, int size, half1** data_h, { *data_h = new half1[size]; int size_b = size*sizeof(half1); - checkCudaErrors( cudaMalloc(data_d, size_b) ); + checkCudaErrors( cudaMalloc((void**)data_d, size_b) ); float *data_tmp_h, *data_tmp_d; switch(fp16Import) @@ -441,7 +441,7 @@ class network_t { checkCudaErrors( cudaFree(*data) ); } - checkCudaErrors( cudaMalloc(data, size*sizeof(value_type)) ); + checkCudaErrors( cudaMalloc((void**)data, size*sizeof(value_type)) ); } void setConvolutionAlgorithm(const cudnnConvolutionFwdAlgo_t& algo) { @@ -578,7 +578,7 @@ class network_t &sizeInBytes) ); if (sizeInBytes!=0) { - checkCudaErrors( cudaMalloc(&workSpace,sizeInBytes) ); + checkCudaErrors( cudaMalloc((void**)&workSpace,sizeInBytes) ); } scaling_type alpha = scaling_type(1); scaling_type beta = scaling_type(0); @@ -726,7 +726,7 @@ class network_t std::cout << "Performing forward propagation ...\n"; - checkCudaErrors( cudaMalloc(&srcData, IMAGE_H*IMAGE_W*sizeof(value_type)) ); + checkCudaErrors( cudaMalloc((void**)&srcData, IMAGE_H*IMAGE_W*sizeof(value_type)) ); checkCudaErrors( cudaMemcpy(srcData, imgData_h, IMAGE_H*IMAGE_W*sizeof(value_type), cudaMemcpyHostToDevice) ); diff --git a/src/cuda/custom-apps/rodinia-kmn-no-tex/kmeans_cuda.cu b/src/cuda/custom-apps/rodinia-kmn-no-tex/kmeans_cuda.cu index 0865090ad..5fae97ee3 100644 --- a/src/cuda/custom-apps/rodinia-kmn-no-tex/kmeans_cuda.cu +++ b/src/cuda/custom-apps/rodinia-kmn-no-tex/kmeans_cuda.cu @@ -212,7 +212,7 @@ kmeansCuda(float **feature, /* in: [npoints][nfeatures] */ block_clusters_d, block_deltas_d); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); // time_kernel = omp_get_wtime() - time_kernel; // time_back = omp_get_wtime(); diff --git a/src/cuda/custom-apps/rodinia-kmn-no-tex/kmeans_cuda_kernel.cu b/src/cuda/custom-apps/rodinia-kmn-no-tex/kmeans_cuda_kernel.cu index 1054c2993..0ec5676de 100644 --- a/src/cuda/custom-apps/rodinia-kmn-no-tex/kmeans_cuda_kernel.cu +++ b/src/cuda/custom-apps/rodinia-kmn-no-tex/kmeans_cuda_kernel.cu @@ -11,11 +11,8 @@ #define SDATA( index) CUT_BANK_CHECKER(sdata, index) -// t_features has the layout dim0[points 0-m-1]dim1[ points 0-m-1]... -texture t_features; -// t_features_flipped has the layout point0[dim 0-n-1]point1[dim 0-n-1] -texture t_features_flipped; -texture t_clusters; +/* This variant binds no textures (all binds are commented out in + kmeans_cuda.cu), so the texture references are gone entirely. */ //__constant__ float c_clusters[ASSUMED_NR_CLUSTERS*34]; /* constant memory for cluster centers */ diff --git a/src/cuda/custom-apps/shoc-modified-spmv/spmv-modified.cu b/src/cuda/custom-apps/shoc-modified-spmv/spmv-modified.cu index e66031e85..c0ae0e810 100644 --- a/src/cuda/custom-apps/shoc-modified-spmv/spmv-modified.cu +++ b/src/cuda/custom-apps/shoc-modified-spmv/spmv-modified.cu @@ -13,21 +13,42 @@ static const int TEMP_BUFFER_SIZE = 1024; enum kernelType{CSR_SCALAR, CSR_VECTOR, ELLPACKR}; -texture vecTex; // vector textures -texture vecTexD; +/* Texture references were removed in CUDA 12; the host fills these handles + via cudaMemcpyToSymbol so the reader structs below are unchanged. */ +__constant__ cudaTextureObject_t vecTex; // vector textures +__constant__ cudaTextureObject_t vecTexD; +static cudaTextureObject_t h_vecTex = 0; +static cudaTextureObject_t h_vecTexD = 0; + +template +static cudaTextureObject_t makeVecTexture(void *ptr, size_t bytes) +{ + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeLinear; + resDesc.res.linear.devPtr = ptr; + resDesc.res.linear.desc = cudaCreateChannelDesc(); + resDesc.res.linear.sizeInBytes = bytes; + texDesc.readMode = cudaReadModeElementType; + cudaTextureObject_t obj = 0; + cudaCreateTextureObject(&obj, &resDesc, &texDesc, NULL); + return obj; +} // Texture Readers (used so kernels can be templated) struct texReaderSP { __device__ __forceinline__ float operator()(const int idx) const { - return tex1Dfetch(vecTex, idx); + return tex1Dfetch(vecTex, idx); } }; struct texReaderDP { __device__ __forceinline__ double operator()(const int idx) const { - int2 v = tex1Dfetch(vecTexD, idx); + int2 v = tex1Dfetch(vecTexD, idx); #if (__CUDA_ARCH__ < 130) // Devices before arch 130 don't support DP, and having the // __hiloint2double() intrinsic will cause compilation to fail. @@ -211,12 +232,14 @@ void csrTest(floatType* h_val, if (sizeof(floatType) == sizeof(float)) { cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(); - cudaBindTexture(0, vecTex, d_vec, channelDesc, numRows * sizeof(float)); + h_vecTex = makeVecTexture(d_vec, numRows * sizeof(float)); + cudaMemcpyToSymbol(vecTex, &h_vecTex, sizeof(h_vecTex)); suffix = "-SP"; } else { cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(); - cudaBindTexture(0, vecTexD, d_vec, channelDesc, numRows * sizeof(int2)); + h_vecTexD = makeVecTexture(d_vec, numRows * sizeof(int2)); + cudaMemcpyToSymbol(vecTexD, &h_vecTexD, sizeof(h_vecTexD)); suffix = "-DP"; } @@ -253,7 +276,7 @@ void csrTest(floatType* h_val, } cout << "CSR Scalar Done\n"; zero<<>>(d_out, numRows); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); //cout << "CSR Vector Kernel\n"; //for (int k=0; k diff --git a/src/cuda/cutlass-bench b/src/cuda/cutlass-bench index e51efbfe1..2c85f4975 160000 --- a/src/cuda/cutlass-bench +++ b/src/cuda/cutlass-bench @@ -1 +1 @@ -Subproject commit e51efbfe18fe4f4cbb66ab814c55bf4aa0185491 +Subproject commit 2c85f497547eb441f0fe80bfb0fb2e6f9add1719 diff --git a/src/cuda/ispass-2009/AES/Makefile b/src/cuda/ispass-2009/AES/Makefile index 14d53a0f5..9e3104fd1 100644 --- a/src/cuda/ispass-2009/AES/Makefile +++ b/src/cuda/ispass-2009/AES/Makefile @@ -39,8 +39,7 @@ EXECUTABLE := ispass-2009-AES CUFILES := aesHost.cu # C/C++ source files (compiled with gcc / c++) CCFILES := aescuda.cpp aesCudaUtils.cpp -LINKFLAGS := -L$(BOOST_LIB) -ADDITIONAL_LIBS := -lboost_filesystem -lboost_system +# now uses C++17 std::filesystem instead of boost::filesystem HDRDIR := NEWLIBDIR := diff --git a/src/cuda/ispass-2009/AES/aesCudaUtils.cpp b/src/cuda/ispass-2009/AES/aesCudaUtils.cpp index 336718612..d9f594f92 100644 --- a/src/cuda/ispass-2009/AES/aesCudaUtils.cpp +++ b/src/cuda/ispass-2009/AES/aesCudaUtils.cpp @@ -107,8 +107,8 @@ unsigned initAesCuda(std::string myKeyFile, unsigned char myKeyBuffer[], const u if ( !inputArray ) throw std::string("input array not allocated"); - boost::intmax_t inputFileSize = getFileSize(inputPath); - boost::intmax_t keyFileSize = getFileSize(keyPath); + std::intmax_t inputFileSize = getFileSize(inputPath); + std::intmax_t keyFileSize = getFileSize(keyPath); if ( keyFileSize==0 ) throw std::string("cannot use an empty input file"); @@ -186,7 +186,7 @@ unsigned initAesCuda(std::string myKeyFile, unsigned char myKeyBuffer[], const u } -boost::intmax_t getFileSize(path &myPath){ +std::intmax_t getFileSize(path &myPath){ if ( !exists(myPath) ) throw std::string("file "+myPath.string()+" doesn't exist"); @@ -333,7 +333,7 @@ unsigned galoisProd(unsigned a, unsigned b){ } //scrive su file il risultato -void writeToFile(const std::string &outPath, char *storingArray, boost::intmax_t dataSize, unsigned maxInputSize){ +void writeToFile(const std::string &outPath, char *storingArray, std::intmax_t dataSize, unsigned maxInputSize){ if ( !storingArray ) throw std::string("writeToFile: array not allocated"); diff --git a/src/cuda/ispass-2009/AES/aesCudaUtils.h b/src/cuda/ispass-2009/AES/aesCudaUtils.h index c02e8a290..a26e89651 100644 --- a/src/cuda/ispass-2009/AES/aesCudaUtils.h +++ b/src/cuda/ispass-2009/AES/aesCudaUtils.h @@ -24,8 +24,8 @@ @author Svetlin Manavski */ -#include "boost/filesystem/operations.hpp" -#include "boost/filesystem/fstream.hpp" +#include +#include #include #include #include @@ -36,7 +36,7 @@ #include #include -using namespace boost::filesystem; +using namespace std::filesystem; //------------------------------------------help-functions------------------------------------------------------- unsigned mySbox(unsigned num); @@ -55,7 +55,7 @@ void usage(); unsigned initAesCuda(std::string myKeyFile, unsigned char myKeyBuffer[], const unsigned int myKeyBitsSize, std::string myInputFile, char inputArray[], const unsigned inputArraySize); -boost::intmax_t getFileSize(path &myPath); +std::intmax_t getFileSize(path &myPath); void readFromFileNotForm(path &myPath, char *storingArray, unsigned dataSize); @@ -71,4 +71,4 @@ void invMixColumn(std::vector &temp); unsigned galoisProd(unsigned a, unsigned b); -void writeToFile(const std::string &outPath, char *storingArray, boost::intmax_t dataSize, unsigned maxInputSize); +void writeToFile(const std::string &outPath, char *storingArray, std::intmax_t dataSize, unsigned maxInputSize); diff --git a/src/cuda/ispass-2009/AES/aesDecrypt128_kernel.h b/src/cuda/ispass-2009/AES/aesDecrypt128_kernel.h index 5634ef83a..a6cbaebd2 100644 --- a/src/cuda/ispass-2009/AES/aesDecrypt128_kernel.h +++ b/src/cuda/ispass-2009/AES/aesDecrypt128_kernel.h @@ -47,7 +47,9 @@ #define INVSBOX(index) CUT_BANK_CHECKER( invSBoxBlock, index ) -texture texDKey128; +/* Texture references were removed in CUDA 12; the host fills this handle + via cudaMemcpyToSymbol so the fetch sites below are unchanged. */ +__constant__ cudaTextureObject_t texDKey128; __global__ void aesDecrypt128( unsigned * result, unsigned * inData, int inputSize) { @@ -81,7 +83,7 @@ __global__ void aesDecrypt128( unsigned * result, unsigned * inData, int inputSi //----------------------------------- 1st stage ----------------------------------- x = mod4tx; - keyElem = tex1Dfetch(texDKey128, x); + keyElem = tex1Dfetch(texDKey128, x); STAGEBLOCK2(tx).uival = STAGEBLOCK1(tx).uival ^ keyElem; __syncthreads(); @@ -105,7 +107,7 @@ __global__ void aesDecrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+4; - keyElem = tex1Dfetch(texDKey128, x); + keyElem = tex1Dfetch(texDKey128, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -128,7 +130,7 @@ __global__ void aesDecrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+8; - keyElem = tex1Dfetch(texDKey128, x); + keyElem = tex1Dfetch(texDKey128, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -151,7 +153,7 @@ __global__ void aesDecrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+12; - keyElem = tex1Dfetch(texDKey128, x); + keyElem = tex1Dfetch(texDKey128, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -174,7 +176,7 @@ __global__ void aesDecrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+16; - keyElem = tex1Dfetch(texDKey128, x); + keyElem = tex1Dfetch(texDKey128, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -197,7 +199,7 @@ __global__ void aesDecrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+20; - keyElem = tex1Dfetch(texDKey128, x); + keyElem = tex1Dfetch(texDKey128, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -220,7 +222,7 @@ __global__ void aesDecrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+24; - keyElem = tex1Dfetch(texDKey128, x); + keyElem = tex1Dfetch(texDKey128, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -243,7 +245,7 @@ __global__ void aesDecrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+28; - keyElem = tex1Dfetch(texDKey128, x); + keyElem = tex1Dfetch(texDKey128, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -266,7 +268,7 @@ __global__ void aesDecrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+32; - keyElem = tex1Dfetch(texDKey128, x); + keyElem = tex1Dfetch(texDKey128, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -289,7 +291,7 @@ __global__ void aesDecrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+36; - keyElem = tex1Dfetch(texDKey128, x); + keyElem = tex1Dfetch(texDKey128, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -304,7 +306,7 @@ __global__ void aesDecrypt128( unsigned * result, unsigned * inData, int inputSi op4 = STAGEBLOCK1( posIdx_D[16 + mod4tx*4+3] + idx2 ).ubval[3]; x = mod4tx+40; - keyElem = tex1Dfetch(texDKey128, x); + keyElem = tex1Dfetch(texDKey128, x); STAGEBLOCK2(tx).ubval[3] = INVSBOX(op4).ubval[0]^( keyElem>>24); STAGEBLOCK2(tx).ubval[2] = INVSBOX(op3).ubval[0]^( keyElem>>16 & 0x000000FF); diff --git a/src/cuda/ispass-2009/AES/aesDecrypt256_kernel.h b/src/cuda/ispass-2009/AES/aesDecrypt256_kernel.h index 243b54958..d1a804b73 100644 --- a/src/cuda/ispass-2009/AES/aesDecrypt256_kernel.h +++ b/src/cuda/ispass-2009/AES/aesDecrypt256_kernel.h @@ -47,7 +47,9 @@ #define INVSBOX(index) CUT_BANK_CHECKER( invSBoxBlock, index ) -texture texDKey; +/* Texture references were removed in CUDA 12; the host fills this handle + via cudaMemcpyToSymbol so the fetch sites below are unchanged. */ +__constant__ cudaTextureObject_t texDKey; __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSize) { @@ -81,7 +83,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi //----------------------------------- 1st stage ----------------------------------- x = mod4tx; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK2(tx).uival = STAGEBLOCK1(tx).uival ^ keyElem; __syncthreads(); @@ -105,7 +107,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+4; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -128,7 +130,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+8; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -151,7 +153,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+12; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -174,7 +176,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+16; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -197,7 +199,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+20; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -220,7 +222,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+24; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -243,7 +245,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+28; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -266,7 +268,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+32; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -289,7 +291,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+36; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -312,7 +314,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+40; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -335,7 +337,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+44; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -358,7 +360,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+48; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -381,7 +383,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+52; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -396,7 +398,7 @@ __global__ void aesDecrypt256( unsigned * result, unsigned * inData, int inputSi op4 = STAGEBLOCK1( posIdx_D[16 + mod4tx*4+3] + idx2 ).ubval[3]; x = mod4tx+56; - keyElem = tex1Dfetch(texDKey, x); + keyElem = tex1Dfetch(texDKey, x); STAGEBLOCK2(tx).ubval[3] = INVSBOX(op4).ubval[0]^( keyElem>>24); STAGEBLOCK2(tx).ubval[2] = INVSBOX(op3).ubval[0]^( keyElem>>16 & 0x000000FF); diff --git a/src/cuda/ispass-2009/AES/aesEncrypt128_kernel.h b/src/cuda/ispass-2009/AES/aesEncrypt128_kernel.h index 187ab7509..50ce26017 100644 --- a/src/cuda/ispass-2009/AES/aesEncrypt128_kernel.h +++ b/src/cuda/ispass-2009/AES/aesEncrypt128_kernel.h @@ -45,7 +45,9 @@ #define TBOXE2(index) CUT_BANK_CHECKER( tBox2Block, index ) #define TBOXE3(index) CUT_BANK_CHECKER( tBox3Block, index ) -texture texEKey128; +/* Texture references were removed in CUDA 12; the host fills this handle + via cudaMemcpyToSymbol so the fetch sites below are unchanged. */ +__constant__ cudaTextureObject_t texEKey128; __global__ void aesEncrypt128( unsigned * result, unsigned * inData, int inputSize) { @@ -82,7 +84,7 @@ __global__ void aesEncrypt128( unsigned * result, unsigned * inData, int inputSi //----------------------------------- 1st stage ----------------------------------- x = mod4tx; - keyElem = tex1Dfetch(texEKey128, x); + keyElem = tex1Dfetch(texEKey128, x); STAGEBLOCK2(tx).uival = STAGEBLOCK1(tx).uival ^ keyElem; __syncthreads(); @@ -106,7 +108,7 @@ __global__ void aesEncrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+4; - keyElem = tex1Dfetch(texEKey128, x); + keyElem = tex1Dfetch(texEKey128, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -129,7 +131,7 @@ __global__ void aesEncrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+8; - keyElem = tex1Dfetch(texEKey128, x); + keyElem = tex1Dfetch(texEKey128, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -152,7 +154,7 @@ __global__ void aesEncrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+12; - keyElem = tex1Dfetch(texEKey128, x); + keyElem = tex1Dfetch(texEKey128, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -175,7 +177,7 @@ __global__ void aesEncrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+16; - keyElem = tex1Dfetch(texEKey128, x); + keyElem = tex1Dfetch(texEKey128, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -198,7 +200,7 @@ __global__ void aesEncrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+20; - keyElem = tex1Dfetch(texEKey128, x); + keyElem = tex1Dfetch(texEKey128, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -221,7 +223,7 @@ __global__ void aesEncrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+24; - keyElem = tex1Dfetch(texEKey128, x); + keyElem = tex1Dfetch(texEKey128, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -244,7 +246,7 @@ __global__ void aesEncrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+28; - keyElem = tex1Dfetch(texEKey128, x); + keyElem = tex1Dfetch(texEKey128, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -267,7 +269,7 @@ __global__ void aesEncrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+32; - keyElem = tex1Dfetch(texEKey128, x); + keyElem = tex1Dfetch(texEKey128, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -290,7 +292,7 @@ __global__ void aesEncrypt128( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+36; - keyElem = tex1Dfetch(texEKey128, x); + keyElem = tex1Dfetch(texEKey128, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -305,7 +307,7 @@ __global__ void aesEncrypt128( unsigned * result, unsigned * inData, int inputSi op4 = STAGEBLOCK1( posIdx_E[mod4tx*4+3] + idx2 ).ubval[3]; x = mod4tx+40; - keyElem = tex1Dfetch(texEKey128, x); + keyElem = tex1Dfetch(texEKey128, x); STAGEBLOCK2(tx).ubval[3] = TBOXE1(op4).ubval[3]^( keyElem>>24); diff --git a/src/cuda/ispass-2009/AES/aesEncrypt256_kernel.h b/src/cuda/ispass-2009/AES/aesEncrypt256_kernel.h index 47f82a459..3d3a58aa8 100644 --- a/src/cuda/ispass-2009/AES/aesEncrypt256_kernel.h +++ b/src/cuda/ispass-2009/AES/aesEncrypt256_kernel.h @@ -45,7 +45,9 @@ #define TBOXE2(index) CUT_BANK_CHECKER( tBox2Block, index ) #define TBOXE3(index) CUT_BANK_CHECKER( tBox3Block, index ) -texture texEKey; +/* Texture references were removed in CUDA 12; the host fills this handle + via cudaMemcpyToSymbol so the fetch sites below are unchanged. */ +__constant__ cudaTextureObject_t texEKey; __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSize) { @@ -82,7 +84,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi //----------------------------------- 1st stage ----------------------------------- x = mod4tx; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK2(tx).uival = STAGEBLOCK1(tx).uival ^ keyElem; __syncthreads(); @@ -106,7 +108,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+4; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -129,7 +131,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+8; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -152,7 +154,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+12; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -175,7 +177,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+16; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -198,7 +200,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+20; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -221,7 +223,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+24; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -244,7 +246,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+28; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -267,7 +269,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+32; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -290,7 +292,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+36; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -313,7 +315,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+40; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -336,7 +338,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+44; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -359,7 +361,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+48; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK2(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -382,7 +384,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = TBOXE3(op4).uival; x = mod4tx+52; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK1(tx).uival = op1^op2^op3^op4^keyElem; __syncthreads(); @@ -397,7 +399,7 @@ __global__ void aesEncrypt256( unsigned * result, unsigned * inData, int inputSi op4 = STAGEBLOCK1( posIdx_E[mod4tx*4+3] + idx2 ).ubval[3]; x = mod4tx+56; - keyElem = tex1Dfetch(texEKey, x); + keyElem = tex1Dfetch(texEKey, x); STAGEBLOCK2(tx).ubval[3] = TBOXE1(op4).ubval[3]^( keyElem>>24); STAGEBLOCK2(tx).ubval[2] = TBOXE1(op3).ubval[3]^( (keyElem>>16) & 0x000000FF); diff --git a/src/cuda/ispass-2009/AES/aesHost.cu b/src/cuda/ispass-2009/AES/aesHost.cu index d162baf51..4dffda5b3 100644 --- a/src/cuda/ispass-2009/AES/aesHost.cu +++ b/src/cuda/ispass-2009/AES/aesHost.cu @@ -46,7 +46,7 @@ extern "C" void aesEncryptHandler128(unsigned *d_Result, unsigned *d_Input, int dim3 grid((inputSize/BSIZE)/4, 1); aesEncrypt128<<< grid, threads >>>( d_Result, d_Input, inputSize); - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); } extern "C" void aesDecryptHandler128(unsigned *d_Result, unsigned *d_Input, int inputSize) { @@ -55,7 +55,7 @@ extern "C" void aesDecryptHandler128(unsigned *d_Result, unsigned *d_Input, int dim3 grid((inputSize/BSIZE)/4, 1); aesDecrypt128<<< grid, threads >>>( d_Result, d_Input, inputSize); - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); } extern "C" void aesEncryptHandler256(unsigned *d_Result, unsigned *d_Input, int inputSize) { @@ -64,7 +64,7 @@ extern "C" void aesEncryptHandler256(unsigned *d_Result, unsigned *d_Input, int dim3 grid((inputSize/BSIZE)/4, 1); aesEncrypt256<<< grid, threads >>>( d_Result, d_Input, inputSize); - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); } extern "C" void aesDecryptHandler256(unsigned *d_Result, unsigned *d_Input, int inputSize) { @@ -73,7 +73,7 @@ extern "C" void aesDecryptHandler256(unsigned *d_Result, unsigned *d_Input, int dim3 grid((inputSize/BSIZE)/4, 1); aesDecrypt256<<< grid, threads >>>( d_Result, d_Input, inputSize); - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); } @@ -132,15 +132,25 @@ extern "C" int aesHost(unsigned char* result, const unsigned char* inData, int i chDesc.z = 0; chDesc.w = 0; chDesc.f = cudaChannelFormatKindUnsigned; - texEKey.normalized = false; - texDKey.normalized = false; - texEKey128.normalized = false; - texDKey128.normalized = false; - - CUDA_SAFE_CALL( cudaBindTexture( 0, &texEKey128, d_Key, &chDesc, (size_t)keySize) ); - CUDA_SAFE_CALL( cudaBindTexture( 0, &texDKey128, d_Key, &chDesc, (size_t)keySize) ); - CUDA_SAFE_CALL( cudaBindTexture( 0, &texEKey, d_Key, &chDesc, (size_t)keySize) ); - CUDA_SAFE_CALL( cudaBindTexture( 0, &texDKey, d_Key, &chDesc, (size_t)keySize) ); + /* All four kernels read the same key buffer, so one texture object is + created and copied into each __constant__ handle. */ + cudaTextureObject_t h_keyTex = 0; + { + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeLinear; + resDesc.res.linear.devPtr = d_Key; + resDesc.res.linear.desc = chDesc; + resDesc.res.linear.sizeInBytes = (size_t)keySize; + texDesc.readMode = cudaReadModeElementType; + CUDA_SAFE_CALL( cudaCreateTextureObject(&h_keyTex, &resDesc, &texDesc, NULL) ); + } + CUDA_SAFE_CALL( cudaMemcpyToSymbol(texEKey128, &h_keyTex, sizeof(h_keyTex)) ); + CUDA_SAFE_CALL( cudaMemcpyToSymbol(texDKey128, &h_keyTex, sizeof(h_keyTex)) ); + CUDA_SAFE_CALL( cudaMemcpyToSymbol(texEKey, &h_keyTex, sizeof(h_keyTex)) ); + CUDA_SAFE_CALL( cudaMemcpyToSymbol(texDKey, &h_keyTex, sizeof(h_keyTex)) ); // allocate device memory for result unsigned int size_Result = inputSize; diff --git a/src/cuda/ispass-2009/BFS/bfs.cu b/src/cuda/ispass-2009/BFS/bfs.cu index 8e2348b28..e053d54a4 100644 --- a/src/cuda/ispass-2009/BFS/bfs.cu +++ b/src/cuda/ispass-2009/BFS/bfs.cu @@ -190,7 +190,7 @@ void BFSGraph( int argc, char** argv) CUDA_SAFE_CALL( cudaMemcpy( d_over, &stop, sizeof(bool), cudaMemcpyHostToDevice) ); CUT_SAFE_CALL( cutStartTimer( timer)); Kernel<<< grid, threads, 0 >>>( d_graph_nodes, d_graph_edges, d_graph_mask, d_graph_visited, d_cost, d_over, no_of_nodes); - CUDA_SAFE_CALL(cudaThreadSynchronize()); + CUDA_SAFE_CALL(cudaDeviceSynchronize()); CUT_SAFE_CALL( cutStopTimer( timer)); timer_acc += cutGetTimerValue(timer); CUT_SAFE_CALL( cutResetTimer( timer)); diff --git a/src/cuda/ispass-2009/CP/benchmarks/cp/src/cuda/main.cu b/src/cuda/ispass-2009/CP/benchmarks/cp/src/cuda/main.cu index cc369d2cf..83411267e 100644 --- a/src/cuda/ispass-2009/CP/benchmarks/cp/src/cuda/main.cu +++ b/src/cuda/ispass-2009/CP/benchmarks/cp/src/cuda/main.cu @@ -179,14 +179,14 @@ int main(int argc, char** argv) { if (copyatomstoconstbuf(atoms + 4*atomstart, runatoms, 0*gridspacing)) return -1; - if (parameters->synchronizeGpu) cudaThreadSynchronize(); + if (parameters->synchronizeGpu) cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_GPU); // RUN the kernel... cenergy<<>>(runatoms, 0.1, d_output); CUERR // check and clear any existing errors - if (parameters->synchronizeGpu) cudaThreadSynchronize(); + if (parameters->synchronizeGpu) cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE); // final_iteration_count = iterations; diff --git a/src/cuda/ispass-2009/CP/benchmarks/cp/src/cuda_base/main.cu b/src/cuda/ispass-2009/CP/benchmarks/cp/src/cuda_base/main.cu index 00b01556e..7d556e448 100644 --- a/src/cuda/ispass-2009/CP/benchmarks/cp/src/cuda_base/main.cu +++ b/src/cuda/ispass-2009/CP/benchmarks/cp/src/cuda_base/main.cu @@ -179,7 +179,7 @@ int main(int argc, char** argv) { if (copyatomstoconstbuf(atoms + 4*atomstart, runatoms, 0*gridspacing)) return -1; - if (parameters->synchronizeGpu) cudaThreadSynchronize(); + if (parameters->synchronizeGpu) cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_GPU); // RUN the kernel... @@ -187,7 +187,7 @@ int main(int argc, char** argv) { cenergy<<>>(runatoms, 0.1, d_output); CUERR // check and clear any existing errors - if (parameters->synchronizeGpu) cudaThreadSynchronize(); + if (parameters->synchronizeGpu) cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE); // final_iteration_count = iterations; diff --git a/src/cuda/ispass-2009/CP/benchmarks/cp/src/cuda_short/main.cu b/src/cuda/ispass-2009/CP/benchmarks/cp/src/cuda_short/main.cu index cc369d2cf..83411267e 100644 --- a/src/cuda/ispass-2009/CP/benchmarks/cp/src/cuda_short/main.cu +++ b/src/cuda/ispass-2009/CP/benchmarks/cp/src/cuda_short/main.cu @@ -179,14 +179,14 @@ int main(int argc, char** argv) { if (copyatomstoconstbuf(atoms + 4*atomstart, runatoms, 0*gridspacing)) return -1; - if (parameters->synchronizeGpu) cudaThreadSynchronize(); + if (parameters->synchronizeGpu) cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_GPU); // RUN the kernel... cenergy<<>>(runatoms, 0.1, d_output); CUERR // check and clear any existing errors - if (parameters->synchronizeGpu) cudaThreadSynchronize(); + if (parameters->synchronizeGpu) cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE); // final_iteration_count = iterations; diff --git a/src/cuda/ispass-2009/DG/src/MaxwellsRun3d.c b/src/cuda/ispass-2009/DG/src/MaxwellsRun3d.c index d4ee9f903..7657269e7 100644 --- a/src/cuda/ispass-2009/DG/src/MaxwellsRun3d.c +++ b/src/cuda/ispass-2009/DG/src/MaxwellsRun3d.c @@ -36,7 +36,7 @@ void MaxwellsRun3d(Mesh *mesh, double FinalTime, double dt){ } #ifdef CUDA - cudaThreadSynchronize(); + cudaDeviceSynchronize(); #endif double flopsV = p_Np*p_Np*36 + p_Np*66; /* V3 */ diff --git a/src/cuda/ispass-2009/LIB/libor.cu b/src/cuda/ispass-2009/LIB/libor.cu index 136cb3592..30fb8c16d 100644 --- a/src/cuda/ispass-2009/LIB/libor.cu +++ b/src/cuda/ispass-2009/LIB/libor.cu @@ -310,7 +310,7 @@ int main(int argc, char **argv){ // Execute GPU kernel -- no Greeks - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); CUT_SAFE_CALL( cutResetTimer(hTimer) ); CUT_SAFE_CALL( cutStartTimer(hTimer) ); @@ -323,7 +323,7 @@ int main(int argc, char **argv){ Pathcalc_Portfolio_KernelGPU2<<>>(d_v); CUT_CHECK_ERROR("Pathcalc_Portfolio_kernelGPU2() execution failed\n"); - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); // Read back GPU results and compute average @@ -341,7 +341,7 @@ int main(int argc, char **argv){ // Execute GPU kernel -- Greeks - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); CUT_SAFE_CALL( cutResetTimer(hTimer) ); CUT_SAFE_CALL( cutStartTimer(hTimer) ); @@ -349,7 +349,7 @@ int main(int argc, char **argv){ Pathcalc_Portfolio_KernelGPU<<>>(d_v,d_Lb); CUT_CHECK_ERROR("Pathcalc_Portfolio_kernelGPU() execution failed\n"); - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); // Read back GPU results and compute average diff --git a/src/cuda/ispass-2009/LPS/laplace3d.cu b/src/cuda/ispass-2009/LPS/laplace3d.cu index 5df1297e2..561f513fe 100644 --- a/src/cuda/ispass-2009/LPS/laplace3d.cu +++ b/src/cuda/ispass-2009/LPS/laplace3d.cu @@ -147,7 +147,7 @@ int main(int argc, char **argv){ h_u1, sizeof(float)*NX, sizeof(float)*NX, NY*NZ, cudaMemcpyHostToDevice) ); - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); CUT_SAFE_CALL(cutStopTimer(hTimer)); printf("\nCopy u1 to device: %f (ms) \n", cutGetTimerValue(hTimer)); CUT_SAFE_CALL( cutResetTimer(hTimer) ); @@ -165,7 +165,7 @@ int main(int argc, char **argv){ // Execute GPU kernel - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); CUT_SAFE_CALL( cutResetTimer(hTimer) ); CUT_SAFE_CALL( cutStartTimer(hTimer) ); @@ -173,7 +173,7 @@ int main(int argc, char **argv){ GPU_laplace3d<<>>(NX, NY, NZ, pitch, d_u1, d_u2); d_foo = d_u1; d_u1 = d_u2; d_u2 = d_foo; // swap d_u1 and d_u3 - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); CUT_CHECK_ERROR("GPU_laplace3d execution failed\n"); } diff --git a/src/cuda/ispass-2009/MUM/Makefile b/src/cuda/ispass-2009/MUM/Makefile index cb30dd4f6..5f24fad9a 100644 --- a/src/cuda/ispass-2009/MUM/Makefile +++ b/src/cuda/ispass-2009/MUM/Makefile @@ -47,5 +47,11 @@ CCFILES := \ ################################################################################ # Rules and targets +# SuffixNode::id() guards with "if (this)", which is undefined behaviour: +# modern GCC assumes this != NULL and deletes the check, so the legacy +# nullptr->id() calls segfault instead of returning 0. +CXXFLAGS += -fno-delete-null-pointer-checks +CFLAGS += -fno-delete-null-pointer-checks + GPGPUSIM_ROOT := .. include ../../common/common.mk diff --git a/src/cuda/ispass-2009/MUM/mummergpu.cu b/src/cuda/ispass-2009/MUM/mummergpu.cu index 968173e07..0990157ba 100644 --- a/src/cuda/ispass-2009/MUM/mummergpu.cu +++ b/src/cuda/ispass-2009/MUM/mummergpu.cu @@ -18,6 +18,12 @@ #include #include +/* Host-side handles for the __constant__ texture objects above, kept so + the objects can be destroyed where the code used to unbind. */ +static cudaTextureObject_t h_reftex = 0; +static cudaTextureObject_t h_nodetex = 0; +static cudaTextureObject_t h_childrentex = 0; + #define BLOCKSIZE 256 #define CUDA_SAFE_CALL( call) do { \ @@ -345,12 +351,22 @@ void loadReferenceTexture(MatchContext* ctx) numrows*ref->pitch, cudaMemcpyHostToDevice)); - reftex.addressMode[0] = cudaAddressModeClamp; - reftex.addressMode[1] = cudaAddressModeClamp; - reftex.filterMode = cudaFilterModePoint; - reftex.normalized = false; - CUDA_SAFE_CALL(cudaBindTextureToArray( reftex, (cudaArray*)ref->d_ref_tex_array, refTextureDesc)); + { + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeArray; + resDesc.res.array.array = (cudaArray*)ref->d_ref_tex_array; + texDesc.addressMode[0] = cudaAddressModeClamp; + texDesc.addressMode[1] = cudaAddressModeClamp; + texDesc.filterMode = cudaFilterModePoint; + texDesc.normalizedCoords = 0; + texDesc.readMode = cudaReadModeElementType; + CUDA_SAFE_CALL(cudaCreateTextureObject(&h_reftex, &resDesc, &texDesc, NULL)); + CUDA_SAFE_CALL(cudaMemcpyToSymbol(reftex, &h_reftex, sizeof(h_reftex))); + } stopTimer(toboardtimer); ctx->statistics.t_moving_tree_pages += getTimerValue(toboardtimer); @@ -367,7 +383,7 @@ void loadReferenceTexture(MatchContext* ctx) void unloadReferenceTexture(Reference* ref) { - CUDA_SAFE_CALL(cudaUnbindTexture( reftex ) ); + CUDA_SAFE_CALL(cudaDestroyTextureObject(h_reftex)); CUDA_SAFE_CALL(cudaFreeArray((cudaArray*)(ref->d_ref_tex_array))); ref->d_ref_tex_array = NULL; } @@ -406,14 +422,22 @@ void loadReference(MatchContext* ctx) ref->tex_width * ref->tex_height * sizeof(PixelOfNode), cudaMemcpyHostToDevice)); - nodetex.addressMode[0] = cudaAddressModeClamp; - nodetex.addressMode[1] = cudaAddressModeClamp; - nodetex.filterMode = cudaFilterModePoint; - nodetex.normalized = false; // access with normalized texture coordinates - CUDA_SAFE_CALL( cudaBindTextureToArray( nodetex, - (cudaArray*)ref->d_node_tex_array, - nodeTextureDesc)); + { + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeArray; + resDesc.res.array.array = (cudaArray*)ref->d_node_tex_array; + texDesc.addressMode[0] = cudaAddressModeClamp; + texDesc.addressMode[1] = cudaAddressModeClamp; + texDesc.filterMode = cudaFilterModePoint; + texDesc.normalizedCoords = 0; + texDesc.readMode = cudaReadModeElementType; + CUDA_SAFE_CALL(cudaCreateTextureObject(&h_nodetex, &resDesc, &texDesc, NULL)); + CUDA_SAFE_CALL(cudaMemcpyToSymbol(nodetex, &h_nodetex, sizeof(h_nodetex))); + } cudaChannelFormatDesc childrenTextureDesc = cudaCreateChannelDesc(32, 32, 32, 32, cudaChannelFormatKindUnsigned); @@ -432,14 +456,22 @@ void loadReference(MatchContext* ctx) ref->tex_width * ref->tex_height * sizeof(PixelOfChildren), cudaMemcpyHostToDevice)); - childrentex.addressMode[0] = cudaAddressModeClamp; - childrentex.addressMode[1] = cudaAddressModeClamp; - childrentex.filterMode = cudaFilterModePoint; - childrentex.normalized = false; // access with normalized texture coordinates - CUDA_SAFE_CALL( cudaBindTextureToArray( childrentex, - (cudaArray*)(ref->d_children_tex_array), - childrenTextureDesc)); + { + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeArray; + resDesc.res.array.array = (cudaArray*)(ref->d_children_tex_array); + texDesc.addressMode[0] = cudaAddressModeClamp; + texDesc.addressMode[1] = cudaAddressModeClamp; + texDesc.filterMode = cudaFilterModePoint; + texDesc.normalizedCoords = 0; + texDesc.readMode = cudaReadModeElementType; + CUDA_SAFE_CALL(cudaCreateTextureObject(&h_childrentex, &resDesc, &texDesc, NULL)); + CUDA_SAFE_CALL(cudaMemcpyToSymbol(childrentex, &h_childrentex, sizeof(h_childrentex))); + } fprintf(stderr, "done\n"); stopTimer(toboardtimer); @@ -457,11 +489,11 @@ void unloadReference(MatchContext* ctx) { Reference* ref = ctx->ref; - CUDA_SAFE_CALL(cudaUnbindTexture( nodetex ) ); + CUDA_SAFE_CALL(cudaDestroyTextureObject(h_nodetex)); CUDA_SAFE_CALL(cudaFreeArray((cudaArray*)(ref->d_node_tex_array))); ref->d_node_tex_array = NULL; - CUDA_SAFE_CALL(cudaUnbindTexture( childrentex ) ); + CUDA_SAFE_CALL(cudaDestroyTextureObject(h_childrentex)); CUDA_SAFE_CALL(cudaFreeArray((cudaArray*)(ref->d_children_tex_array))); ref->d_children_tex_array = NULL; @@ -1022,7 +1054,7 @@ int matchSubset(MatchContext* ctx, } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); // check if kernel execution generated an error cudaError_t err = cudaGetLastError(); @@ -1076,7 +1108,7 @@ int matchSubset(MatchContext* ctx, ctx->queries->d_lengths_array, numQueries, ctx->min_match_length); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); } stopTimer(rctimer); @@ -1239,7 +1271,7 @@ int matchQueries(MatchContext* ctx) matchSubset(ctx, 0, pages, num_reference_pages); ctx->statistics.bp_avg_query_length = ctx->queries->texlen/(float)(ctx->queries->count) - 2; destroyQueryBlock(ctx->queries); - cudaThreadExit(); + cudaDeviceReset(); } for (int i = 0; i < num_reference_pages; ++i) diff --git a/src/cuda/ispass-2009/MUM/mummergpu_kernel.cu b/src/cuda/ispass-2009/MUM/mummergpu_kernel.cu index 8e931851f..e4936a036 100644 --- a/src/cuda/ispass-2009/MUM/mummergpu_kernel.cu +++ b/src/cuda/ispass-2009/MUM/mummergpu_kernel.cu @@ -13,10 +13,11 @@ -texture nodetex; -texture childrentex; - -texture reftex; +/* Texture references were removed in CUDA 12; the host fills these handles + via cudaMemcpyToSymbol so the fetch sites below are unchanged. */ +__constant__ cudaTextureObject_t nodetex; +__constant__ cudaTextureObject_t childrentex; +__constant__ cudaTextureObject_t reftex; __device__ void set_result(const TextureAddress& cur, MatchCoord* result, @@ -44,7 +45,7 @@ __device__ char getRef(int refpos) int bigy = refpos >> 18; int y = (bigy << 2) + (bigx & 0x3); int x = bigx >> 2; - return tex2D(reftex, x, y); + return tex2D(reftex, x, y); } __device__ char rc(char c) @@ -118,7 +119,7 @@ mummergpuKernel(MatchCoord* match_coords, XPRINTF("Next edge to follow: %c (%d)\n", c, qry_match_len); PixelOfChildren children; - children.data = tex2D(childrentex,cur.x, cur.y); + children.data = tex2D(childrentex,cur.x, cur.y); prev = cur; switch(c) @@ -148,7 +149,7 @@ mummergpuKernel(MatchCoord* match_coords, { unsigned short xval = cur.data & 0xFFFF; unsigned short yval = (cur.data & 0xFFFF0000) >> 16; - node.data = tex2D(nodetex, xval, yval); + node.data = tex2D(nodetex, xval, yval); } XPRINTF(" Edge coordinates: %d - %d\n", node.start, node.end); @@ -214,7 +215,7 @@ mummergpuKernel(MatchCoord* match_coords, NEXT_SUBSTRING: - node.data = tex2D(nodetex, prev.x, prev.y); + node.data = tex2D(nodetex, prev.x, prev.y); cur = node.suffix; XPRINTF(" following suffix link. mustmatch:%d qry_match_len:%d sl:(%d,%d)\n", @@ -293,7 +294,7 @@ mummergpuRCKernel(MatchCoord* match_coords, XPRINTF("Next edge to follow: %c (%d)\n", c, qry_match_len); PixelOfChildren children; - children.data = tex2D(childrentex,cur.x, cur.y); + children.data = tex2D(childrentex,cur.x, cur.y); prev = cur; switch(c) @@ -323,7 +324,7 @@ mummergpuRCKernel(MatchCoord* match_coords, { unsigned short xval = cur.data & 0xFFFF; unsigned short yval = (cur.data & 0xFFFF0000) >> 16; - node.data = tex2D(nodetex, xval, yval); + node.data = tex2D(nodetex, xval, yval); } XPRINTF(" Edge coordinates: %d - %d\n", node.start, node.end); @@ -389,7 +390,7 @@ mummergpuRCKernel(MatchCoord* match_coords, NEXT_SUBSTRING: - node.data = tex2D(nodetex, prev.x, prev.y); + node.data = tex2D(nodetex, prev.x, prev.y); cur = node.suffix; XPRINTF(" following suffix link. mustmatch:%d qry_match_len:%d sl:(%d,%d)\n", diff --git a/src/cuda/ispass-2009/NQU/nqueen.cu b/src/cuda/ispass-2009/NQU/nqueen.cu index 68dc9b520..c4e769317 100644 --- a/src/cuda/ispass-2009/NQU/nqueen.cu +++ b/src/cuda/ispass-2009/NQU/nqueen.cu @@ -728,7 +728,7 @@ int main(int argc, char** argv) } if(cpu) { - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); CUT_SAFE_CALL( cutResetTimer(hTimer) ); CUT_SAFE_CALL( cutStartTimer(hTimer) ); @@ -744,7 +744,7 @@ int main(int argc, char** argv) if(gpu) { //start = clock(); - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); CUT_SAFE_CALL( cutResetTimer(hTimer) ); CUT_SAFE_CALL( cutStartTimer(hTimer) ); solution = solve_nqueen_cuda(n, steps); diff --git a/src/cuda/ispass-2009/RAY/rayTracing.cu b/src/cuda/ispass-2009/RAY/rayTracing.cu index 80145ddd3..29c045ea4 100644 --- a/src/cuda/ispass-2009/RAY/rayTracing.cu +++ b/src/cuda/ispass-2009/RAY/rayTracing.cu @@ -177,7 +177,7 @@ void render() #else render<<>>(d_output, d_node, width, height, anim, obs.getDistance()); #endif - CUDA_SAFE_CALL( cudaThreadSynchronize() ); + CUDA_SAFE_CALL( cudaDeviceSynchronize() ); CUT_SAFE_CALL(cutStopTimer(timer)); #ifdef DEBUG_RT_CUDA diff --git a/src/cuda/ispass-2009/STO/storeGPU.cu b/src/cuda/ispass-2009/STO/storeGPU.cu index 70e23ab59..a4d8c39dd 100644 --- a/src/cuda/ispass-2009/STO/storeGPU.cu +++ b/src/cuda/ispass-2009/STO/storeGPU.cu @@ -689,7 +689,7 @@ sg_status_type sg_md5(unsigned char* buffer, int size, CUT_CHECK_ERROR("Kernel execution failed"); /* wait till the kernel finishes execution */ - CUDA_SAFE_CALL(cudaThreadSynchronize()); + CUDA_SAFE_CALL(cudaDeviceSynchronize()); /* stop the timer (kernel execution) */ CUT_SAFE_CALL(cutStopTimer(timer)); @@ -856,7 +856,7 @@ sg_status_type sg_md5_overlap(unsigned char* buffer, int size, CUT_CHECK_ERROR("Kernel execution failed"); /* wait till the kernel finishes execution */ - CUDA_SAFE_CALL(cudaThreadSynchronize()); + CUDA_SAFE_CALL(cudaDeviceSynchronize()); /* stop the timer (kernel execution) */ CUT_SAFE_CALL(cutStopTimer(timer)); @@ -1009,7 +1009,7 @@ sg_status_type sg_sha1(unsigned char* buffer, int size, CUT_CHECK_ERROR("Kernel execution failed"); /* wait till the kernel finishes execution */ - CUDA_SAFE_CALL(cudaThreadSynchronize()); + CUDA_SAFE_CALL(cudaDeviceSynchronize()); /* stop the timer (kernel execution) */ CUT_SAFE_CALL(cutStopTimer(timer)); @@ -1177,7 +1177,7 @@ sg_status_type sg_sha1_overlap(unsigned char* buffer, int size, CUT_CHECK_ERROR("Kernel execution failed"); /* wait till the kernel finishes execution */ - CUDA_SAFE_CALL(cudaThreadSynchronize()); + CUDA_SAFE_CALL(cudaDeviceSynchronize()); /* stop the timer (kernel execution) */ CUT_SAFE_CALL(cutStopTimer(timer)); diff --git a/src/cuda/ispass-2009/WP/makefile b/src/cuda/ispass-2009/WP/makefile index 888e3d3da..8b4e709fc 100644 --- a/src/cuda/ispass-2009/WP/makefile +++ b/src/cuda/ispass-2009/WP/makefile @@ -84,7 +84,7 @@ else GENCODE_SM10 := -gencode=arch=compute_10,code=\"sm_10,compute_10\" GENCODE_SM20 := -gencode=arch=compute_20,code=\"sm_20,compute_20\" endif -PHASE += $(GENCODE_SM10) $(GENCODE_SM20) +PHASE += $(GENCODE_SM10) $(GENCODE_SM20) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) ROOTBINDIR ?= bin @@ -92,15 +92,17 @@ BINDIR ?= $(ROOTBINDIR) BINSUBDIR := release TARGETDIR := $(BINDIR)/$(BINSUBDIR) ROOTOBJDIR ?= obj -LIBDIR := $(NVIDIA_COMPUTE_SDK_LOCATION)/lib -COMMONDIR := $(NVIDIA_COMPUTE_SDK_LOCATION)/common +LIBDIR := $(GPUAPPS_SDK_LIB) +COMMONDIR := $(NVIDIA_COMPUTE_SDK_LOCATION) GPGPUSIM_ROOT ?= ../../.. INTERMED_FILES := *.cpp*.i *.cpp*.ii *.cu.c *.cudafe*.* *.fatbin.c *.cubin *.hash CUDAHOME=$(CUDA_INSTALL_PATH) NVOPENCC_VER:=$(shell $$CUDAHOME/open64/bin/nvopencc --version 2>&1 | awk '/GPGPU-Sim/ {printf("_nvopencc_CL%d", $$3);}') -#GPGPULINK = -L$(CUDAHOME)/lib64/ -lcudart -L$(NVIDIA_COMPUTE_SDK_LOCATION)/C/lib/ -lcutil_x86_64 -lm -lz -ldl -lGL -lstdc++ $(NEWLIBDIR) $(LIB) # /usr/lib64/libstdc++.so.6 -GPGPULINK = -L$(CUDAHOME)/lib64/ -lcudart -L$(NVIDIA_COMPUTE_SDK_LOCATION)/C/lib/ -lm -lz -ldl -lGL -lstdc++ $(NEWLIBDIR) $(LIB) # /usr/lib64/libstdc++.so.6 +#GPGPULINK = -L$(CUDAHOME)/lib64/ -lcudart -L$(GPUAPPS_SDK_LIB) -lcutil_x86_64 -lm -lz -ldl -lGL -lstdc++ $(NEWLIBDIR) $(LIB) # /usr/lib64/libstdc++.so.6 +# No source in WP includes a GL header; -lGL was vestigial and needs the +# libgl-dev symlink, which is not present on a headless box. +GPGPULINK = -L$(CUDAHOME)/lib64/ -lcudart -L$(GPUAPPS_SDK_LIB) -lm -lz -ldl -lstdc++ $(NEWLIBDIR) $(LIB) # /usr/lib64/libstdc++.so.6 .SUFFIXES : all : vanilla $(BINDIR)/$(BINSUBDIR)/ispass-2009-WP compare_snaps diff --git a/src/cuda/ispass-2009/WP/wsm5.cu b/src/cuda/ispass-2009/WP/wsm5.cu index 894e937ef..aa024c192 100644 --- a/src/cuda/ispass-2009/WP/wsm5.cu +++ b/src/cuda/ispass-2009/WP/wsm5.cu @@ -181,7 +181,10 @@ WSM5_GPU_INIT ( int * myproc , int * nproc, int * mydevice ) fprintf(stderr,"Device %02d: maxgdim %d %d %d\n",i,dp.maxGridSize[0] ,dp.maxGridSize[1] ,dp.maxGridSize[2]) ; - fprintf(stderr,"Device %02d: clock %d\n",i,dp.clockRate) ; + // cudaDeviceProp::clockRate was removed in CUDA 13; query the attribute. + int clockKHz = 0 ; + cudaDeviceGetAttribute(&clockKHz,cudaDevAttrClockRate,i) ; + fprintf(stderr,"Device %02d: clock %d\n",i,clockKHz) ; fprintf(stderr,"Device %02d: talign %d\n",i,dp.textureAlignment) ; } @@ -296,7 +299,7 @@ TODEV(retvals,(*kme-*kms+1)) ; ,dips+1 , dipe , djps+1 , djpe , dkps+1 , dkpe ,dips+1 , dipe , djps+1 , djpe , dkps+1 , dkpe ) ; - cudaThreadSynchronize() ; + cudaDeviceSynchronize() ; e2 = rsl_internal_microclock_() ; fprintf(stderr,"Call to wsm5_gpu (not including data xfer): %d microseconds\n",e2-s2) ; #endif diff --git a/src/cuda/lonestargpu-2.0/apps/bfs/Makefile b/src/cuda/lonestargpu-2.0/apps/bfs/Makefile index 482f12b21..2e7df7cba 100644 --- a/src/cuda/lonestargpu-2.0/apps/bfs/Makefile +++ b/src/cuda/lonestargpu-2.0/apps/bfs/Makefile @@ -4,7 +4,7 @@ SRC=main.cu INC=bfs_ls.h B40_DIR=./back40computing-read-only/ B40C_INC=-I $(B40_DIR) -I $(B40_DIR)/test/ -VARIANTS=bfs bfs-atomic bfs-wlw bfs-wla +VARIANTS=bfs bfs-atomic bfs-wlc bfs-wlw bfs-wla include ../common.mk diff --git a/src/cuda/lonestargpu-2.0/apps/bfs/bfs_worklistc.h b/src/cuda/lonestargpu-2.0/apps/bfs/bfs_worklistc.h index 74125ce72..ab1868719 100644 --- a/src/cuda/lonestargpu-2.0/apps/bfs/bfs_worklistc.h +++ b/src/cuda/lonestargpu-2.0/apps/bfs/bfs_worklistc.h @@ -16,8 +16,30 @@ unsigned int NVERTICES; const int BLKSIZE = 704; const int IN_CORE = 1; // set this to zero to disable global-barrier version -texture columns; -texture row_offsets; +/* Texture references were removed in CUDA 12; the host fills these handles + via cudaMemcpyToSymbol so the fetch sites below are unchanged. */ +__constant__ cudaTextureObject_t columns; +__constant__ cudaTextureObject_t row_offsets; +static cudaTextureObject_t h_columns = 0; +static cudaTextureObject_t h_row_offsets = 0; + +static void makeIntTexture(cudaTextureObject_t *out, void *ptr, size_t bytes) +{ + if (*out) { + cudaDestroyTextureObject(*out); + *out = 0; + } + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeLinear; + resDesc.res.linear.devPtr = ptr; + resDesc.res.linear.desc = cudaCreateChannelDesc(); + resDesc.res.linear.sizeInBytes = bytes; + texDesc.readMode = cudaReadModeElementType; + cudaCreateTextureObject(out, &resDesc, &texDesc, NULL); +} __global__ void initialize(foru *dist, unsigned int nv) { @@ -31,7 +53,7 @@ void initialize(foru *dist, unsigned int nv) { __device__ foru processedge2(foru *dist, Graph &graph, unsigned iteration, unsigned edge, unsigned &dst) { - dst = tex1Dfetch(columns, edge); + dst = tex1Dfetch(columns, edge); if (dst >= graph.nnodes) return 0; @@ -53,9 +75,9 @@ foru processedge(foru *dist, Graph &graph, unsigned src, unsigned ii, unsigned & //dst = graph.getDestination(src, ii); // no bounds checking here - dst = tex1Dfetch(columns, tex1Dfetch(row_offsets, graph.srcsrc[src]) + ii); + dst = tex1Dfetch(columns, tex1Dfetch(row_offsets, graph.srcsrc[src]) + ii); - //printf("%d %d %d %d\n", dst, tex1Dfetch(columns, tex1Dfetch(row_offsets, graph.srcsrc[src]) + ii)); + //printf("%d %d %d %d\n", dst, tex1Dfetch(columns, tex1Dfetch(row_offsets, graph.srcsrc[src]) + ii)); if (dst >= graph.nnodes) return 0; @@ -107,7 +129,7 @@ __device__ void expandByCTA(foru *dist, Graph &graph, Worklist2 &inwl, Worklist2 if(inwl.pop_id(id, nn)) { neighborsize = nnsize = graph.getOutDegree(nn); - neighboroffset = tex1Dfetch(row_offsets, graph.srcsrc[nn]); + neighboroffset = tex1Dfetch(row_offsets, graph.srcsrc[nn]); } while(true) @@ -131,7 +153,7 @@ __device__ void expandByCTA(foru *dist, Graph &graph, Worklist2 &inwl, Worklist2 __syncthreads(); neighborsize = graph.getOutDegree(shnn); - neighboroffset = tex1Dfetch(row_offsets, graph.srcsrc[shnn]); + neighboroffset = tex1Dfetch(row_offsets, graph.srcsrc[shnn]); int xy = ((neighborsize + blockDim.x - 1) / blockDim.x) * blockDim.x; for(int i = threadIdx.x; i < xy; i+= blockDim.x) @@ -182,7 +204,7 @@ unsigned processnode2(foru *dist, Graph &graph, Worklist2 &inwl, Worklist2 &outw if(nn != -1) { neighborsize = graph.getOutDegree(nn); - neighboroffset = tex1Dfetch(row_offsets, graph.srcsrc[nn]); + neighboroffset = tex1Dfetch(row_offsets, graph.srcsrc[nn]); } } @@ -330,7 +352,7 @@ __global__ void print_texture(int n) { int id = threadIdx.x + blockDim.x * blockIdx.x; if(id < n) - printf("%d %d\n", id, tex1Dfetch(columns, id)); + printf("%d %d\n", id, tex1Dfetch(columns, id)); } void bfs(Graph &graph, foru *dist) @@ -364,8 +386,10 @@ void bfs(Graph &graph, foru *dist) Worklist2 *inwl = &wl1, *outwl = &wl2; int nitems = 1; - cudaBindTexture(0, columns, graph.edgessrcdst, (graph.nedges + 1) * sizeof(int)); - cudaBindTexture(0, row_offsets, graph.psrc, (graph.nnodes + 1) * sizeof(int)); + makeIntTexture(&h_columns, graph.edgessrcdst, (graph.nedges + 1) * sizeof(int)); + cudaMemcpyToSymbol(columns, &h_columns, sizeof(h_columns)); + makeIntTexture(&h_row_offsets, graph.psrc, (graph.nnodes + 1) * sizeof(int)); + cudaMemcpyToSymbol(row_offsets, &h_row_offsets, sizeof(h_row_offsets)); //print_array<<<1, graph.nedges + 1>>>((int *) graph.edgessrcdst, graph.nedges + 1); //print_texture<<<1, graph.nedges + 1>>>(graph.nedges + 1); diff --git a/src/cuda/lonestargpu-2.0/apps/bh/main.cu b/src/cuda/lonestargpu-2.0/apps/bh/main.cu index b67a6a6df..9c5e576bc 100644 --- a/src/cuda/lonestargpu-2.0/apps/bh/main.cu +++ b/src/cuda/lonestargpu-2.0/apps/bh/main.cu @@ -706,7 +706,7 @@ static void CudaTest(char *msg) { cudaError_t e; - cudaThreadSynchronize(); + cudaDeviceSynchronize(); if (cudaSuccess != (e = cudaGetLastError())) { fprintf(stderr, "%s: %d\n", msg, e); fprintf(stderr, "%s\n", cudaGetErrorString(e)); diff --git a/src/cuda/lonestargpu-2.0/apps/common.mk b/src/cuda/lonestargpu-2.0/apps/common.mk index 2e2240dd3..4f240c1c0 100644 --- a/src/cuda/lonestargpu-2.0/apps/common.mk +++ b/src/cuda/lonestargpu-2.0/apps/common.mk @@ -19,12 +19,12 @@ GENCODE_SM70 ?= -gencode=arch=compute_70,code=\"sm_70,compute_70\" GENCODE_SM75 ?= -gencode=arch=compute_75,code=\"sm_75,compute_75\" ifdef debug -FLAGS := $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) -g -DLSGDEBUG=1 -G +FLAGS := $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) -g -DLSGDEBUG=1 -G else # including -lineinfo -G causes launches to fail because of lack of resources, pity. -FLAGS := -O3 $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) -g -Xptxas -v #-lineinfo -G +FLAGS := -O3 $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) -g -Xptxas -v #-lineinfo -G endif -INCLUDES := -I $(TOPLEVEL)/include -I $(NVIDIA_COMPUTE_SDK_LOCATION)/common/inc +INCLUDES := -I $(TOPLEVEL)/include -I $(GPUAPPS_SDK_INC) LINKS := EXTRA := $(FLAGS) $(NVCC_ADDITIONAL_ARGS) $(INCLUDES) $(LINKS) diff --git a/src/cuda/lonestargpu-2.0/apps/mst/main.cu b/src/cuda/lonestargpu-2.0/apps/mst/main.cu index 3fbcd18e5..bb292b55c 100644 --- a/src/cuda/lonestargpu-2.0/apps/mst/main.cu +++ b/src/cuda/lonestargpu-2.0/apps/mst/main.cu @@ -316,7 +316,7 @@ int main(int argc, char *argv[]) { //dfindcompmin <<>> (mstwt, graph, cs, eleminwts, minwtcomponent, partners, phores, processinnextiteration, goaheadnodeofcomponent, graph.nnodes); //CudaTest("dfindcompmin failed"); //printf("2 %d\n", cs.numberOfComponentsHost()); - //cudaThreadSynchronize(); + //cudaDeviceSynchronize(); //printf("\n"); //cs.copy(cs2); diff --git a/src/cuda/lonestargpu-2.0/apps/pta/andersen.cu b/src/cuda/lonestargpu-2.0/apps/pta/andersen.cu index 3efd74821..2a9907589 100644 --- a/src/cuda/lonestargpu-2.0/apps/pta/andersen.cu +++ b/src/cuda/lonestargpu-2.0/apps/pta/andersen.cu @@ -2336,7 +2336,7 @@ __global__ void findCurrPtsEquivalents() { __host__ void checkKernelErrors(char *msg) { cudaError_t e; - cudaThreadSynchronize(); + cudaDeviceSynchronize(); // cudaThreadSynchronize was removed in CUDA 12 if (cudaSuccess != (e = cudaGetLastError())) { printf("\n%s: %s\n", msg, cudaGetErrorString(e)); exit(-1); @@ -2436,14 +2436,18 @@ extern "C" void createGraph(const uint numObjectVars, const uint maxOffset) { createTime = getEllapsedTime(startTime); } -struct neqAdapter : public thrust::unary_function, uint>{ +/* thrust::unary_function was removed in CUDA 13; it only supplied + argument_type/result_type typedefs that Thrust no longer consults. */ +struct neqAdapter { __host__ __device__ uint operator()(const thrust::tuple& a) { return thrust::get<0>(a) != thrust::get<1>(a); } }; -struct mulAdapter : public thrust::unary_function, uint>{ +/* thrust::unary_function was removed in CUDA 13; it only supplied + argument_type/result_type typedefs that Thrust no longer consults. */ +struct mulAdapter { __host__ __device__ uint operator()(const thrust::tuple& a) { return thrust::get<0>(a) * thrust::get<1>(a); diff --git a/src/cuda/lonestargpu-2.0/apps/pta/main.cu b/src/cuda/lonestargpu-2.0/apps/pta/main.cu index ee44ecdeb..7449b3ca5 100644 --- a/src/cuda/lonestargpu-2.0/apps/pta/main.cu +++ b/src/cuda/lonestargpu-2.0/apps/pta/main.cu @@ -108,8 +108,8 @@ void checkGPUConfiguration() { cudaDeviceGetLimit(&limit, cudaLimitPrintfFifoSize); cudaDeviceSetLimit(cudaLimitPrintfFifoSize, limit * 16); // Make stack bigger, otherwise recursive functions will fail silently (?) - //cudaThreadGetLimit(&limit, cudaLimitStackSize); - //cudaThreadSetLimit(cudaLimitStackSize, limit * 8); + //cudaDeviceGetLimit(&limit, cudaLimitStackSize); + //cudaDeviceSetLimit(cudaLimitStackSize, limit * 8); } uint nextUint(istringstream& lineStream) { diff --git a/src/cuda/lonestargpu-2.0/apps/sssp/Makefile b/src/cuda/lonestargpu-2.0/apps/sssp/Makefile index b97d1d7c6..bb557259e 100644 --- a/src/cuda/lonestargpu-2.0/apps/sssp/Makefile +++ b/src/cuda/lonestargpu-2.0/apps/sssp/Makefile @@ -2,7 +2,7 @@ TOPLEVEL := ../.. APP=sssp SRC=main.cu INC=sssp_ls.h -VARIANTS=sssp sssp-wln +VARIANTS=sssp sssp-wln sssp-wlc OTHER_VARIANTS=sssp-tpatm include ../common.mk diff --git a/src/cuda/lonestargpu-2.0/apps/sssp/sssp_worklistc.h b/src/cuda/lonestargpu-2.0/apps/sssp/sssp_worklistc.h index ff1132adc..1cf971fbb 100644 --- a/src/cuda/lonestargpu-2.0/apps/sssp/sssp_worklistc.h +++ b/src/cuda/lonestargpu-2.0/apps/sssp/sssp_worklistc.h @@ -21,8 +21,30 @@ struct workprogress int iteration; }; -texture columns; -texture row_offsets; +/* Texture references were removed in CUDA 12; the host fills these handles + via cudaMemcpyToSymbol so the fetch sites below are unchanged. */ +__constant__ cudaTextureObject_t columns; +__constant__ cudaTextureObject_t row_offsets; +static cudaTextureObject_t h_columns = 0; +static cudaTextureObject_t h_row_offsets = 0; + +static void makeIntTexture(cudaTextureObject_t *out, void *ptr, size_t bytes) +{ + if (*out) { + cudaDestroyTextureObject(*out); + *out = 0; + } + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeLinear; + resDesc.res.linear.devPtr = ptr; + resDesc.res.linear.desc = cudaCreateChannelDesc(); + resDesc.res.linear.sizeInBytes = bytes; + texDesc.readMode = cudaReadModeElementType; + cudaCreateTextureObject(out, &resDesc, &texDesc, NULL); +} __global__ void initialize(foru *dist, unsigned int nv) { @@ -36,7 +58,7 @@ void initialize(foru *dist, unsigned int nv) { __device__ foru processedge2(foru *dist, Graph &graph, unsigned iteration, unsigned src, unsigned edge, unsigned &dst) { - dst = tex1Dfetch(columns, edge); + dst = tex1Dfetch(columns, edge); if (dst >= graph.nnodes) return 0; foru wt = graph.edgessrcwt[edge]; @@ -87,7 +109,7 @@ __device__ void expandByCTA(foru *dist, Graph &graph, Worklist2 &inwl, Worklist2 if(nn != -1) { neighborsize = nnsize = graph.getOutDegree(nn); - neighboroffset = tex1Dfetch(row_offsets, graph.srcsrc[nn]); + neighboroffset = tex1Dfetch(row_offsets, graph.srcsrc[nn]); } } @@ -112,7 +134,7 @@ __device__ void expandByCTA(foru *dist, Graph &graph, Worklist2 &inwl, Worklist2 __syncthreads(); neighborsize = graph.getOutDegree(shnn); - neighboroffset = tex1Dfetch(row_offsets, graph.srcsrc[shnn]); + neighboroffset = tex1Dfetch(row_offsets, graph.srcsrc[shnn]); int xy = ((neighborsize + blockDim.x - 1) / blockDim.x) * blockDim.x; for(int i = threadIdx.x; i < xy; i+= blockDim.x) @@ -166,7 +188,7 @@ unsigned processnode2(foru *dist, Graph &graph, Worklist2 &inwl, Worklist2 &outw { neighborsize = graph.getOutDegree(nn); - neighboroffset = tex1Dfetch(row_offsets, graph.srcsrc[nn]); + neighboroffset = tex1Dfetch(row_offsets, graph.srcsrc[nn]); } } @@ -301,7 +323,7 @@ __global__ void print_texture(int n) { int id = threadIdx.x + blockDim.x * blockIdx.x; if(id < n) - printf("%d %d\n", id, tex1Dfetch(columns, id)); + printf("%d %d\n", id, tex1Dfetch(columns, id)); } __global__ void remove_dups(Worklist2 wl, int *node_owner, GlobalBarrier gb) @@ -384,8 +406,10 @@ void sssp(foru *hdist, foru *dist, Graph &graph, unsigned long totalcomm) CUDA_SAFE_CALL(cudaMemcpy(dwp, &hwp, sizeof(*dwp), cudaMemcpyHostToDevice)); - cudaBindTexture(0, columns, graph.edgessrcdst, (graph.nedges + 1) * sizeof(int)); - cudaBindTexture(0, row_offsets, graph.psrc, (graph.nnodes + 1) * sizeof(int)); + makeIntTexture(&h_columns, graph.edgessrcdst, (graph.nedges + 1) * sizeof(int)); + cudaMemcpyToSymbol(columns, &h_columns, sizeof(h_columns)); + makeIntTexture(&h_row_offsets, graph.psrc, (graph.nnodes + 1) * sizeof(int)); + cudaMemcpyToSymbol(row_offsets, &h_row_offsets, sizeof(h_row_offsets)); //print_array<<<1, graph.nedges + 1>>>((int *) graph.edgessrcdst, graph.nedges + 1); //print_texture<<<1, graph.nedges + 1>>>(graph.nedges + 1); diff --git a/src/cuda/lonestargpu-2.0/include/common.h b/src/cuda/lonestargpu-2.0/include/common.h index f4b0eded4..7b9020c87 100644 --- a/src/cuda/lonestargpu-2.0/include/common.h +++ b/src/cuda/lonestargpu-2.0/include/common.h @@ -109,7 +109,7 @@ static unsigned CudaTest(char *msg) { cudaError_t e; - cudaThreadSynchronize(); + cudaDeviceSynchronize(); if (cudaSuccess != (e = cudaGetLastError())) { fprintf(stderr, "%s: %d\n", msg, e); fprintf(stderr, "%s\n", cudaGetErrorString(e)); @@ -142,6 +142,19 @@ inline int ConvertSMVer2Cores(int major, int minor) { 0x61, 128}, // Pascal Generation (SM 6.1) GP10x class { 0x62, 128}, // Pascal Generation (SM 6.2) GP10x class { 0x70, 64 }, // Volta Generation (SM 7.0) GV100 class + { 0x72, 64 }, // Volta Generation (SM 7.2) GV10B class + { 0x75, 64 }, // Turing Generation (SM 7.5) TU10x class + { 0x80, 64 }, // Ampere Generation (SM 8.0) GA100 class + { 0x86, 128}, // Ampere Generation (SM 8.6) GA10x class + { 0x87, 128}, // Ampere Generation (SM 8.7) GA10B class + { 0x89, 128}, // Ada Generation (SM 8.9) AD10x class + { 0x90, 128}, // Hopper Generation (SM 9.0) GH100 class + { 0xa0, 128}, // Blackwell Generation (SM 10.0) GB100 class + { 0xa1, 128}, // Blackwell Generation (SM 10.1) GB10x class + { 0xa3, 128}, // Blackwell Generation (SM 10.3) GB30x class + { 0xb0, 128}, // Blackwell Generation (SM 11.0) class + { 0xc0, 128}, // Blackwell Generation (SM 12.0) GB20x class + { 0xc1, 128}, // Blackwell Generation (SM 12.1) class { -1, -1 } }; diff --git a/src/cuda/lonestargpu-2.0/include/header.h b/src/cuda/lonestargpu-2.0/include/header.h index 71a2d1a42..ac6f9f035 100644 --- a/src/cuda/lonestargpu-2.0/include/header.h +++ b/src/cuda/lonestargpu-2.0/include/header.h @@ -35,7 +35,7 @@ void CudaTest(char *msg) { cudaError_t e; - cudaThreadSynchronize(); + cudaDeviceSynchronize(); if (cudaSuccess != (e = cudaGetLastError())) { fprintf(stderr, "%s: %d\n", msg, e); fprintf(stderr, "%s\n", cudaGetErrorString(e)); diff --git a/src/cuda/microbench/Makefile b/src/cuda/microbench/Makefile index 60270d8c7..babee2801 100644 --- a/src/cuda/microbench/Makefile +++ b/src/cuda/microbench/Makefile @@ -1,5 +1,5 @@ -ifeq ($(GPUAPPS_SETUP_ENVIRONMENT_WAS_RUN), 0) -$(error You must run "source setup_environment before calling make") +ifneq ($(GPUAPPS_SETUP_ENVIRONMENT_WAS_RUN),1) +$(error You must run "source setup_environment" before calling make) endif GENCODE_SM10 := -gencode=arch=compute_10,code=\"sm_10,compute_10\" @@ -11,6 +11,9 @@ GENCODE_SM50 := -gencode=arch=compute_50,code=\"sm_50,compute_50\" GENCODE_SM60 := -gencode=arch=compute_60,code=\"sm_60,compute_60\" GENCODE_SM62 := -gencode=arch=compute_62,code=\"sm_62,compute_62\" +cuda-13: cuda-12 + echo "Currently no uBench designed for 13" + cuda-12: cuda-11 echo "Currently no uBench designed for 12" @@ -40,4 +43,4 @@ cuda-4: echo "Currently no uBench designed for 4" $(BINDIR)/$(BINSUBDIR)/microbench-oo-vfunc-test: oo-vfunc-test.cu - nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(NVCC_ADDITIONAL_ARGS) oo-vfunc-test.cu -o $(BINDIR)/$(BINSUBDIR)/microbench-oo-vfunc-test + nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(NVCC_ADDITIONAL_ARGS) oo-vfunc-test.cu -o $(BINDIR)/$(BINSUBDIR)/microbench-oo-vfunc-test diff --git a/src/cuda/pannotia/bc/BC.cu b/src/cuda/pannotia/bc/BC.cu index 13e55ceca..45d60316a 100644 --- a/src/cuda/pannotia/bc/BC.cu +++ b/src/cuda/pannotia/bc/BC.cu @@ -239,7 +239,7 @@ int main(int argc, char **argv) } while (stop) ; - cudaThreadSynchronize(); + cudaDeviceSynchronize(); // Traverse back from the deepest part of the tree while (dist) { @@ -251,10 +251,10 @@ int main(int argc, char **argv) // Back one level dist--; } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); timer4 = gettime(); // Copy back the results for the bc array diff --git a/src/cuda/pannotia/bc/Makefile b/src/cuda/pannotia/bc/Makefile index c85d696cb..9f475e138 100644 --- a/src/cuda/pannotia/bc/Makefile +++ b/src/cuda/pannotia/bc/Makefile @@ -13,9 +13,9 @@ CUSRC = BC.cu EXECUTABLE = $(BINDIR)/$(BINSUBDIR)/bc #@echo $EXECUTABLE OPTS = -O3 -CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) -INC = -I$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/common/inc -I$(CUDA_INSTALL_PATH)/include -LIBS = -L$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/lib -lcutil_x86_64 -lcudart +CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) +INC = -I$(GPUAPPS_SDK_INC) -I$(CUDA_INSTALL_PATH)/include +LIBS = -L$(GPUAPPS_SDK_LIB) -lcutil_$(shell uname -m) -lcudart OBJS = $(notdir $(CPPSRC:.cpp=.o)) diff --git a/src/cuda/pannotia/color/Makefile b/src/cuda/pannotia/color/Makefile index 36efcb9b9..617c73464 100644 --- a/src/cuda/pannotia/color/Makefile +++ b/src/cuda/pannotia/color/Makefile @@ -20,9 +20,9 @@ else ifeq ($(VARIANT),MAXMIN) CUSRC += coloring_maxmin.cu endif OPTS = -O3 -CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) -INC = -I$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/common/inc -I$(CUDA_INSTALL_PATH)/include -LIBS = -L$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/lib -lcutil_x86_64 -lcudart +CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) +INC = -I$(GPUAPPS_SDK_INC) -I$(CUDA_INSTALL_PATH)/include +LIBS = -L$(GPUAPPS_SDK_LIB) -lcutil_$(shell uname -m) -lcudart OBJS = $(notdir $(CPPSRC:.cpp=.o)) diff --git a/src/cuda/pannotia/color/coloring_max.cu b/src/cuda/pannotia/color/coloring_max.cu index ffe88d919..e779f06aa 100644 --- a/src/cuda/pannotia/color/coloring_max.cu +++ b/src/cuda/pannotia/color/coloring_max.cu @@ -246,7 +246,7 @@ int main(int argc, char **argv) graph_color++; } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); double timer4 = gettime(); diff --git a/src/cuda/pannotia/color/coloring_maxmin.cu b/src/cuda/pannotia/color/coloring_maxmin.cu index 5af09e81b..36a6db8ab 100644 --- a/src/cuda/pannotia/color/coloring_maxmin.cu +++ b/src/cuda/pannotia/color/coloring_maxmin.cu @@ -249,7 +249,7 @@ int main(int argc, char **argv) graph_color = graph_color + 2; } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); double timer4 = gettime(); diff --git a/src/cuda/pannotia/fw/Floyd-Warshall-Block.cu b/src/cuda/pannotia/fw/Floyd-Warshall-Block.cu index 7c356ecb2..7f96cc8bf 100644 --- a/src/cuda/pannotia/fw/Floyd-Warshall-Block.cu +++ b/src/cuda/pannotia/fw/Floyd-Warshall-Block.cu @@ -176,7 +176,7 @@ int main(int argc, char **argv) floydwarshall_strip_blocks_y<<>>(dist_d, blk, dim); floydwarshall_remaining_blocks<<>>(dist_d, blk, dim); } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); double timer4 = gettime(); err = cudaMemcpy(result, dist_d, dim * dim * sizeof(int), cudaMemcpyDeviceToHost); diff --git a/src/cuda/pannotia/fw/Floyd-Warshall.cu b/src/cuda/pannotia/fw/Floyd-Warshall.cu index 8379a2f9c..30ca5b960 100644 --- a/src/cuda/pannotia/fw/Floyd-Warshall.cu +++ b/src/cuda/pannotia/fw/Floyd-Warshall.cu @@ -174,7 +174,7 @@ int main(int argc, char **argv) for (int k = 1; k < dim && k < MAX_ITERS; k++) { floydwarshall <<>>(dist_d, next_d, dim, k); } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); double timer4 = gettime(); err = cudaMemcpy(result, dist_d, dim * dim * sizeof(int), cudaMemcpyDeviceToHost); diff --git a/src/cuda/pannotia/fw/Makefile b/src/cuda/pannotia/fw/Makefile index 218f972f4..93d92960c 100644 --- a/src/cuda/pannotia/fw/Makefile +++ b/src/cuda/pannotia/fw/Makefile @@ -20,9 +20,9 @@ else ifeq ($(VARIANT),BLOCK) CUSRC += Floyd-Warshall-Block.cu endif OPTS = -O3 -CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) -INC = -I$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/common/inc -I$(CUDA_INSTALL_PATH)/include -LIBS = -L$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/lib -lcutil_x86_64 -lcudart +CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) +INC = -I$(GPUAPPS_SDK_INC) -I$(CUDA_INSTALL_PATH)/include +LIBS = -L$(GPUAPPS_SDK_LIB) -lcutil_$(shell uname -m) -lcudart OBJS = $(notdir $(CPPSRC:.cpp=.o)) diff --git a/src/cuda/pannotia/mis/Makefile b/src/cuda/pannotia/mis/Makefile index f2fb10917..4a584a2d8 100644 --- a/src/cuda/pannotia/mis/Makefile +++ b/src/cuda/pannotia/mis/Makefile @@ -11,9 +11,9 @@ CPPSRC = ../graph_parser/util.cpp ../graph_parser/parse.cpp CUSRC = mis.cu EXECUTABLE = $(BINDIR)/$(BINSUBDIR)/mis OPTS = -O3 -CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) -INC = -I$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/common/inc -I$(CUDA_INSTALL_PATH)/include -LIBS = -L$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/lib -lcutil_x86_64 -lcudart +CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) +INC = -I$(GPUAPPS_SDK_INC) -I$(CUDA_INSTALL_PATH)/include +LIBS = -L$(GPUAPPS_SDK_LIB) -lcutil_$(shell uname -m) -lcudart OBJS = $(notdir $(CPPSRC:.cpp=.o)) diff --git a/src/cuda/pannotia/mis/mis.cu b/src/cuda/pannotia/mis/mis.cu index 895a081e6..d617b1e21 100644 --- a/src/cuda/pannotia/mis/mis.cu +++ b/src/cuda/pannotia/mis/mis.cu @@ -219,7 +219,7 @@ int main(int argc, char **argv) // Launch the initialization kernel init <<>>(s_array_d, c_array_d, c_array_u_d, num_nodes, num_edges); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); err = cudaGetLastError(); if (err != cudaSuccess) { fprintf(stderr, "ERROR: init kernel (%s)\n", cudaGetErrorString(err)); @@ -263,7 +263,7 @@ int main(int argc, char **argv) } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); err = cudaMemcpy(s_array, s_array_d, num_nodes * sizeof(int), cudaMemcpyDeviceToHost); if (err != cudaSuccess) { diff --git a/src/cuda/pannotia/pagerank/Makefile b/src/cuda/pannotia/pagerank/Makefile index fc37e2f13..4ed785e87 100644 --- a/src/cuda/pannotia/pagerank/Makefile +++ b/src/cuda/pannotia/pagerank/Makefile @@ -20,9 +20,9 @@ else ifeq ($(VARIANT),SPMV) CUSRC += pagerank_spmv.cu endif OPTS = -O3 -CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) -INC = -I$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/common/inc -I$(CUDA_INSTALL_PATH)/include -LIBS = -L$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/lib -lcutil_x86_64 -lcudart +CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) +INC = -I$(GPUAPPS_SDK_INC) -I$(CUDA_INSTALL_PATH)/include +LIBS = -L$(GPUAPPS_SDK_LIB) -lcutil_$(shell uname -m) -lcudart OBJS = $(notdir $(CPPSRC:.cpp=.o)) diff --git a/src/cuda/pannotia/pagerank/pagerank.cu b/src/cuda/pannotia/pagerank/pagerank.cu index 1c3ac82fa..bd01b3a03 100644 --- a/src/cuda/pannotia/pagerank/pagerank.cu +++ b/src/cuda/pannotia/pagerank/pagerank.cu @@ -188,7 +188,7 @@ int main(int argc, char **argv) // Launch the initialization kernel inibuffer <<>>(row_d, pagerank1_d, pagerank2_d, num_nodes, num_edges); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); err = cudaGetLastError(); if (err != cudaSuccess) { fprintf(stderr, "ERROR: cudaLaunch failed (%s)\n", cudaGetErrorString(err)); @@ -205,7 +205,7 @@ int main(int argc, char **argv) pagerank2 <<>>(row_d, col_d, data_d, pagerank1_d, pagerank2_d, num_nodes, num_edges); } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); double timer4 = gettime(); diff --git a/src/cuda/pannotia/pagerank/pagerank_spmv.cu b/src/cuda/pannotia/pagerank/pagerank_spmv.cu index ed2725e86..fc4db2d54 100644 --- a/src/cuda/pannotia/pagerank/pagerank_spmv.cu +++ b/src/cuda/pannotia/pagerank/pagerank_spmv.cu @@ -193,7 +193,7 @@ int main(int argc, char **argv) // Launch the initialization kernel inibuffer <<>>(pagerank1_d, pagerank2_d, num_nodes); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); err = cudaGetLastError(); if (err != cudaSuccess) { fprintf(stderr, "ERROR: cudaLaunch failed (%s)\n", cudaGetErrorString(err)); @@ -203,7 +203,7 @@ int main(int argc, char **argv) // Initialize the CSR inicsr <<>>(row_d, col_d, data_d, col_cnt_d, num_nodes, num_edges); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); err = cudaGetLastError(); if (err != cudaSuccess) { fprintf(stderr, "ERROR: cudaLaunch failed (%s)\n", cudaGetErrorString(err)); @@ -220,7 +220,7 @@ int main(int argc, char **argv) // Launch pagerank kernel 2 pagerank2 <<>>(pagerank1_d, pagerank2_d, num_nodes); } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); double timer4 = gettime(); diff --git a/src/cuda/pannotia/sssp/Makefile b/src/cuda/pannotia/sssp/Makefile index 445c2802d..e5400acc5 100644 --- a/src/cuda/pannotia/sssp/Makefile +++ b/src/cuda/pannotia/sssp/Makefile @@ -20,9 +20,9 @@ else ifeq ($(VARIANT),ELL) CUSRC += sssp_ell.cu endif OPTS = -O3 -CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) -INC = -I$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/common/inc -I$(CUDA_INSTALL_PATH)/include -LIBS = -L$(NVIDIA_COMPUTE_SDK_LOCATION)/../4.2/C/lib -lcutil_x86_64 -lcudart +CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) +INC = -I$(GPUAPPS_SDK_INC) -I$(CUDA_INSTALL_PATH)/include +LIBS = -L$(GPUAPPS_SDK_LIB) -lcutil_$(shell uname -m) -lcudart OBJS = $(notdir $(CPPSRC:.cpp=.o)) diff --git a/src/cuda/pannotia/sssp/sssp_csr.cu b/src/cuda/pannotia/sssp/sssp_csr.cu index baefccbeb..2830f1e99 100644 --- a/src/cuda/pannotia/sssp/sssp_csr.cu +++ b/src/cuda/pannotia/sssp/sssp_csr.cu @@ -199,7 +199,7 @@ int main(int argc, char **argv) // Launch the initialization kernel vector_init <<>>(vector_d1, vector_d2, sourceVertex, num_nodes); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); err = cudaGetLastError(); if (err != cudaSuccess) { fprintf(stderr, "ERROR: vector_init failed (%s)\n", cudaGetErrorString(err)); @@ -245,7 +245,7 @@ int main(int argc, char **argv) } cnt++; } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); double timer4 = gettime(); // Read the cost_array back diff --git a/src/cuda/pannotia/sssp/sssp_ell.cu b/src/cuda/pannotia/sssp/sssp_ell.cu index 9c0ff80d5..dfbd141cc 100644 --- a/src/cuda/pannotia/sssp/sssp_ell.cu +++ b/src/cuda/pannotia/sssp/sssp_ell.cu @@ -193,7 +193,7 @@ int main(int argc, char **argv) // Launch the initialization kernel vector_init <<>>(vector_d1, vector_d2, sourceVertex, num_nodes); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); err = cudaGetLastError(); if (err != cudaSuccess) { fprintf(stderr, "ERROR: vector_init failed (%s)\n", cudaGetErrorString(err)); @@ -239,7 +239,7 @@ int main(int argc, char **argv) } cnt++; } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); double timer4 = gettime(); // Read the cost_array back diff --git a/src/cuda/parboil/benchmarks/bfs/src/cuda/kernel.cu b/src/cuda/parboil/benchmarks/bfs/src/cuda/kernel.cu index addbd1a52..96ca5e200 100644 --- a/src/cuda/parboil/benchmarks/bfs/src/cuda/kernel.cu +++ b/src/cuda/parboil/benchmarks/bfs/src/cuda/kernel.cu @@ -35,8 +35,10 @@ UP_LIMIT are free to visit */ #include "config.h" -texture g_graph_node_ref; -texture g_graph_edge_ref; +/* Texture references were removed in CUDA 12; the host fills these handles + via cudaMemcpyToSymbol so the fetch sites below are unchanged. */ +__constant__ cudaTextureObject_t g_graph_node_ref; +__constant__ cudaTextureObject_t g_graph_edge_ref; // A group of local queues of node IDs, used by an entire thread block. // Multiple queues are used to reduce memory contention. @@ -152,11 +154,11 @@ visit_node(int pid, { g_color[pid] = BLACK; // Mark this node as visited int cur_cost = g_cost[pid]; // Look up shortest-path distance to this node - Node cur_node = tex1Dfetch(g_graph_node_ref,pid); + Node cur_node = tex1Dfetch(g_graph_node_ref,pid); // For each outgoing edge for(int i = cur_node.x; i < cur_node.y + cur_node.x; i++) { - Edge cur_edge = tex1Dfetch(g_graph_edge_ref,i); + Edge cur_edge = tex1Dfetch(g_graph_edge_ref,i); int id = cur_edge.x; int cost = cur_edge.y; cost += cur_cost; diff --git a/src/cuda/parboil/benchmarks/bfs/src/cuda/main.cu b/src/cuda/parboil/benchmarks/bfs/src/cuda/main.cu index 9b38cb551..85f72eca6 100644 --- a/src/cuda/parboil/benchmarks/bfs/src/cuda/main.cu +++ b/src/cuda/parboil/benchmarks/bfs/src/cuda/main.cu @@ -37,6 +37,23 @@ FILE *fp; typedef int2 Node; typedef int2 Edge; +static cudaTextureObject_t h_g_graph_node_ref = 0; +static cudaTextureObject_t h_g_graph_edge_ref = 0; + +static void bindInt2Texture(cudaTextureObject_t *out, void *ptr, size_t bytes) +{ + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeLinear; + resDesc.res.linear.devPtr = ptr; + resDesc.res.linear.desc = cudaCreateChannelDesc(); + resDesc.res.linear.sizeInBytes = bytes; + texDesc.readMode = cudaReadModeElementType; + cudaCreateTextureObject(out, &resDesc, &texDesc, NULL); +} + #include "kernel.cu" const int h_top = 1; const int zero = 0; @@ -134,12 +151,14 @@ int main(int argc, char** argv) cudaMemcpy(d_cost, h_cost, sizeof(int)*num_of_nodes, cudaMemcpyHostToDevice); //bind the texture memory with global memory - cudaBindTexture(0,g_graph_node_ref,d_graph_nodes, sizeof(Node)*num_of_nodes); - cudaBindTexture(0,g_graph_edge_ref,d_graph_edges,sizeof(Edge)*num_of_edges); + bindInt2Texture(&h_g_graph_node_ref, d_graph_nodes, sizeof(Node)*num_of_nodes); + cudaMemcpyToSymbol(g_graph_node_ref, &h_g_graph_node_ref, sizeof(h_g_graph_node_ref)); + bindInt2Texture(&h_g_graph_edge_ref, d_graph_edges, sizeof(Edge)*num_of_edges); + cudaMemcpyToSymbol(g_graph_edge_ref, &h_g_graph_edge_ref, sizeof(h_g_graph_edge_ref)); printf("Starting GPU kernel\n"); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_KERNEL); int num_of_blocks; @@ -257,15 +276,15 @@ int main(int argc, char** argv) return 0; } } while(1); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COPY); printf("GPU kernel done\n"); // copy result from device to host cudaMemcpy(h_cost, d_cost, sizeof(int)*num_of_nodes, cudaMemcpyDeviceToHost); cudaMemcpy(color, d_color, sizeof(int)*num_of_nodes, cudaMemcpyDeviceToHost); - cudaUnbindTexture(g_graph_node_ref); - cudaUnbindTexture(g_graph_edge_ref); + cudaDestroyTextureObject(h_g_graph_node_ref); + cudaDestroyTextureObject(h_g_graph_edge_ref); cudaFree(d_graph_nodes); cudaFree(d_graph_edges); diff --git a/src/cuda/parboil/benchmarks/bfs/src/cuda_base/main.cu b/src/cuda/parboil/benchmarks/bfs/src/cuda_base/main.cu index 6e479d7cd..4047b7625 100644 --- a/src/cuda/parboil/benchmarks/bfs/src/cuda_base/main.cu +++ b/src/cuda/parboil/benchmarks/bfs/src/cuda_base/main.cu @@ -132,7 +132,7 @@ int main(int argc, char** argv) cudaBindTexture(0,g_graph_edge_ref,d_graph_edges,sizeof(Edge)*num_of_edges); printf("Starting GPU kernel\n"); - (cudaThreadSynchronize()); + (cudaDeviceSynchronize()); pb_SwitchToTimer(&timers, pb_TimerID_KERNEL); int num_of_blocks; @@ -182,7 +182,7 @@ int main(int argc, char** argv) k++; } while(1); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COPY); printf("GPU kernel done\n"); diff --git a/src/cuda/parboil/benchmarks/bfs/tools/compare-output b/src/cuda/parboil/benchmarks/bfs/tools/compare-output index e7a55a212..a909f7920 100755 --- a/src/cuda/parboil/benchmarks/bfs/tools/compare-output +++ b/src/cuda/parboil/benchmarks/bfs/tools/compare-output @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # (c) Copyright 2007 The Board of Trustees of the University of Illinois. @@ -8,7 +8,7 @@ import itertools import filecompare as fc import textfilecompare as tfc -ref = file(sys.argv[1], "r") +ref = open(sys.argv[1], "r") size = int(ref.readline()) diff --git a/src/cuda/parboil/benchmarks/cutcp/src/cuda/cutoff6overlap.cu b/src/cuda/parboil/benchmarks/cutcp/src/cuda/cutoff6overlap.cu index 903682aff..4e550ce01 100644 --- a/src/cuda/parboil/benchmarks/cutcp/src/cuda/cutoff6overlap.cu +++ b/src/cuda/parboil/benchmarks/cutcp/src/cuda/cutoff6overlap.cu @@ -618,7 +618,7 @@ extern "C" int gpu_compute_cutoff_potential_lattice6overlap( cudaStreamSynchronize(cutoffstream); CUERR; - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaStreamDestroy(cutoffstream); printf("Finished CUDA kernel calls \n"); diff --git a/src/cuda/parboil/benchmarks/cutcp/tools/compare-output b/src/cuda/parboil/benchmarks/cutcp/tools/compare-output index ae14a9451..e23862ba1 100755 --- a/src/cuda/parboil/benchmarks/cutcp/tools/compare-output +++ b/src/cuda/parboil/benchmarks/cutcp/tools/compare-output @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # (c) Copyright 2008-2010 The Board of Trustees of the University of Illinois. @@ -40,4 +40,4 @@ comparison = fc.Sequence([ # End of file fc.Compare(bfc.eof)]) -fc.default_main(comparison) +fc.default_main(comparison, mode="rb") diff --git a/src/cuda/parboil/benchmarks/lbm/src/cuda/lbm.cu b/src/cuda/parboil/benchmarks/lbm/src/cuda/lbm.cu index d78cbecf9..93ef2822b 100644 --- a/src/cuda/parboil/benchmarks/lbm/src/cuda/lbm.cu +++ b/src/cuda/parboil/benchmarks/lbm/src/cuda/lbm.cu @@ -128,7 +128,7 @@ void CUDA_LBM_initializeGrid( float** d_grid, float** h_grid ) { void CUDA_LBM_getDeviceGrid( float** d_grid, float** h_grid ) { const size_t size = TOTAL_PADDED_CELLS*N_CELL_ENTRIES*sizeof( float ) + 2*TOTAL_MARGIN*sizeof( float ); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CUDA_ERRCK; cudaMemcpy(*h_grid - REAL_MARGIN, *d_grid - REAL_MARGIN, size, cudaMemcpyDeviceToHost); CUDA_ERRCK; diff --git a/src/cuda/parboil/benchmarks/lbm/src/cuda_base/lbm.cu b/src/cuda/parboil/benchmarks/lbm/src/cuda_base/lbm.cu index 24c040fc2..0218f903f 100644 --- a/src/cuda/parboil/benchmarks/lbm/src/cuda_base/lbm.cu +++ b/src/cuda/parboil/benchmarks/lbm/src/cuda_base/lbm.cu @@ -128,7 +128,7 @@ void CUDA_LBM_initializeGrid( float** d_grid, float** h_grid ) { void CUDA_LBM_getDeviceGrid( float** d_grid, float** h_grid ) { const size_t size = TOTAL_PADDED_CELLS*N_CELL_ENTRIES*sizeof( float ) + 2*TOTAL_MARGIN*sizeof( float ); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CUDA_ERRCK; cudaMemcpy(*h_grid - REAL_MARGIN, *d_grid - REAL_MARGIN, size, cudaMemcpyDeviceToHost); CUDA_ERRCK; diff --git a/src/cuda/parboil/benchmarks/lbm/tools/compare-output b/src/cuda/parboil/benchmarks/lbm/tools/compare-output index 4fd4802e6..83853e3e5 100755 --- a/src/cuda/parboil/benchmarks/lbm/tools/compare-output +++ b/src/cuda/parboil/benchmarks/lbm/tools/compare-output @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # (c) Copyright 2007 The Board of Trustees of the University of Illinois. @@ -34,4 +34,4 @@ comparison = fc.Then( fc.Compare(bfc.many_float(3*150*120*120), equal=compare_floats, message=reference_err), fc.Compare(bfc.eof)) -fc.default_main(comparison) +fc.default_main(comparison, mode="rb") diff --git a/src/cuda/parboil/benchmarks/mri-gridding/tools/compare-output b/src/cuda/parboil/benchmarks/mri-gridding/tools/compare-output index 175b8d647..5404568e2 100755 --- a/src/cuda/parboil/benchmarks/mri-gridding/tools/compare-output +++ b/src/cuda/parboil/benchmarks/mri-gridding/tools/compare-output @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import sys @@ -9,10 +9,10 @@ tol_ratio = 0.002 def Exit(b): if b: - print "Pass" + print("Pass") sys.exit(0) else: - print "Mismatch" + print("Mismatch") sys.exit(1) def Run(): diff --git a/src/cuda/parboil/benchmarks/mri-q/src/cuda/main.cu b/src/cuda/parboil/benchmarks/mri-q/src/cuda/main.cu index 094c496f7..58b3d38e3 100644 --- a/src/cuda/parboil/benchmarks/mri-q/src/cuda/main.cu +++ b/src/cuda/parboil/benchmarks/mri-q/src/cuda/main.cu @@ -124,12 +124,12 @@ main (int argc, char *argv[]) { cudaMalloc((void **)&phiMag_d, numK * sizeof(float)); CUDA_ERRCK; - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_KERNEL); computePhiMag_GPU(numK, phiR_d, phiI_d, phiMag_d); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COPY); cleanupMemoryGPU(numK, sizeof(float), phiMag_d, phiMag); @@ -166,12 +166,12 @@ main (int argc, char *argv[]) { CUDA_ERRCK; cudaMemset((void *)Qi_d, 0, numX * sizeof(float)); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_KERNEL); computeQ_GPU(numK, numX, x_d, y_d, z_d, kVals, Qr_d, Qi_d); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COPY); cudaFree(x_d); diff --git a/src/cuda/parboil/benchmarks/mri-q/tools/compare-output b/src/cuda/parboil/benchmarks/mri-q/tools/compare-output index 013522d9a..4b9b5beee 100755 --- a/src/cuda/parboil/benchmarks/mri-q/tools/compare-output +++ b/src/cuda/parboil/benchmarks/mri-q/tools/compare-output @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # (c) Copyright 2007 The Board of Trustees of the University of Illinois. @@ -21,7 +21,7 @@ def compare_floats(ref_list, cmp_list): for (r, c) in zip(ref_list, cmp_list): diff = abs(r - c) if not (diff <= abstol or diff < 0.002 * abs(r)): - print r, c + print(r, c) # Floats mismatch return False @@ -42,4 +42,4 @@ comparison = fc.Then( fc.Bind(fc.Compare(bfc.uint32, message=size_err), compare_array), fc.Compare(bfc.eof)) -fc.default_main(comparison) +fc.default_main(comparison, mode="rb") diff --git a/src/cuda/parboil/benchmarks/sad/src/cuda/main.cu b/src/cuda/parboil/benchmarks/sad/src/cuda/main.cu index 601f90457..041c21f96 100644 --- a/src/cuda/parboil/benchmarks/sad/src/cuda/main.cu +++ b/src/cuda/parboil/benchmarks/sad/src/cuda/main.cu @@ -297,7 +297,8 @@ main(int argc, char **argv) pb_SwitchToTimer(&timers, pb_TimerID_COPY); cudaMalloc((void **)&d_cur_image, image_size_bytes); CUDA_ERRCK - cudaMallocArray(&ref_ary, &get_ref().channelDesc, + cudaChannelFormatDesc refChannelDesc = sad_ref_channel_desc(); + cudaMallocArray(&ref_ary, &refChannelDesc, ref_image->width, ref_image->height); CUDA_ERRCK @@ -315,7 +316,7 @@ main(int argc, char **argv) ref_image->height, cudaMemcpyHostToDevice); CUDA_ERRCK - cudaBindTextureToArray(get_ref(), ref_ary); + sad_bind_ref(ref_ary); CUDA_ERRCK /* Allocate SAD data on the device */ @@ -365,7 +366,7 @@ main(int argc, char **argv) /* Free GPU memory */ cudaFree(d_sads); CUDA_ERRCK - cudaUnbindTexture(get_ref()); + sad_unbind_ref(); CUDA_ERRCK cudaFreeArray(ref_ary); CUDA_ERRCK diff --git a/src/cuda/parboil/benchmarks/sad/src/cuda/sad4.cu b/src/cuda/parboil/benchmarks/sad/src/cuda/sad4.cu index a4d245609..5dad29b42 100644 --- a/src/cuda/parboil/benchmarks/sad/src/cuda/sad4.cu +++ b/src/cuda/parboil/benchmarks/sad/src/cuda/sad4.cu @@ -40,7 +40,11 @@ __shared__ unsigned short frame_loc[THREADS_W * THREADS_H * 16]; /* The part of the reference image that is in the search range */ -texture ref; +/* Texture references were removed in CUDA 12. The object lives here and the + host binds it through sad_bind_ref(), preserving the original reason for + get_ref(): the texture is used here but set up from main.cu. */ +__constant__ cudaTextureObject_t ref; +static cudaTextureObject_t h_ref = 0; /* The local SAD array on the device. This is an array of short ints. It is * interpreted as an array of 8-byte data for global data transfers. */ @@ -144,28 +148,28 @@ __global__ void mb_sad_calc(unsigned short *blk_sad, /* 4x4 SAD computation */ for(int y=0; y<4; y++) { int t; - t = tex2D(ref, search_off_x, search_off_y + y); + t = tex2D(ref, search_off_x, search_off_y + y); sad1 += abs(t - FRAME_GET(cur_o, 0, y)); - t = tex2D(ref, search_off_x + 1, search_off_y + y); + t = tex2D(ref, search_off_x + 1, search_off_y + y); sad1 += abs(t - FRAME_GET(cur_o, 1, y)); sad2 += abs(t - FRAME_GET(cur_o, 0, y)); - t = tex2D(ref, search_off_x + 2, search_off_y + y); + t = tex2D(ref, search_off_x + 2, search_off_y + y); sad1 += abs(t - FRAME_GET(cur_o, 2, y)); sad2 += abs(t - FRAME_GET(cur_o, 1, y)); sad3 += abs(t - FRAME_GET(cur_o, 0, y)); - t = tex2D(ref, search_off_x + 3, search_off_y + y); + t = tex2D(ref, search_off_x + 3, search_off_y + y); sad1 += abs(t - FRAME_GET(cur_o, 3, y)); sad2 += abs(t - FRAME_GET(cur_o, 2, y)); sad3 += abs(t - FRAME_GET(cur_o, 1, y)); - t = tex2D(ref, search_off_x + 4, search_off_y + y); + t = tex2D(ref, search_off_x + 4, search_off_y + y); sad2 += abs(t - FRAME_GET(cur_o, 3, y)); sad3 += abs(t - FRAME_GET(cur_o, 2, y)); - t = tex2D(ref, search_off_x + 5, search_off_y + y); + t = tex2D(ref, search_off_x + 5, search_off_y + y); sad3 += abs(t - FRAME_GET(cur_o, 3, y)); } @@ -217,7 +221,28 @@ __global__ void mb_sad_calc(unsigned short *blk_sad, } } -texture &get_ref(void) +cudaChannelFormatDesc sad_ref_channel_desc(void) { - return ref; + return cudaCreateChannelDesc(); +} + +void sad_bind_ref(cudaArray_t ary) +{ + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeArray; + resDesc.res.array.array = ary; + texDesc.readMode = cudaReadModeElementType; + cudaCreateTextureObject(&h_ref, &resDesc, &texDesc, NULL); + cudaMemcpyToSymbol(ref, &h_ref, sizeof(h_ref)); +} + +void sad_unbind_ref(void) +{ + if (h_ref) { + cudaDestroyTextureObject(h_ref); + h_ref = 0; + } } diff --git a/src/cuda/parboil/benchmarks/sad/src/cuda/sad4.h b/src/cuda/parboil/benchmarks/sad/src/cuda/sad4.h index a2f5c1832..9901ecf87 100644 --- a/src/cuda/parboil/benchmarks/sad/src/cuda/sad4.h +++ b/src/cuda/parboil/benchmarks/sad/src/cuda/sad4.h @@ -46,7 +46,9 @@ __global__ void mb_sad_calc(unsigned short*, unsigned short*, int, int); -/* A function to get a reference to the "ref" texture, because sharing - * of textures between files isn't really supported. */ -texture &get_ref(void); +/* The "ref" texture object lives in sad4.cu, because sharing of textures + * between files isn't really supported. */ +cudaChannelFormatDesc sad_ref_channel_desc(void); +void sad_bind_ref(cudaArray_t ary); +void sad_unbind_ref(void); diff --git a/src/cuda/parboil/benchmarks/sad/tools/compare-output b/src/cuda/parboil/benchmarks/sad/tools/compare-output index bc05bcbe9..de13981fe 100755 --- a/src/cuda/parboil/benchmarks/sad/tools/compare-output +++ b/src/cuda/parboil/benchmarks/sad/tools/compare-output @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # (c) Copyright 2007 The Board of Trustees of the University of Illinois. @@ -33,4 +33,4 @@ comparison = fc.Then( compare_frame_SADs(n))), fc.Compare(bfc.eof)) -fc.default_main(comparison) +fc.default_main(comparison, mode="rb") diff --git a/src/cuda/parboil/benchmarks/sad/tools/compute-one-sad.py b/src/cuda/parboil/benchmarks/sad/tools/compute-one-sad.py index 555d26251..e0c8fd57c 100755 --- a/src/cuda/parboil/benchmarks/sad/tools/compute-one-sad.py +++ b/src/cuda/parboil/benchmarks/sad/tools/compute-one-sad.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # (c) Copyright 2007 The Board of Trustees of the University of Illinois. @@ -9,10 +9,11 @@ import binaryfilecompare as bfc class Img: - def __init__(self, (w, h), d): + def __init__(self, xxx_todo_changeme, d): + (w, h) = xxx_todo_changeme self.width = w - self.height = h - self.data = d + self.height = h + self.data = d def load_image(f): width = bfc.uint16(f) @@ -20,8 +21,8 @@ def load_image(f): lines = [bfc.many_uint16(width)(f) for n in range(height)] return Img((width, height), lines) -frm = load_image(file('input/default/frame.bin')) -ref = load_image(file('input/default/reference.bin')) +frm = load_image(open('input/default/frame.bin')) +ref = load_image(open('input/default/reference.bin')) def getpix(img, x, y): if x < 0: x = 0 @@ -36,10 +37,10 @@ def pixdif(x, y, xoff, yoff): # Compute 4x4 SADs for this search offset in the reference frame searchoff = (1,1) -print "Search position: %d" % (searchoff[0] + 16 + 33 * (searchoff[1] + 16)) +print(("Search position: %d" % (searchoff[0] + 16 + 33 * (searchoff[1] + 16)))) -print [[sum([sum([pixdif(4*bx+x, 4*by+y, searchoff[0], searchoff[1]) +print([[sum([sum([pixdif(4*bx+x, 4*by+y, searchoff[0], searchoff[1]) for x in range(4)]) for y in range(4)]) for bx in range(4)] - for by in range(4)] + for by in range(4)]) diff --git a/src/cuda/parboil/benchmarks/sgemm/src/cuda/io.cc b/src/cuda/parboil/benchmarks/sgemm/src/cuda/io.cc index 793d9e9fd..3a8f026eb 100644 --- a/src/cuda/parboil/benchmarks/sgemm/src/cuda/io.cc +++ b/src/cuda/parboil/benchmarks/sgemm/src/cuda/io.cc @@ -34,6 +34,7 @@ bool readColMajorMatrixFile(const char *fn, int &nr_row, int &nr_col, std::vecto } v.pop_back(); // remove the duplicated last element + return true; } bool writeColMajorMatrixFile(const char *fn, int nr_row, int nr_col, std::vector&v) diff --git a/src/cuda/parboil/benchmarks/sgemm/src/cuda_base/main.cu b/src/cuda/parboil/benchmarks/sgemm/src/cuda_base/main.cu index b7d1e03c0..cdc33de28 100644 --- a/src/cuda/parboil/benchmarks/sgemm/src/cuda_base/main.cu +++ b/src/cuda/parboil/benchmarks/sgemm/src/cuda_base/main.cu @@ -84,7 +84,7 @@ main (int argc, char *argv[]) { cudaMemcpy(dA, &matA.front(), A_sz, cudaMemcpyHostToDevice); cudaMemcpy(dB, &matBT.front(), B_sz, cudaMemcpyHostToDevice); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer( &timers, pb_TimerID_KERNEL ); @@ -92,7 +92,7 @@ main (int argc, char *argv[]) { basicSgemm('N', 'T', matArow, matBcol, matAcol, 1.0f, \ dA, matArow, dB, matBcol, 0.0f, dC, matArow); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); if (params->outFile) { pb_SwitchToTimer( &timers, pb_TimerID_COPY ); diff --git a/src/cuda/parboil/benchmarks/sgemm/tools/compare-output b/src/cuda/parboil/benchmarks/sgemm/tools/compare-output index a77cec2bc..7ba85a39a 100755 --- a/src/cuda/parboil/benchmarks/sgemm/tools/compare-output +++ b/src/cuda/parboil/benchmarks/sgemm/tools/compare-output @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # (c) Copyright 2010 The Board of Trustees of the University of Illinois. @@ -12,9 +12,9 @@ def compare_floats(ref_list, cmp_list): # Lists should be the same length if len(ref_list) != len(cmp_list): - print "Different in length" - print "ref=" + str(len(ref_list)) +" "+ str(ref_list[-2]) - print "cmp=" + str(len(cmp_list)) +" "+ str(cmp_list[-1]) + print("Different in length") + print("ref=" + str(len(ref_list)) +" "+ str(ref_list[-2])) + print("cmp=" + str(len(cmp_list)) +" "+ str(cmp_list[-1])) return False diff --git a/src/cuda/parboil/benchmarks/spmv/src/cuda/main.cu b/src/cuda/parboil/benchmarks/spmv/src/cuda/main.cu index 67062d98f..d2353d4cb 100644 --- a/src/cuda/parboil/benchmarks/spmv/src/cuda/main.cu +++ b/src/cuda/parboil/benchmarks/spmv/src/cuda/main.cu @@ -121,7 +121,7 @@ int main(int argc, char** argv) { cudaMemcpyToSymbol(jds_ptr_int, h_ptr, depth*sizeof(int)); cudaMemcpyToSymbol(sh_zcnt_int, h_nzcnt,nzcnt_len*sizeof(int)); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE); unsigned int grid; unsigned int block; @@ -140,13 +140,13 @@ int main(int argc, char** argv) { CUERR // check and clear any existing errors - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COPY); //HtoD memory copy cudaMemcpy(h_Ax_vector, d_Ax_vector,dim*sizeof(float), cudaMemcpyDeviceToHost); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaFree(d_data); cudaFree(d_indices); diff --git a/src/cuda/parboil/benchmarks/spmv/src/cuda/spmv_jds.h b/src/cuda/parboil/benchmarks/spmv/src/cuda/spmv_jds.h index 075c23946..b682fd231 100644 --- a/src/cuda/parboil/benchmarks/spmv/src/cuda/spmv_jds.h +++ b/src/cuda/parboil/benchmarks/spmv/src/cuda/spmv_jds.h @@ -10,7 +10,8 @@ //TEXTURE memory -texture tex_x_float; +/* tex_x_float is unused in this variant; the texture version lives in + src/cuda_tex. Texture references were removed in CUDA 12. */ //constant memory __constant__ int jds_ptr_int[5000]; diff --git a/src/cuda/parboil/benchmarks/spmv/src/cuda_base/main.cu b/src/cuda/parboil/benchmarks/spmv/src/cuda_base/main.cu index 214264cb2..b4b8ee5ce 100644 --- a/src/cuda/parboil/benchmarks/spmv/src/cuda_base/main.cu +++ b/src/cuda/parboil/benchmarks/spmv/src/cuda_base/main.cu @@ -130,7 +130,7 @@ int main(int argc, char** argv) { cudaMemcpyToSymbol(jds_ptr_int, h_ptr, depth*sizeof(int)); cudaMemcpyToSymbol(sh_zcnt_int, h_nzcnt,nzcnt_len*sizeof(int)); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE); unsigned int grid; unsigned int block; @@ -149,13 +149,13 @@ int main(int argc, char** argv) { CUERR // check and clear any existing errors - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COPY); //HtoD memory copy cudaMemcpy(h_Ax_vector, d_Ax_vector,dim*sizeof(float), cudaMemcpyDeviceToHost); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaFree(d_data); cudaFree(d_indices); cudaFree(d_ptr); diff --git a/src/cuda/parboil/benchmarks/spmv/src/cuda_base_tex/main.cu b/src/cuda/parboil/benchmarks/spmv/src/cuda_base_tex/main.cu index a5fb25807..176cfc066 100644 --- a/src/cuda/parboil/benchmarks/spmv/src/cuda_base_tex/main.cu +++ b/src/cuda/parboil/benchmarks/spmv/src/cuda_base_tex/main.cu @@ -119,7 +119,7 @@ int main(int argc, char** argv) { cudaMemcpyToSymbol(jds_ptr_int, h_ptr, depth*sizeof(int)); cudaMemcpyToSymbol(sh_zcnt_int, h_nzcnt,nzcnt_len*sizeof(int)); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE); unsigned int grid; unsigned int block; @@ -143,13 +143,13 @@ int main(int argc, char** argv) { CUERR // check and clear any existing errors - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COPY); //HtoD memory copy cudaMemcpy(h_Ax_vector, d_Ax_vector,dim*sizeof(float), cudaMemcpyDeviceToHost); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaFree(d_data); cudaFree(d_indices); cudaFree(d_ptr); diff --git a/src/cuda/parboil/benchmarks/spmv/src/cuda_tex/main.cu b/src/cuda/parboil/benchmarks/spmv/src/cuda_tex/main.cu index d5baf7364..c8fa5d329 100644 --- a/src/cuda/parboil/benchmarks/spmv/src/cuda_tex/main.cu +++ b/src/cuda/parboil/benchmarks/spmv/src/cuda_tex/main.cu @@ -122,7 +122,7 @@ int main(int argc, char** argv) { cudaMemcpyToSymbol(jds_ptr_int, h_ptr, depth*sizeof(int)); cudaMemcpyToSymbol(sh_zcnt_int, h_nzcnt,nzcnt_len*sizeof(int)); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE); unsigned int grid; unsigned int block; @@ -144,13 +144,13 @@ int main(int argc, char** argv) { } CUERR // check and clear any existing errors - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COPY); //HtoD memory copy cudaMemcpy(h_Ax_vector, d_Ax_vector,dim*sizeof(float), cudaMemcpyDeviceToHost); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaFree(d_data); cudaFree(d_indices); cudaFree(d_ptr); diff --git a/src/cuda/parboil/benchmarks/spmv/tools/compare-output b/src/cuda/parboil/benchmarks/spmv/tools/compare-output index f404a7614..9abf78d66 100755 --- a/src/cuda/parboil/benchmarks/spmv/tools/compare-output +++ b/src/cuda/parboil/benchmarks/spmv/tools/compare-output @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # (c) Copyright 2007 The Board of Trustees of the University of Illinois. @@ -24,7 +24,7 @@ def compare_floats(ref_list, cmp_list): diff = abs(r - c) if not (diff <= abstol or diff < 0.002 * abs(r)): # Floats mismatch - print "Fail at row %d: (gold) %f != %f (computed)" % (row, r, c) + print("Fail at row %d: (gold) %f != %f (computed)" % (row, r, c)) num_printed_error = num_printed_error + 1 if (num_printed_error >= 10): break @@ -50,4 +50,4 @@ comparison = fc.Then( fc.Bind(fc.Compare(bfc.uint32, message=size_err), compare_array), fc.Compare(bfc.eof)) -fc.default_main(comparison) +fc.default_main(comparison, mode="rb") diff --git a/src/cuda/parboil/benchmarks/stencil/src/cuda_base/main.cu b/src/cuda/parboil/benchmarks/stencil/src/cuda_base/main.cu index 644525575..4b9f24740 100644 --- a/src/cuda/parboil/benchmarks/stencil/src/cuda_base/main.cu +++ b/src/cuda/parboil/benchmarks/stencil/src/cuda_base/main.cu @@ -104,7 +104,7 @@ int main(int argc, char** argv) { cudaMemcpy(d_Anext, d_A0, size*sizeof(float), cudaMemcpyDeviceToDevice); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE); //only use 1D thread block @@ -126,10 +126,10 @@ int main(int argc, char** argv) { d_A0 = d_Anext; d_Anext = d_temp; - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COPY); cudaMemcpy(h_Anext, d_Anext,size*sizeof(float), cudaMemcpyDeviceToHost); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaFree(d_A0); cudaFree(d_Anext); diff --git a/src/cuda/parboil/benchmarks/stencil/src/cuda_fermi/main.cu b/src/cuda/parboil/benchmarks/stencil/src/cuda_fermi/main.cu index 427418dc0..ed8d6266a 100644 --- a/src/cuda/parboil/benchmarks/stencil/src/cuda_fermi/main.cu +++ b/src/cuda/parboil/benchmarks/stencil/src/cuda_fermi/main.cu @@ -105,7 +105,7 @@ int main(int argc, char** argv) { cudaMemcpy(d_A0, h_A0, size*sizeof(float), cudaMemcpyHostToDevice); cudaMemcpy(d_Anext, d_A0, size*sizeof(float), cudaMemcpyDeviceToDevice); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE); //only use tx-by-ty threads @@ -131,10 +131,10 @@ int main(int argc, char** argv) { - cudaThreadSynchronize(); + cudaDeviceSynchronize(); pb_SwitchToTimer(&timers, pb_TimerID_COPY); cudaMemcpy(h_Anext, d_Anext,size*sizeof(float), cudaMemcpyDeviceToHost); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaFree(d_A0); cudaFree(d_Anext); diff --git a/src/cuda/parboil/benchmarks/stencil/tools/compare-output b/src/cuda/parboil/benchmarks/stencil/tools/compare-output index 45428c388..9f7b8d1cd 100755 --- a/src/cuda/parboil/benchmarks/stencil/tools/compare-output +++ b/src/cuda/parboil/benchmarks/stencil/tools/compare-output @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import sys @@ -9,10 +9,10 @@ tol_ratio = 0.002 def Exit(b): if b: - print "Pass" + print("Pass") sys.exit(0) else: - print "Mismatch" + print("Mismatch") sys.exit(1) def Run(): @@ -39,13 +39,13 @@ def Run(): hy.close() if lx != ly: - print "Reference and compare are different in size" + print("Reference and compare are different in size") Exit(False) if len(data_r) != 4 * lx: - print "Reference: sanity check failed" + print("Reference: sanity check failed") Exit(False) if len(data_c) != 4 * ly: - print "Compare: sanity check failed" + print("Compare: sanity check failed") Exit(False) for i in range(0, lx, 4): @@ -54,7 +54,7 @@ def Run(): diff = abs(r - c) if not (diff <= tol_diff or diff < tol_ratio * abs(r)): - print r, c, "at" , (i)%512, ((i)/512)%512, ((i)/512)/512 + print(r, c, "at" , (i)%512, ((i)/512)%512, ((i)/512)/512) Exit(False) Exit(True) diff --git a/src/cuda/parboil/benchmarks/tpacf/tools/compare-output b/src/cuda/parboil/benchmarks/tpacf/tools/compare-output index d21278fa8..14ba23a4c 100755 --- a/src/cuda/parboil/benchmarks/tpacf/tools/compare-output +++ b/src/cuda/parboil/benchmarks/tpacf/tools/compare-output @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # (c) Copyright 2007 The Board of Trustees of the University of Illinois. @@ -25,28 +25,28 @@ def compare_histograms(ref, cmp): return False - if (compare_bins(zip(ref[0:3],cmp[0:3]), 0.10, 3)): + if (compare_bins(list(zip(ref[0:3],cmp[0:3])), 0.10, 3)): return False #These bins are particularly sensitive to precision issues. #Going from DP to SP likely causes underflow for a large sample portion - if (compare_bins(zip(ref[3:6],cmp[3:6]), 0.35, 20)): + if (compare_bins(list(zip(ref[3:6],cmp[3:6])), 0.35, 20)): return False #Bins get progressively less sensitive to precision, and # generally contain many more entries as well - if (compare_bins(zip(ref[6:9],cmp[6:9]), 0.05, 10)): + if (compare_bins(list(zip(ref[6:9],cmp[6:9])), 0.05, 10)): return False - if (compare_bins(zip(ref[9:12],cmp[9:12]), 0.02, 10)): + if (compare_bins(list(zip(ref[9:12],cmp[9:12])), 0.02, 10)): return False - if (compare_bins(zip(ref[12:21],cmp[12:21]), 0.01, 10)): + if (compare_bins(list(zip(ref[12:21],cmp[12:21])), 0.01, 10)): return False - if (compare_bins(zip(ref[21:32],cmp[21:32]), 0.001, 10)): + if (compare_bins(list(zip(ref[21:32],cmp[21:32])), 0.001, 10)): return False - if (compare_bins(zip(ref[32:],cmp[32:]), 0.001, 10000)): + if (compare_bins(list(zip(ref[32:],cmp[32:])), 0.001, 10000)): return False fulldiff = sum(ref) - sum(cmp) if ( fulldiff > 0.0001 * sum(ref) ): - print fulldiff + print(fulldiff) return False return True diff --git a/src/cuda/parboil/common/mk/cuda.mk b/src/cuda/parboil/common/mk/cuda.mk index 9e99fdf8d..376a7a621 100644 --- a/src/cuda/parboil/common/mk/cuda.mk +++ b/src/cuda/parboil/common/mk/cuda.mk @@ -22,7 +22,7 @@ LANG_CUDACFLAGS=$(LANG_CFLAGS) CFLAGS=$(APP_CFLAGS) $(LANG_CFLAGS) $(PLATFORM_CFLAGS) CXXFLAGS=$(APP_CXXFLAGS) $(LANG_CXXFLAGS) $(PLATFORM_CXXFLAGS) -CUDACFLAGS=$(LANG_CUDACFLAGS) $(PLATFORM_CUDACFLAGS) $(APP_CUDACFLAGS) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM61) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) +CUDACFLAGS=$(LANG_CUDACFLAGS) $(PLATFORM_CUDACFLAGS) $(APP_CUDACFLAGS) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM61) $(GENCODE_SM62) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) CUDALDFLAGS=$(LANG_LDFLAGS) $(PLATFORM_CUDALDFLAGS) $(APP_CUDALDFLAGS) # Rules common to all makefiles diff --git a/src/cuda/parboil/common/python/binaryfilecompare.py b/src/cuda/parboil/common/python/binaryfilecompare.py index e93b39382..d6310327f 100644 --- a/src/cuda/parboil/common/python/binaryfilecompare.py +++ b/src/cuda/parboil/common/python/binaryfilecompare.py @@ -3,38 +3,38 @@ import struct def uint16(f): - """Read a 16-bit unsigned integer from f.""" + """Read a 16-bit unsigned integer from f.""" chars = f.read(2) - if len(chars) != 2: raise ValueError, "Unexpected end of file" - [c, c2] = chars - return ord(c) + (ord(c2) << 8) + if len(chars) != 2: raise ValueError("Unexpected end of file") + (n,) = struct.unpack(" \n") sys.exit(-1) - ref = open_or_abort(sys.argv[1]) - out = open_or_abort(sys.argv[2]) + ref = open_or_abort(sys.argv[1], mode) + out = open_or_abort(sys.argv[2], mode) (ok, _) = comparison_routine.run(ref, out) if ok: diff --git a/src/cuda/parboil/common/python/textfilecompare.py b/src/cuda/parboil/common/python/textfilecompare.py index f7cd7abc5..0731055bd 100644 --- a/src/cuda/parboil/common/python/textfilecompare.py +++ b/src/cuda/parboil/common/python/textfilecompare.py @@ -15,7 +15,7 @@ def float(f): number.""" words = f.readline().split() if len(words) != 1: - raise ValueError, "Expecting line to contain a single number" + raise ValueError("Expecting line to contain a single number") return builtin_float(words[0]) def floats(f): diff --git a/src/cuda/parboil/driver/__init__.py b/src/cuda/parboil/driver/__init__.py index 0d0d962b9..9648c1b26 100644 --- a/src/cuda/parboil/driver/__init__.py +++ b/src/cuda/parboil/driver/__init__.py @@ -3,6 +3,7 @@ import sys import os + from . import globals from . import actions from . import options @@ -12,7 +13,7 @@ def run(): # Print a banner message - print ("Parboil parallel benchmark suite, version 0.2") + print("Parboil parallel benchmark suite, version 0.2") print() # Global variable setup diff --git a/src/cuda/parboil/driver/actions.py b/src/cuda/parboil/driver/actions.py index 1a61fa1b8..941030894 100644 --- a/src/cuda/parboil/driver/actions.py +++ b/src/cuda/parboil/driver/actions.py @@ -5,6 +5,7 @@ import os + from . import process from . import benchmark from . import globals @@ -15,7 +16,7 @@ def benchmark_iter(): """Iterate over the benchmarks in 'bmks'.""" # bmks is a dictionary from str to Future(Benchmark) - return map(lambda x: x.get(), globals.benchmarks.values()) + return map(lambda x: x.get(), iter(globals.benchmarks.values())) def list_benchmarks(): """List all benchmarks on standard output.""" @@ -63,7 +64,7 @@ def compile_benchmark(bmk, version_name, platform=None): except KeyError: print("Cannot find benchmark version") return - + return impl.build(bmk, platform) def clean_benchmark(bmk, version_name=None, platform=None): @@ -88,7 +89,7 @@ def run_benchmark(bmk, version_name, input_name, check=True, extra_opts=[], plat except KeyError: print("Cannot find benchmark version") return ErrorType.CannotFindVersion - + try: data = bmk.datas[input_name] except KeyError: print("Cannot find data set") @@ -119,7 +120,7 @@ def debug_benchmark(bmk, version_name, input_name, check=True, extra_opts=[], pl except KeyError: print("Cannot find benchmark version") return ErrorType.CannotFindVersion - + try: data = bmk.datas[input_name] except KeyError: print("Cannot find data set") diff --git a/src/cuda/parboil/driver/benchmark.py b/src/cuda/parboil/driver/benchmark.py index f767035e3..220be5a69 100644 --- a/src/cuda/parboil/driver/benchmark.py +++ b/src/cuda/parboil/driver/benchmark.py @@ -5,7 +5,6 @@ from os import path import re from itertools import repeat, chain -from functools import reduce from . import globals from . import process @@ -13,6 +12,7 @@ from .futures import Future from .error import ErrorType +from functools import reduce class Benchmark(object): """A benchmark. @@ -94,7 +94,7 @@ class BenchImpl(object): def __init__(self, dir, description=None): if not isinstance(dir, pbf.Directory): - raise TypeError("dir must be a directory") + raise TypeEror("dir must be a directory") self.name = dir.getName() self.dir = dir diff --git a/src/cuda/parboil/driver/parboilfile.py b/src/cuda/parboil/driver/parboilfile.py index eed887274..7a4ba66d3 100644 --- a/src/cuda/parboil/driver/parboilfile.py +++ b/src/cuda/parboil/driver/parboilfile.py @@ -1,296 +1,295 @@ -# File objects used by the parboil driver. -# -# A File holds information about a file or directory that the Parboil driver -# may interact with. In general, the file or direcotry may or may not be -# open, and may or may not exist. -# File objects contain utility routines to help the driver scan directories -# and recover from errors. - -# This code replaces some of the functionality of the following functions: -# scan_for_files -# scan_for_benchmarks -# scan_for_benchmark_versions -# scan_for_benchmark_datasets -# touch_directory -# find_benchmarks -# Benchmark.createFromName -# BenchImpl.createFromName -# BenchDataset.createFromName -# some of the os.path calls in benchmark.py - -# Each Benchmark should reference a Directory object for its code and -# a Directory object for its shared data. -# Each BenchImpl should reference a Directory object. -# Each BenchDataset should reference a Directory object for the data set. - -import os -import os.path as path - -class FileBase(object): - """The base class for file objects. An instance of FileBase has - information about one file or directory. - - A FileBase instance reflects what is *expected* about the corresponding - file in the file system. The actual state of the file system might be - different. For example, a file described by a FileBase object might not - actually exist.""" - - def valid(self): - """f.valid() -> bool - - Test whether this file is valid. If the file doesn't exist and it - is not required to exist, then it is valid. If the file exists, - then ths function returns the same results as exists(). This function - should not raise an exception.""" - raise NotImplementedError("'FileBase' is an abstract base class") - - def exists(self): - """f.exists() -> bool - - Test whether this file exists and is a valid file. This function - should not raise an exception.""" - raise NotImplementedError("'FileBase' is an abstract base class") - - def isDir(self): - """f.isDir() -> bool - - Test whether this FileBase object represents a directory. This - function should not access the file system.""" - raise NotImplementedError("'FileBase' is an abstract base class") - - def isFile(self): - """f.isFile() -> bool - - Test whether this FileBase object represents an ordinary file. This - function should not access the file system.""" - raise NotImplementedError("'FileBase' is an abstract base class") - - def getPath(self): - """f.getPath() -> string - - Get the path to this file. This function should not access the - file system.""" - raise NotImplementedError("'FileBase' is an abstract base class") - - def getName(self): - """f.getName() -> string - - Get the name of this file. This function should not access the - file system.""" - raise NotImplementedError("'FileBase' is an abstract base class") - -class File(FileBase): - """A description of a file.""" - def __init__(self, fpath, must_exist = True): - """File(path, must_exist) - - Create a description of a file, containing its path and whether or - not it must exist. This function does not access the file system.""" - - self._path = fpath - self._must_exist = must_exist - self._name = path.split(fpath)[1] - - def exists(self): - try: return path.isfile(self.getPath()) - except OSError: return False # handles file-not-found case - - def valid(self): - if self._must_exist: - return self.exists() - else: - return True - - def isDir(self): return False - - def isFile(self): return True - - def getPath(self): - return self._path - - def getName(self): - return self._name - - def open(self, mode='r', buffering=None): - """f.open(mode, buffering) -> file object - - Open the file.""" - if buffering is None: return open(self.getPath(), mode) - else: return open(self.getPath(), mode, buffering=buffering) - -class Directory(FileBase): - """A description of a directory.""" - def __init__(self, dpath, - contents_list = [], scan_func = None, must_exist = True): - """Directory(path, contents-list, scan-function or None, must-exist) - - Create a Directory object. Files given as part of contents_list - are added to directory. Any other files in the directory are - passed (by full path) to the scanner function to decide whether to - include them. The scanner function should return None if a file is - to be ignored or a FileBase object if the file is to be noticed. - - This function does not access the file system.""" - for f in contents_list: - assert isinstance(f, FileBase) - if scan_func and not must_exist: - raise ValueError("Invalid combination of arguments: scan_func is provided but must_exist is False") - - self._realContents = None - self._interesting = scan_func - self._mustExist = must_exist - self._contentsList = contents_list - self._path = dpath - self._name = path.split(dpath)[1] - - def exists(self): - try: return path.isdir(self.getPath()) - except OSError: return False # handles file-not-found case - - def valid(self): - - if self._mustExist and not self.exists(): - return False - - if self.exists(): - for file in self._contentsList: - if not file.valid(): return False - if self._realContents is not None: - for file in self._realContents: - if not file.valid(): return False - - #Children are valid, and either exists or doesn't have to - return True - - def isDir(self): return True - - def isFile(self): return False - - def getPath(self): - return self._path - - def getName(self): - return self._name - - def scan(self): - """d.scan() -- scan the contents of the file system to find the - contents of this directory.""" - if self._realContents is not None: return - - # Scan the directory and assign self._realContents - if not self.exists(): - raise OSError("Directory '" + self._name + "' does not exist.") - - all_contents = os.listdir(self.getPath()) - - def has_file_of_name(name): - for x in self._contentsList: - if x.getName() == name: - return True - return False - - new_contents = list(filter(lambda x: not has_file_of_name(x), all_contents)) - - self._realContents = list(filter(lambda x: x is not None, - [self._interesting(path.join(self.getPath(), x)) for x in new_contents])) - - def touch(self): - """d.touch() -- create this directory if it doesn't exist. - Throw an error if the file cannot be created, exists but is not a - directory, or exists but is not readable, writable, and listable by - the user.""" - def touch_dir(dirpath): - """Ensures that the directory 'dirpath' and its parent directories - exist. If they do not exist, they will be created. It is an - error if the path exists but is not a directory.""" - if path.isdir(dirpath): - return - elif path.exists(dirpath): - raise OSError("Path exists but is not a directory") - else: - (head, tail) = path.split(dirpath) - if head: touch_dir(head) - os.mkdir(dirpath) - - touch_dir(self._path) - - def getChildByName(self, filename): - """d.getChild(filename) -> FileBase object - - Get a file from this directory. - Raise an exception if the file is not in this directory.""" - for x in self.getChildren(): - if x.getName() == filename: - return x - return None - - - def getChildByPath(self, pathname): - """d.getChild(filepath) -> FileBase object - - Get a file from this directory. Verify that the file exists - before returning it. Raise an exception if the file doesn't exist - or is ignored by this directory.""" - (basepathname, filename) = path.split(pathname) - if basepathname != self.getPath(): - raise ValueError("Path is not a child of this directory") - return self.getChildByName(filename) - - def getChildren(self): - """d.getChildren(filepath) -> list of FileBase - - Get a list of all children of this directory.""" - - if self._realContents is None: - return self._contentsList - else: - return self._contentsList + self._realContents - - def getScannedChildren(self): - """d.getScannedChildren(filepath) -> list of FileBase - - Get a list of all children of this directory that were found by - scanning the directory. Explicitly listed contents are not - included in the list.""" - return self._realContents - - def scanAndReturnNames(self): - """Exectues the scan operation for this directory, returning a list of - strings representing the names of files discovered.""" - - self.scan() - return [ x.getName() for x in self.getScannedChildren() ] - - def addChild(self, newchild): - """addChild(newchild) - Adds parameter to its expected children list. Returns None. - Parameter must be a FileBase obejct.""" - if not isinstance(newchild, FileBase): - raise TypeError("parameter must be a FileBase object") - - self._contentsList.append(newchild) - -def scan_file(fpath, directory=False, create_file=lambda x: File(x), boring=[]): - """scan_file(path, directory=False, create_file, boring=[]) -> FileBase - - Test the file referenced by path. Invoke creat_file on that path - if it is to be noticed and returns the results, else returns None. - A file is considered 'to be noticed' if its name is not in boring, - and it is a directory or file if directory is True or False, respectively. - This function accesses the file system to determine the file type - (directory or file) and raises an OSError on inability to access. - """ - - # Look for directories or regular files, depending on the 'directory' - # parameter - if directory: valid_test = path.isdir - else: valid_test = path.isfile - - # True if 'dirname' is not a boring name, and it is a directory - fname = path.split(fpath)[1] - - if fname in boring: return None - - if valid_test(fpath): return create_file(fpath) - - +# File objects used by the parboil driver. +# +# A File holds information about a file or directory that the Parboil driver +# may interact with. In general, the file or direcotry may or may not be +# open, and may or may not exist. +# File objects contain utility routines to help the driver scan directories +# and recover from errors. + +# This code replaces some of the functionality of the following functions: +# scan_for_files +# scan_for_benchmarks +# scan_for_benchmark_versions +# scan_for_benchmark_datasets +# touch_directory +# find_benchmarks +# Benchmark.createFromName +# BenchImpl.createFromName +# BenchDataset.createFromName +# some of the os.path calls in benchmark.py + +# Each Benchmark should reference a Directory object for its code and +# a Directory object for its shared data. +# Each BenchImpl should reference a Directory object. +# Each BenchDataset should reference a Directory object for the data set. + +import os +import os.path as path + +class FileBase(object): + """The base class for file objects. An instance of FileBase has + information about one file or directory. + + A FileBase instance reflects what is *expected* about the corresponding + file in the file system. The actual state of the file system might be + different. For example, a file described by a FileBase object might not + actually exist.""" + + def valid(self): + """f.valid() -> bool + + Test whether this file is valid. If the file doesn't exist and it + is not required to exist, then it is valid. If the file exists, + then ths function returns the same results as exists(). This function + should not raise an exception.""" + raise NotImplementedError("'FileBase' is an abstract base class") + + def exists(self): + """f.exists() -> bool + + Test whether this file exists and is a valid file. This function + should not raise an exception.""" + raise NotImplementedError("'FileBase' is an abstract base class") + + def isDir(self): + """f.isDir() -> bool + + Test whether this FileBase object represents a directory. This + function should not access the file system.""" + raise NotImplementedError("'FileBase' is an abstract base class") + + def isFile(self): + """f.isFile() -> bool + + Test whether this FileBase object represents an ordinary file. This + function should not access the file system.""" + raise NotImplementedError("'FileBase' is an abstract base class") + + def getPath(self): + """f.getPath() -> string + + Get the path to this file. This function should not access the + file system.""" + raise NotImplementedError("'FileBase' is an abstract base class") + + def getName(self): + """f.getName() -> string + + Get the name of this file. This function should not access the + file system.""" + raise NotImplementedError("'FileBase' is an abstract base class") + +class File(FileBase): + """A description of a file.""" + def __init__(self, fpath, must_exist = True): + """File(path, must_exist) + + Create a description of a file, containing its path and whether or + not it must exist. This function does not access the file system.""" + + self._path = fpath + self._must_exist = must_exist + self._name = path.split(fpath)[1] + + def exists(self): + try: return path.isfile(self.getPath()) + except OSError: return False # handles file-not-found case + + def valid(self): + if self._must_exist: + return self.exists() + else: + return True + + def isDir(self): return False + + def isFile(self): return True + + def getPath(self): + return self._path + + def getName(self): + return self._name + + def open(self, mode='r', buffering=None): + """f.open(mode, buffering) -> file object + + Open the file.""" + if buffering is None: return open(self.getPath(), mode) + else: return open(self.getPath(), mode, buffering) + +class Directory(FileBase): + """A description of a directory.""" + def __init__(self, dpath, + contents_list = [], scan_func = None, must_exist = True): + """Directory(path, contents-list, scan-function or None, must-exist) + + Create a Directory object. Files given as part of contents_list + are added to directory. Any other files in the directory are + passed (by full path) to the scanner function to decide whether to + include them. The scanner function should return None if a file is + to be ignored or a FileBase object if the file is to be noticed. + + This function does not access the file system.""" + for f in contents_list: + assert isinstance(f, FileBase) + if scan_func and not must_exist: + raise ValueError("Invalid combination of arguments: scan_func is provided but must_exist is False") + + self._realContents = None + self._interesting = scan_func + self._mustExist = must_exist + self._contentsList = contents_list + self._path = dpath + self._name = path.split(dpath)[1] + + def exists(self): + try: return path.isdir(self.getPath()) + except OSError: return False # handles file-not-found case + + def valid(self): + + if self._mustExist and not self.exists(): + return False + + if self.exists(): + for file in self._contentsList: + if not file.valid(): return False + if self._realContents is not None: + for file in self._realContents: + if not file.valid(): return False + + #Children are valid, and either exists or doesn't have to + return True + + def isDir(self): return True + + def isFile(self): return False + + def getPath(self): + return self._path + + def getName(self): + return self._name + + def scan(self): + """d.scan() -- scan the contents of the file system to find the + contents of this directory.""" + if self._realContents is not None: return + + # Scan the directory and assign self._realContents + if not self.exists(): + raise OSError("Directory '" + self._name + "' does not exist.") + + all_contents = os.listdir(self.getPath()) + + def has_file_of_name(name): + for x in self._contentsList: + if x.getName() == name: + return True + return False + + new_contents = [x for x in all_contents if not has_file_of_name(x)] + + self._realContents = [x for x in [self._interesting(path.join(self.getPath(), x)) for x in new_contents] if x is not None] + + def touch(self): + """d.touch() -- create this directory if it doesn't exist. + Throw an error if the file cannot be created, exists but is not a + directory, or exists but is not readable, writable, and listable by + the user.""" + def touch_dir(dirpath): + """Ensures that the directory 'dirpath' and its parent directories + exist. If they do not exist, they will be created. It is an + error if the path exists but is not a directory.""" + if path.isdir(dirpath): + return + elif path.exists(dirpath): + raise OSError("Path exists but is not a directory") + else: + (head, tail) = path.split(dirpath) + if head: touch_dir(head) + os.mkdir(dirpath) + + touch_dir(self._path) + + def getChildByName(self, filename): + """d.getChild(filename) -> FileBase object + + Get a file from this directory. + Raise an exception if the file is not in this directory.""" + for x in self.getChildren(): + if x.getName() == filename: + return x + return None + + + def getChildByPath(self, pathname): + """d.getChild(filepath) -> FileBase object + + Get a file from this directory. Verify that the file exists + before returning it. Raise an exception if the file doesn't exist + or is ignored by this directory.""" + (basepathname, filename) = path.split(pathname) + if basepathname != self.getPath(): + raise ValueError("Path is not a child of this directory") + return self.getChildByName(filename) + + def getChildren(self): + """d.getChildren(filepath) -> list of FileBase + + Get a list of all children of this directory.""" + + if self._realContents is None: + return self._contentsList + else: + return self._contentsList + self._realContents + + def getScannedChildren(self): + """d.getScannedChildren(filepath) -> list of FileBase + + Get a list of all children of this directory that were found by + scanning the directory. Explicitly listed contents are not + included in the list.""" + return self._realContents + + def scanAndReturnNames(self): + """Exectues the scan operation for this directory, returning a list of + strings representing the names of files discovered.""" + + self.scan() + return [ x.getName() for x in self.getScannedChildren() ] + + def addChild(self, newchild): + """addChild(newchild) + Adds parameter to its expected children list. Returns None. + Parameter must be a FileBase obejct.""" + if not isinstance(newchild, FileBase): + raise TypeError("parameter must be a FileBase object") + + self._contentsList.append(newchild) + +def scan_file(fpath, directory=False, create_file=lambda x: File(x), boring=[]): + """scan_file(path, directory=False, create_file, boring=[]) -> FileBase + + Test the file referenced by path. Invoke creat_file on that path + if it is to be noticed and returns the results, else returns None. + A file is considered 'to be noticed' if its name is not in boring, + and it is a directory or file if directory is True or False, respectively. + This function accesses the file system to determine the file type + (directory or file) and raises an OSError on inability to access. + """ + + # Look for directories or regular files, depending on the 'directory' + # parameter + if directory: valid_test = path.isdir + else: valid_test = path.isfile + + # True if 'dirname' is not a boring name, and it is a directory + fname = path.split(fpath)[1] + + if fname in boring: return None + + if valid_test(fpath): return create_file(fpath) + + diff --git a/src/cuda/parboil/driver/ppkg.py b/src/cuda/parboil/driver/ppkg.py index 13a320caf..5f23c786a 100644 --- a/src/cuda/parboil/driver/ppkg.py +++ b/src/cuda/parboil/driver/ppkg.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import re import os @@ -30,7 +30,7 @@ def readFilter(self): try: self.filters.append(re.compile(l)) except: - print "Not valid pattern: %s" % l + print("Not valid pattern: %s" % l) f.close() def readBenchmarks(self): @@ -73,17 +73,17 @@ def walk(self, top): if not self.ignore(fullName): self.add(fullName) else: - print "Ignore %s" % fullName + print("Ignore %s" % fullName) def walk_benchmarks(self, top): for entry in os.listdir(top): if entry in self.benchmarks: self.walk(os.path.join(top, entry)) else: - print "Ignoring %s" % entry + print("Ignoring %s" % entry) def add(self, path): - print "Adding %s ..." % path + print("Adding %s ..." % path) if not self.dont_run: self.tarfile.add(path) @@ -92,8 +92,8 @@ def close(self): self.tarfile.close() if len(sys.argv) != 3: - print "Usage: ./ppkg.py " - print " add your own ignore list in pkg.ignore file in the current directory" + print("Usage: ./ppkg.py ") + print(" add your own ignore list in pkg.ignore file in the current directory") a = Archiver(sys.argv[1], False) a.readFilter() diff --git a/src/cuda/parboil/driver/sanity_check.py b/src/cuda/parboil/driver/sanity_check.py index e0a6dae23..80e7da56b 100644 --- a/src/cuda/parboil/driver/sanity_check.py +++ b/src/cuda/parboil/driver/sanity_check.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Parboil sanity checker # @@ -27,6 +27,7 @@ import time import subprocess import socket +from functools import reduce err_string = { 0: 'success', @@ -74,7 +75,7 @@ def scan_inputs(self): def run(self, ver, datum, pl, fake=False): cmd = 'python parboil run %s %s %s %s' % (self.name, ver, datum, pl) - print cmd + print(cmd) if fake: return 0, '' @@ -90,11 +91,11 @@ def run(self, ver, datum, pl, fake=False): for cat in self.pbTimerCats: if line.find(cat) != -1: line = " ++ %s" % line - print line, + print(line, end=' ') timing += line isCat = True break - if not isCat: print line, + if not isCat: print(line, end=' ') sts = os.waitpid(p.pid, 0)[1] # return p.returncode, timing @@ -139,7 +140,7 @@ def get_result_string(self): def write_result(self, out): x = self.get_result_string() - print x, + print(x, end=' ') out.write(x) out.flush() @@ -206,7 +207,7 @@ def scan_platforms(platform): tokens = mks.split('.') lang = tokens[0] - if lang not in platforms.keys(): + if lang not in list(platforms.keys()): platforms[lang] = [] platforms[lang].append(reduce(lambda x, y: x+y, tokens[1:-1])) return platforms diff --git a/src/cuda/parboil/driver/text.py b/src/cuda/parboil/driver/text.py index 5ee4480ed..420eb1342 100644 --- a/src/cuda/parboil/driver/text.py +++ b/src/cuda/parboil/driver/text.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 + import re @@ -14,12 +15,12 @@ def __init__(self, f, init, s): self.current = init self.begin = True - def next(self): + def __next__(self): if self.begin: self.begin = False return self.current else: - cur = self.f(self.current, self.s.next()) # raises StopIteration + cur = self.f(self.current, next(self.s)) # raises StopIteration self.current = cur return cur @@ -57,7 +58,7 @@ def format_columns(text, indent=0): # length; however, must take at least one token n = 0 lengths = iscan(lambda n, t: n + len(t), inl_indent, tokens) - lengths.next() + next(lengths) for c in lengths: if c > COLUMNS: break n += 1 diff --git a/src/cuda/parboil/parboil b/src/cuda/parboil/parboil index 664de9dd7..37a412927 100755 --- a/src/cuda/parboil/parboil +++ b/src/cuda/parboil/parboil @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # (c) 2007 The Board of Trustees of the University of Illinois. diff --git a/src/cuda/polybench-gpu-1.0/CUDA/2DCONV/2DConvolution.cu b/src/cuda/polybench-gpu-1.0/CUDA/2DCONV/2DConvolution.cu index 247d6ca4a..462bc4e7c 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/2DCONV/2DConvolution.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/2DCONV/2DConvolution.cu @@ -140,7 +140,7 @@ void convolution2DCuda(DATA_TYPE* A, DATA_TYPE* B, DATA_TYPE* B_outputFromGpu) dim3 grid((size_t)ceil( ((float)NI) / ((float)block.x) ), (size_t)ceil( ((float)NJ) / ((float)block.y)) ); t_start = rtclock(); Convolution2D_kernel<<>>(A_gpu,B_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); t_end = rtclock(); fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_end - t_start);//); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/2MM/2mm.cu b/src/cuda/polybench-gpu-1.0/CUDA/2MM/2mm.cu index e1fc6c7f9..f1f8174cc 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/2MM/2mm.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/2MM/2mm.cu @@ -194,9 +194,9 @@ void mm2Cuda(DATA_TYPE* A, DATA_TYPE* B, DATA_TYPE* C, DATA_TYPE* D, DATA_TYPE* dim3 grid2((size_t)ceil( ((float)NL) / ((float)block.x) ), (size_t)ceil( ((float)NI) / ((float)block.y)) ); t_start = rtclock(); mm2_kernel1<<>>(A_gpu, B_gpu, C_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); mm2_kernel2<<>>(C_gpu, D_gpu, E_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); t_end = rtclock(); fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_end - t_start); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/3DCONV/3DConvolution.cu b/src/cuda/polybench-gpu-1.0/CUDA/3DCONV/3DConvolution.cu index 8183ae898..2f5479f2c 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/3DCONV/3DConvolution.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/3DCONV/3DConvolution.cu @@ -167,7 +167,7 @@ void convolution3DCuda(DATA_TYPE* A, DATA_TYPE* B, DATA_TYPE* B_outputFromGpu) convolution3D_kernel<<< grid, block >>>(A_gpu, B_gpu, i); } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); t_end = rtclock(); fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_end - t_start); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/3MM/3mm.cu b/src/cuda/polybench-gpu-1.0/CUDA/3MM/3mm.cu index 2be8c3761..938a5ca27 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/3MM/3mm.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/3MM/3mm.cu @@ -235,11 +235,11 @@ void mm3Cuda(DATA_TYPE* A, DATA_TYPE* B, DATA_TYPE* C, DATA_TYPE* D, DATA_TYPE* t_start = rtclock(); mm3_kernel1<<>>(A_gpu, B_gpu, E_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); mm3_kernel2<<>>(C_gpu, D_gpu, F_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); mm3_kernel3<<>>(E_gpu, F_gpu, G_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); t_end = rtclock(); cudaMemcpy(G_outputFromGpu, G_gpu, sizeof(DATA_TYPE) * NI * NL, cudaMemcpyDeviceToHost); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/ATAX/atax.cu b/src/cuda/polybench-gpu-1.0/CUDA/ATAX/atax.cu index fcf37811f..f3b101a0d 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/ATAX/atax.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/ATAX/atax.cu @@ -161,9 +161,9 @@ void ataxGpu(DATA_TYPE* A, DATA_TYPE* x, DATA_TYPE* y, DATA_TYPE* tmp, DATA_TYPE t_start = rtclock(); atax_kernel1<<< grid1, block >>>(A_gpu,x_gpu,tmp_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); atax_kernel2<<< grid2, block >>>(A_gpu,y_gpu,tmp_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); t_end = rtclock(); fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_end - t_start); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/BICG/bicg.cu b/src/cuda/polybench-gpu-1.0/CUDA/BICG/bicg.cu index b1bde0e47..f4d01859e 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/BICG/bicg.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/BICG/bicg.cu @@ -180,9 +180,9 @@ void bicgCuda(DATA_TYPE* A, DATA_TYPE* r, DATA_TYPE* s, DATA_TYPE* p, DATA_TYPE* t_start = rtclock(); bicg_kernel1<<< grid1, block >>>(A_gpu, r_gpu, s_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); bicg_kernel2<<< grid2, block >>>(A_gpu, p_gpu, q_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); t_end = rtclock(); fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_end - t_start); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/CORR/correlation.cu b/src/cuda/polybench-gpu-1.0/CUDA/CORR/correlation.cu index a60a7a5f9..f988d24b7 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/CORR/correlation.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/CORR/correlation.cu @@ -272,13 +272,13 @@ void correlationCuda(DATA_TYPE* data, DATA_TYPE* mean, DATA_TYPE* stddev, DATA_T t_start = rtclock(); mean_kernel<<< grid1, block1 >>>(mean_gpu,data_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); std_kernel<<< grid2, block2 >>>(mean_gpu,stddev_gpu,data_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); reduce_kernel<<< grid3, block3 >>>(mean_gpu,stddev_gpu,data_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); corr_kernel<<< grid4, block4 >>>(symmat_gpu,data_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); t_end = rtclock(); fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_end - t_start); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/COVAR/covariance.cu b/src/cuda/polybench-gpu-1.0/CUDA/COVAR/covariance.cu index 46320c7f9..8e4d4c9ce 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/COVAR/covariance.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/COVAR/covariance.cu @@ -209,11 +209,11 @@ void covarianceCuda(DATA_TYPE* data, DATA_TYPE* symmat, DATA_TYPE* mean, DATA_TY t_start = rtclock(); mean_kernel<<>>(mean_gpu,data_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); reduce_kernel<<>>(mean_gpu,data_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); covar_kernel<<>>(symmat_gpu,data_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); t_end = rtclock(); fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_end - t_start); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/FDTD-2D/fdtd2d.cu b/src/cuda/polybench-gpu-1.0/CUDA/FDTD-2D/fdtd2d.cu index 98c0125d6..9cad85fb7 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/FDTD-2D/fdtd2d.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/FDTD-2D/fdtd2d.cu @@ -197,11 +197,11 @@ void fdtdCuda(DATA_TYPE* _fict_, DATA_TYPE* ex, DATA_TYPE* ey, DATA_TYPE* hz, DA for(int t = 0; t< tmax; t++) { fdtd_step1_kernel<<>>(_fict_gpu, ex_gpu, ey_gpu, hz_gpu, t); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); fdtd_step2_kernel<<>>(ex_gpu, ey_gpu, hz_gpu, t); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); fdtd_step3_kernel<<>>(ex_gpu, ey_gpu, hz_gpu, t); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); } t_end = rtclock(); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/GEMM/gemm.cu b/src/cuda/polybench-gpu-1.0/CUDA/GEMM/gemm.cu index d0c8660e6..47ba3dcd8 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/GEMM/gemm.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/GEMM/gemm.cu @@ -160,7 +160,7 @@ void gemmCuda(DATA_TYPE* A, DATA_TYPE* B, DATA_TYPE* C, DATA_TYPE* C_outputFromG t_start = rtclock(); gemm_kernel<<< grid, block >>>(A_gpu, B_gpu, C_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); t_end = rtclock(); fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_end - t_start); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/GESUMMV/gesummv.cu b/src/cuda/polybench-gpu-1.0/CUDA/GESUMMV/gesummv.cu index 27d87d737..8d2b740fc 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/GESUMMV/gesummv.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/GESUMMV/gesummv.cu @@ -145,7 +145,7 @@ void gesummvCuda(DATA_TYPE* A, DATA_TYPE* B, DATA_TYPE* x, DATA_TYPE* y, DATA_TY t_start = rtclock(); gesummv_kernel<<< grid, block>>>(A_gpu,B_gpu,x_gpu, y_gpu, tmp_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); t_end = rtclock(); cudaMemcpy(y_outputFromGpu, y_gpu, sizeof(DATA_TYPE) * N, cudaMemcpyDeviceToHost); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/GRAMSCHM/gramschmidt.cu b/src/cuda/polybench-gpu-1.0/CUDA/GRAMSCHM/gramschmidt.cu index 49c018e94..1b9d0d785 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/GRAMSCHM/gramschmidt.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/GRAMSCHM/gramschmidt.cu @@ -189,11 +189,11 @@ void gramschmidtCuda(DATA_TYPE* A, DATA_TYPE* R, DATA_TYPE* Q, DATA_TYPE* A_outp for (k = 0; k < N; k++) { gramschmidt_kernel1<<>>(A_gpu, R_gpu, Q_gpu, k); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); gramschmidt_kernel2<<>>(A_gpu, R_gpu, Q_gpu, k); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); gramschmidt_kernel3<<>>(A_gpu, R_gpu, Q_gpu, k); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); } t_end = rtclock(); fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_end - t_start); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/MVT/mvt.cu b/src/cuda/polybench-gpu-1.0/CUDA/MVT/mvt.cu index 85be1599e..22d674761 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/MVT/mvt.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/MVT/mvt.cu @@ -163,7 +163,7 @@ void mvtCuda(DATA_TYPE* a, DATA_TYPE* x1, DATA_TYPE* x2, DATA_TYPE* y_1, DATA_TY t_start = rtclock(); mvt_kernel1<<>>(a_gpu,x1_gpu,y_1_gpu); mvt_kernel2<<>>(a_gpu,x2_gpu,y_2_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); t_end = rtclock(); fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_end - t_start); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/SYR2K/syr2k.cu b/src/cuda/polybench-gpu-1.0/CUDA/SYR2K/syr2k.cu index 1e3ae9d19..1ddb28c54 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/SYR2K/syr2k.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/SYR2K/syr2k.cu @@ -154,7 +154,7 @@ void syr2kCuda(DATA_TYPE* A, DATA_TYPE* B, DATA_TYPE* C, DATA_TYPE* C_outputFrom t_start = rtclock(); syr2k_kernel<<>>(A_gpu,B_gpu,C_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); t_end = rtclock(); fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_end - t_start); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/SYRK/syrk.cu b/src/cuda/polybench-gpu-1.0/CUDA/SYRK/syrk.cu index 37fd48f82..8b75d09d7 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/SYRK/syrk.cu +++ b/src/cuda/polybench-gpu-1.0/CUDA/SYRK/syrk.cu @@ -151,7 +151,7 @@ void syrkCuda(DATA_TYPE* A, DATA_TYPE* C, DATA_TYPE* C_outputFromGpu) dim3 grid((size_t)(ceil(((float)N) / ((float)DIM_THREAD_BLOCK_X))), (size_t)ceil(((float)N) / ((float)DIM_THREAD_BLOCK_Y))); t_start = rtclock(); syrk_kernel<<>>(alpha, beta, A_gpu,C_gpu); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); t_end = rtclock(); fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_end - t_start); diff --git a/src/cuda/polybench-gpu-1.0/CUDA/common.mk b/src/cuda/polybench-gpu-1.0/CUDA/common.mk index 965130e7c..90ec99668 100644 --- a/src/cuda/polybench-gpu-1.0/CUDA/common.mk +++ b/src/cuda/polybench-gpu-1.0/CUDA/common.mk @@ -11,6 +11,6 @@ GENCODE_SM70 ?= -gencode=arch=compute_70,code=\"sm_70,compute_70\" GENCODE_SM75 ?= -gencode=arch=compute_75,code=\"sm_75,compute_75\" all: - nvcc -O3 ${GENCODE_SM10} ${GENCODE_SM13} ${GENCODE_SM20} ${GENCODE_SM30} ${GENCODE_SM35} ${GENCODE_SM35} ${GENCODE_SM50} ${GENCODE_SM50} ${GENCODE_SM60} ${GENCODE_SM62} ${GENCODE_SM70} ${GENCODE_SM75} ${NVCC_ADDITIONAL_ARGS} ${CUFILES} -o ${EXECUTABLE} + nvcc -O3 ${GENCODE_SM10} ${GENCODE_SM13} ${GENCODE_SM20} ${GENCODE_SM30} ${GENCODE_SM35} ${GENCODE_SM35} ${GENCODE_SM50} ${GENCODE_SM50} ${GENCODE_SM60} ${GENCODE_SM62} ${GENCODE_SM70} ${GENCODE_SM75} $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) ${NVCC_ADDITIONAL_ARGS} ${CUFILES} -o ${EXECUTABLE} clean: rm -f *~ *.exe diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2DCONV/CUDA/2DConvCudaDefaultConfig/conv_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2DCONV/CUDA/2DConvCudaDefaultConfig/conv_cuda.cu index e925cada7..a85cfeca9 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2DCONV/CUDA/2DConvCudaDefaultConfig/conv_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2DCONV/CUDA/2DConvCudaDefaultConfig/conv_cuda.cu @@ -977,7 +977,7 @@ void hmpp_codelet__conv2D( int &hmppcg_status_, void * __h, const cudaDevicePro A.makeStreamWait(kernel_stream); B.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__conv2D_loop0_<<>>(A.getDeviceAddr(), B.getDeviceAddr()); @@ -987,7 +987,7 @@ void hmpp_codelet__conv2D( int &hmppcg_status_, void * __h, const cudaDevicePro A.waitOnEvent(kernel_event); B.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2DCONV/CUDA/2DConvCudaOptConfig_P_i_j_U1_n2_n/conv_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2DCONV/CUDA/2DConvCudaOptConfig_P_i_j_U1_n2_n/conv_cuda.cu index 7436c26c5..6019262c5 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2DCONV/CUDA/2DConvCudaOptConfig_P_i_j_U1_n2_n/conv_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2DCONV/CUDA/2DConvCudaOptConfig_P_i_j_U1_n2_n/conv_cuda.cu @@ -999,7 +999,7 @@ void hmpp_codelet__conv2D( int &hmppcg_status_, void * __h, const cudaDevicePro A.makeStreamWait(kernel_stream); B.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__conv2D_loop0_<<>>(A.getDeviceAddr(), B.getDeviceAddr()); @@ -1009,7 +1009,7 @@ void hmpp_codelet__conv2D( int &hmppcg_status_, void * __h, const cudaDevicePro A.waitOnEvent(kernel_event); B.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2MM/CUDA/2mmCudaDefaultConfig/group1_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2MM/CUDA/2mmCudaDefaultConfig/group1_cuda.cu index fa25e311b..401d8a43e 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2MM/CUDA/2mmCudaDefaultConfig/group1_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2MM/CUDA/2mmCudaDefaultConfig/group1_cuda.cu @@ -1020,7 +1020,7 @@ void hmpp_codelet__twoMMloopa( int &hmppcg_status_, void * __h, const cudaDevic b.makeStreamWait(kernel_stream); c.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__twoMMloopa_loop0_<<>>(a.getDeviceAddr(), b.getDeviceAddr(), c.getDeviceAddr()); @@ -1031,7 +1031,7 @@ void hmpp_codelet__twoMMloopa( int &hmppcg_status_, void * __h, const cudaDevic b.waitOnEvent(kernel_event); c.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1075,7 +1075,7 @@ void hmpp_codelet__twoMMloopb( int &hmppcg_status_, void * __h, const cudaDevic d.makeStreamWait(kernel_stream); e.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__twoMMloopb_loop0_<<>>(c_1.getDeviceAddr(), d.getDeviceAddr(), e.getDeviceAddr()); @@ -1086,7 +1086,7 @@ void hmpp_codelet__twoMMloopb( int &hmppcg_status_, void * __h, const cudaDevic d.waitOnEvent(kernel_event); e.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2MM/CUDA/2mmCudaOptConfigP_U1sn1sn3sn1sn1sn3sn/group1_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2MM/CUDA/2mmCudaOptConfigP_U1sn1sn3sn1sn1sn3sn/group1_cuda.cu index 195b622d7..5a1508b1b 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2MM/CUDA/2mmCudaOptConfigP_U1sn1sn3sn1sn1sn3sn/group1_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/2MM/CUDA/2mmCudaOptConfigP_U1sn1sn3sn1sn1sn3sn/group1_cuda.cu @@ -1035,7 +1035,7 @@ void hmpp_codelet__twoMMloopa( int &hmppcg_status_, void * __h, const cudaDevic b.makeStreamWait(kernel_stream); c.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__twoMMloopa_loop0_<<>>(a.getDeviceAddr(), b.getDeviceAddr(), c.getDeviceAddr()); @@ -1046,7 +1046,7 @@ void hmpp_codelet__twoMMloopa( int &hmppcg_status_, void * __h, const cudaDevic b.waitOnEvent(kernel_event); c.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1099,7 +1099,7 @@ void hmpp_codelet__twoMMloopb( int &hmppcg_status_, void * __h, const cudaDevic d.makeStreamWait(kernel_stream); e.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__twoMMloopb_loop0_<<>>(c_1.getDeviceAddr(), d.getDeviceAddr(), e.getDeviceAddr()); @@ -1110,7 +1110,7 @@ void hmpp_codelet__twoMMloopb( int &hmppcg_status_, void * __h, const cudaDevic d.waitOnEvent(kernel_event); e.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3DCONV/CUDA/3DConvCudaDefaultConfig/conv_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3DCONV/CUDA/3DConvCudaDefaultConfig/conv_cuda.cu index ee8148309..358320ad4 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3DCONV/CUDA/3DConvCudaDefaultConfig/conv_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3DCONV/CUDA/3DConvCudaDefaultConfig/conv_cuda.cu @@ -1005,7 +1005,7 @@ void hmpp_codelet__conv3D( int &hmppcg_status_, void * __h, const cudaDevicePro A.makeStreamWait(kernel_stream); B.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__conv3D_loop0_<<>>(A.getDeviceAddr(), B.getDeviceAddr()); @@ -1015,7 +1015,7 @@ void hmpp_codelet__conv3D( int &hmppcg_status_, void * __h, const cudaDevicePro A.waitOnEvent(kernel_event); B.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3DCONV/CUDA/3DConvCudaOptConfig_P_i_k_j_U1_n4_n1_n_O2/conv_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3DCONV/CUDA/3DConvCudaOptConfig_P_i_k_j_U1_n4_n1_n_O2/conv_cuda.cu index 389dac816..5054756d9 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3DCONV/CUDA/3DConvCudaOptConfig_P_i_k_j_U1_n4_n1_n_O2/conv_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3DCONV/CUDA/3DConvCudaOptConfig_P_i_k_j_U1_n4_n1_n_O2/conv_cuda.cu @@ -1036,7 +1036,7 @@ void hmpp_codelet__conv3D( int &hmppcg_status_, void * __h, const cudaDevicePro A.makeStreamWait(kernel_stream); B.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__conv3D_loop0_<<>>(A.getDeviceAddr(), B.getDeviceAddr()); @@ -1046,7 +1046,7 @@ void hmpp_codelet__conv3D( int &hmppcg_status_, void * __h, const cudaDevicePro A.waitOnEvent(kernel_event); B.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3MM/CUDA/3mmCudaDefaultConfig/group1_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3MM/CUDA/3mmCudaDefaultConfig/group1_cuda.cu index 0d2077b27..e7088f137 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3MM/CUDA/3mmCudaDefaultConfig/group1_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3MM/CUDA/3mmCudaDefaultConfig/group1_cuda.cu @@ -1064,7 +1064,7 @@ void hmpp_codelet__threeMMloopa( int &hmppcg_status_, void * __h, const cudaDev b.makeStreamWait(kernel_stream); e.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__threeMMloopa_loop0_<<>>(a.getDeviceAddr(), b.getDeviceAddr(), e.getDeviceAddr()); @@ -1075,7 +1075,7 @@ void hmpp_codelet__threeMMloopa( int &hmppcg_status_, void * __h, const cudaDev b.waitOnEvent(kernel_event); e.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1120,7 +1120,7 @@ void hmpp_codelet__threeMMloopb( int &hmppcg_status_, void * __h, const cudaDev d.makeStreamWait(kernel_stream); f.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__threeMMloopb_loop0_<<>>(c.getDeviceAddr(), d.getDeviceAddr(), f.getDeviceAddr()); @@ -1131,7 +1131,7 @@ void hmpp_codelet__threeMMloopb( int &hmppcg_status_, void * __h, const cudaDev d.waitOnEvent(kernel_event); f.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1176,7 +1176,7 @@ void hmpp_codelet__threeMMloopc( int &hmppcg_status_, void * __h, const cudaDev f_1.makeStreamWait(kernel_stream); g.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__threeMMloopc_loop0_<<>>(e_1.getDeviceAddr(), f_1.getDeviceAddr(), g.getDeviceAddr()); @@ -1187,7 +1187,7 @@ void hmpp_codelet__threeMMloopc( int &hmppcg_status_, void * __h, const cudaDev f_1.waitOnEvent(kernel_event); g.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3MM/CUDA/3mmCudaOptConfig_P_U1sn1sn3sn1sn1sn3sn1sn1sn3sn/group1_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3MM/CUDA/3mmCudaOptConfig_P_U1sn1sn3sn1sn1sn3sn1sn1sn3sn/group1_cuda.cu index 3df7a90b8..1745ff7dd 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3MM/CUDA/3mmCudaOptConfig_P_U1sn1sn3sn1sn1sn3sn1sn1sn3sn/group1_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/3MM/CUDA/3mmCudaOptConfig_P_U1sn1sn3sn1sn1sn3sn1sn1sn3sn/group1_cuda.cu @@ -1081,7 +1081,7 @@ void hmpp_codelet__threeMMloopa( int &hmppcg_status_, void * __h, const cudaDev b.makeStreamWait(kernel_stream); e.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__threeMMloopa_loop0_<<>>(a.getDeviceAddr(), b.getDeviceAddr(), e.getDeviceAddr()); @@ -1092,7 +1092,7 @@ void hmpp_codelet__threeMMloopa( int &hmppcg_status_, void * __h, const cudaDev b.waitOnEvent(kernel_event); e.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1146,7 +1146,7 @@ void hmpp_codelet__threeMMloopb( int &hmppcg_status_, void * __h, const cudaDev d.makeStreamWait(kernel_stream); f.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__threeMMloopb_loop0_<<>>(c.getDeviceAddr(), d.getDeviceAddr(), f.getDeviceAddr()); @@ -1157,7 +1157,7 @@ void hmpp_codelet__threeMMloopb( int &hmppcg_status_, void * __h, const cudaDev d.waitOnEvent(kernel_event); f.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1211,7 +1211,7 @@ void hmpp_codelet__threeMMloopc( int &hmppcg_status_, void * __h, const cudaDev f_1.makeStreamWait(kernel_stream); g.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__threeMMloopc_loop0_<<>>(e_1.getDeviceAddr(), f_1.getDeviceAddr(), g.getDeviceAddr()); @@ -1222,7 +1222,7 @@ void hmpp_codelet__threeMMloopc( int &hmppcg_status_, void * __h, const cudaDev f_1.waitOnEvent(kernel_event); g.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/ATAX/CUDA/AtaxCudaDefaultConfig/group1_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/ATAX/CUDA/AtaxCudaDefaultConfig/group1_cuda.cu index 9202846e0..333598b15 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/ATAX/CUDA/AtaxCudaDefaultConfig/group1_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/ATAX/CUDA/AtaxCudaDefaultConfig/group1_cuda.cu @@ -1028,7 +1028,7 @@ void hmpp_codelet__ataxLoopa( int &hmppcg_status_, void * __h, const cudaDevice #if CUDA_VERSION >= 3020 y.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__ataxLoopa_loop0_<<>>(y.getDeviceAddr()); @@ -1037,7 +1037,7 @@ void hmpp_codelet__ataxLoopa( int &hmppcg_status_, void * __h, const cudaDevice if((hmppcg_status_ = CHECK_STATUS(cudaEventRecord(kernel_event, kernel_stream)))) return; y.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1056,7 +1056,7 @@ void hmpp_codelet__ataxLoopa( int &hmppcg_status_, void * __h, const cudaDevice tmp.makeStreamWait(kernel_stream); x.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__ataxLoopa_loop1_<<>>(a.getDeviceAddr(), tmp.getDeviceAddr(), x.getDeviceAddr()); @@ -1067,7 +1067,7 @@ void hmpp_codelet__ataxLoopa( int &hmppcg_status_, void * __h, const cudaDevice tmp.waitOnEvent(kernel_event); x.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1107,7 +1107,7 @@ void hmpp_codelet__ataxLoopb( int &hmppcg_status_, void * __h, const cudaDevice tmp_1.makeStreamWait(kernel_stream); y_1.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__ataxLoopb_loop0_<<>>(i_4, a_1.getDeviceAddr(), tmp_1.getDeviceAddr(), y_1.getDeviceAddr()); @@ -1118,7 +1118,7 @@ void hmpp_codelet__ataxLoopb( int &hmppcg_status_, void * __h, const cudaDevice tmp_1.waitOnEvent(kernel_event); y_1.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/ATAX/CUDA/AtaxCudaOptConfig_P_j_i_T4_4_1_1_1_/group1_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/ATAX/CUDA/AtaxCudaOptConfig_P_j_i_T4_4_1_1_1_/group1_cuda.cu index ff22ba8c4..5d6b4b2dd 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/ATAX/CUDA/AtaxCudaOptConfig_P_j_i_T4_4_1_1_1_/group1_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/ATAX/CUDA/AtaxCudaOptConfig_P_j_i_T4_4_1_1_1_/group1_cuda.cu @@ -1038,7 +1038,7 @@ void hmpp_codelet__ataxLoopa( int &hmppcg_status_, void * __h, const cudaDevice #if CUDA_VERSION >= 3020 y.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__ataxLoopa_loop0_<<>>(y.getDeviceAddr()); @@ -1047,7 +1047,7 @@ void hmpp_codelet__ataxLoopa( int &hmppcg_status_, void * __h, const cudaDevice if((hmppcg_status_ = CHECK_STATUS(cudaEventRecord(kernel_event, kernel_stream)))) return; y.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1066,7 +1066,7 @@ void hmpp_codelet__ataxLoopa( int &hmppcg_status_, void * __h, const cudaDevice tmp.makeStreamWait(kernel_stream); x.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__ataxLoopa_loop1_<<>>(a.getDeviceAddr(), tmp.getDeviceAddr(), x.getDeviceAddr()); @@ -1077,7 +1077,7 @@ void hmpp_codelet__ataxLoopa( int &hmppcg_status_, void * __h, const cudaDevice tmp.waitOnEvent(kernel_event); x.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1119,7 +1119,7 @@ void hmpp_codelet__ataxLoopb( int &hmppcg_status_, void * __h, const cudaDevice tmp_1.makeStreamWait(kernel_stream); y_1.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__ataxLoopb_loop0_<<>>(a_1.getDeviceAddr(), tmp_1.getDeviceAddr(), y_1.getDeviceAddr()); @@ -1130,7 +1130,7 @@ void hmpp_codelet__ataxLoopb( int &hmppcg_status_, void * __h, const cudaDevice tmp_1.waitOnEvent(kernel_event); y_1.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/BICG/CUDA/BicgCudaDefaultConfig/bicg_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/BICG/CUDA/BicgCudaDefaultConfig/bicg_cuda.cu index 34347038a..6944c3e36 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/BICG/CUDA/BicgCudaDefaultConfig/bicg_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/BICG/CUDA/BicgCudaDefaultConfig/bicg_cuda.cu @@ -1020,7 +1020,7 @@ void hmpp_codelet__runBicg( int &hmppcg_status_, void * __h, const cudaDevicePr #if CUDA_VERSION >= 3020 s.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runBicg_loop0_<<>>(s.getDeviceAddr()); @@ -1029,7 +1029,7 @@ void hmpp_codelet__runBicg( int &hmppcg_status_, void * __h, const cudaDevicePr if((hmppcg_status_ = CHECK_STATUS(cudaEventRecord(kernel_event, kernel_stream)))) return; s.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1052,7 +1052,7 @@ void hmpp_codelet__runBicg( int &hmppcg_status_, void * __h, const cudaDevicePr r.makeStreamWait(kernel_stream); s.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runBicg_loop1_<<>>(i_2, a.getDeviceAddr(), r.getDeviceAddr(), s.getDeviceAddr()); @@ -1063,7 +1063,7 @@ void hmpp_codelet__runBicg( int &hmppcg_status_, void * __h, const cudaDevicePr r.waitOnEvent(kernel_event); s.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1084,7 +1084,7 @@ void hmpp_codelet__runBicg( int &hmppcg_status_, void * __h, const cudaDevicePr p.makeStreamWait(kernel_stream); q.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runBicg_loop2_<<>>(a.getDeviceAddr(), p.getDeviceAddr(), q.getDeviceAddr()); @@ -1095,7 +1095,7 @@ void hmpp_codelet__runBicg( int &hmppcg_status_, void * __h, const cudaDevicePr p.waitOnEvent(kernel_event); q.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/BICG/CUDA/BicgCudaOptConfig_P_j_i_T1_2_2_2_2_/bicg_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/BICG/CUDA/BicgCudaOptConfig_P_j_i_T1_2_2_2_2_/bicg_cuda.cu index 3a95687ad..dc74b528e 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/BICG/CUDA/BicgCudaOptConfig_P_j_i_T1_2_2_2_2_/bicg_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/BICG/CUDA/BicgCudaOptConfig_P_j_i_T1_2_2_2_2_/bicg_cuda.cu @@ -1048,7 +1048,7 @@ void hmpp_codelet__runBicg( int &hmppcg_status_, void * __h, const cudaDevicePr #if CUDA_VERSION >= 3020 s.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runBicg_loop0_<<>>(s.getDeviceAddr()); @@ -1057,7 +1057,7 @@ void hmpp_codelet__runBicg( int &hmppcg_status_, void * __h, const cudaDevicePr if((hmppcg_status_ = CHECK_STATUS(cudaEventRecord(kernel_event, kernel_stream)))) return; s.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1076,7 +1076,7 @@ void hmpp_codelet__runBicg( int &hmppcg_status_, void * __h, const cudaDevicePr r.makeStreamWait(kernel_stream); s.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runBicg_loop1_<<>>(a.getDeviceAddr(), r.getDeviceAddr(), s.getDeviceAddr()); @@ -1087,7 +1087,7 @@ void hmpp_codelet__runBicg( int &hmppcg_status_, void * __h, const cudaDevicePr r.waitOnEvent(kernel_event); s.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1106,7 +1106,7 @@ void hmpp_codelet__runBicg( int &hmppcg_status_, void * __h, const cudaDevicePr p.makeStreamWait(kernel_stream); q.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runBicg_loop2_<<>>(a.getDeviceAddr(), p.getDeviceAddr(), q.getDeviceAddr()); @@ -1117,7 +1117,7 @@ void hmpp_codelet__runBicg( int &hmppcg_status_, void * __h, const cudaDevicePr p.waitOnEvent(kernel_event); q.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/CORR/CUDA/CorrCudaDefaultConfig/corr_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/CORR/CUDA/CorrCudaDefaultConfig/corr_cuda.cu index f725ce5bd..cc3255450 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/CORR/CUDA/CorrCudaDefaultConfig/corr_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/CORR/CUDA/CorrCudaDefaultConfig/corr_cuda.cu @@ -1135,7 +1135,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pdata.makeStreamWait(kernel_stream); pmean.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runCorr_loop0_<<>>(pdata.getDeviceAddr(), pmean.getDeviceAddr()); @@ -1145,7 +1145,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pdata.waitOnEvent(kernel_event); pmean.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1164,7 +1164,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pmean.makeStreamWait(kernel_stream); pstddev.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runCorr_loop1_<<>>(pdata.getDeviceAddr(), pmean.getDeviceAddr(), pstddev.getDeviceAddr()); @@ -1175,7 +1175,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pmean.waitOnEvent(kernel_event); pstddev.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1194,7 +1194,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pmean.makeStreamWait(kernel_stream); pstddev.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runCorr_loop2_<<>>(pdata.getDeviceAddr(), pmean.getDeviceAddr(), pstddev.getDeviceAddr()); @@ -1205,7 +1205,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pmean.waitOnEvent(kernel_event); pstddev.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1223,7 +1223,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pdata.makeStreamWait(kernel_stream); psymmat.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runCorr_loop3_<<>>(pdata.getDeviceAddr(), psymmat.getDeviceAddr()); @@ -1233,7 +1233,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pdata.waitOnEvent(kernel_event); psymmat.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1250,7 +1250,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr #if CUDA_VERSION >= 3020 psymmat.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runCorr_loop4_<<>>(psymmat.getDeviceAddr()); @@ -1259,7 +1259,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr if((hmppcg_status_ = CHECK_STATUS(cudaEventRecord(kernel_event, kernel_stream)))) return; psymmat.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/CORR/CUDA/CorrCudaOptConfig_P_T1_1_1_1_1_1_1_1_4_8thLoopParallelizedNot7th/corr_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/CORR/CUDA/CorrCudaOptConfig_P_T1_1_1_1_1_1_1_1_4_8thLoopParallelizedNot7th/corr_cuda.cu index b798031dc..ff7f6cfb0 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/CORR/CUDA/CorrCudaOptConfig_P_T1_1_1_1_1_1_1_1_4_8thLoopParallelizedNot7th/corr_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/CORR/CUDA/CorrCudaOptConfig_P_T1_1_1_1_1_1_1_1_4_8thLoopParallelizedNot7th/corr_cuda.cu @@ -1148,7 +1148,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pdata.makeStreamWait(kernel_stream); pmean.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runCorr_loop0_<<>>(pdata.getDeviceAddr(), pmean.getDeviceAddr()); @@ -1158,7 +1158,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pdata.waitOnEvent(kernel_event); pmean.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1177,7 +1177,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pmean.makeStreamWait(kernel_stream); pstddev.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runCorr_loop1_<<>>(pdata.getDeviceAddr(), pmean.getDeviceAddr(), pstddev.getDeviceAddr()); @@ -1188,7 +1188,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pmean.waitOnEvent(kernel_event); pstddev.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1207,7 +1207,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pmean.makeStreamWait(kernel_stream); pstddev.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runCorr_loop2_<<>>(pdata.getDeviceAddr(), pmean.getDeviceAddr(), pstddev.getDeviceAddr()); @@ -1218,7 +1218,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pmean.waitOnEvent(kernel_event); pstddev.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1241,7 +1241,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr #if CUDA_VERSION >= 3020 psymmat.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runCorr_loop3_<<>>(j1_1, psymmat.getDeviceAddr()); @@ -1250,7 +1250,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr if((hmppcg_status_ = CHECK_STATUS(cudaEventRecord(kernel_event, kernel_stream)))) return; psymmat.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1269,7 +1269,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pdata.makeStreamWait(kernel_stream); psymmat.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runCorr_loop4_<<>>(j1_1, pdata.getDeviceAddr(), psymmat.getDeviceAddr()); @@ -1279,7 +1279,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr pdata.waitOnEvent(kernel_event); psymmat.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1298,7 +1298,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr #if CUDA_VERSION >= 3020 psymmat.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runCorr_loop5_<<>>(psymmat.getDeviceAddr()); @@ -1307,7 +1307,7 @@ void hmpp_codelet__runCorr( int &hmppcg_status_, void * __h, const cudaDevicePr if((hmppcg_status_ = CHECK_STATUS(cudaEventRecord(kernel_event, kernel_stream)))) return; psymmat.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/COVAR/CUDA/CovarCudaDefaultConfig/group1_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/COVAR/CUDA/CovarCudaDefaultConfig/group1_cuda.cu index 6c52c65f5..8a31559d9 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/COVAR/CUDA/CovarCudaDefaultConfig/group1_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/COVAR/CUDA/CovarCudaDefaultConfig/group1_cuda.cu @@ -1048,7 +1048,7 @@ void hmpp_codelet__covarLoopa( int &hmppcg_status_, void * __h, const cudaDevic pdata.makeStreamWait(kernel_stream); pmean.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__covarLoopa_loop0_<<>>(pdata.getDeviceAddr(), pmean.getDeviceAddr()); @@ -1058,7 +1058,7 @@ void hmpp_codelet__covarLoopa( int &hmppcg_status_, void * __h, const cudaDevic pdata.waitOnEvent(kernel_event); pmean.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1095,7 +1095,7 @@ void hmpp_codelet__covarLoopb( int &hmppcg_status_, void * __h, const cudaDevic pdata_2.makeStreamWait(kernel_stream); pmean_1.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__covarLoopb_loop0_<<>>(pdata_2.getDeviceAddr(), pmean_1.getDeviceAddr()); @@ -1105,7 +1105,7 @@ void hmpp_codelet__covarLoopb( int &hmppcg_status_, void * __h, const cudaDevic pdata_2.waitOnEvent(kernel_event); pmean_1.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1154,7 +1154,7 @@ void hmpp_codelet__covarLoopc( int &hmppcg_status_, void * __h, const cudaDevic pdata_1.makeStreamWait(kernel_stream); psymmat.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__covarLoopc_loop0_<<>>(pdata_1.getDeviceAddr(), psymmat.getDeviceAddr()); @@ -1164,7 +1164,7 @@ void hmpp_codelet__covarLoopc( int &hmppcg_status_, void * __h, const cudaDevic pdata_1.waitOnEvent(kernel_event); psymmat.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/COVAR/CUDA/CovarCudaOptConfig_P_U1sn1sn1sn1sn1sn1sn4sn_Parallelize6thLoopNot5th/group1_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/COVAR/CUDA/CovarCudaOptConfig_P_U1sn1sn1sn1sn1sn1sn4sn_Parallelize6thLoopNot5th/group1_cuda.cu index 23f936210..98bd14d25 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/COVAR/CUDA/CovarCudaOptConfig_P_U1sn1sn1sn1sn1sn1sn4sn_Parallelize6thLoopNot5th/group1_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/COVAR/CUDA/CovarCudaOptConfig_P_U1sn1sn1sn1sn1sn1sn4sn_Parallelize6thLoopNot5th/group1_cuda.cu @@ -1050,7 +1050,7 @@ void hmpp_codelet__covarLoopa( int &hmppcg_status_, void * __h, const cudaDevic pdata.makeStreamWait(kernel_stream); pmean.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__covarLoopa_loop0_<<>>(pdata.getDeviceAddr(), pmean.getDeviceAddr()); @@ -1060,7 +1060,7 @@ void hmpp_codelet__covarLoopa( int &hmppcg_status_, void * __h, const cudaDevic pdata.waitOnEvent(kernel_event); pmean.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1097,7 +1097,7 @@ void hmpp_codelet__covarLoopb( int &hmppcg_status_, void * __h, const cudaDevic pdata_2.makeStreamWait(kernel_stream); pmean_1.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__covarLoopb_loop0_<<>>(pdata_2.getDeviceAddr(), pmean_1.getDeviceAddr()); @@ -1107,7 +1107,7 @@ void hmpp_codelet__covarLoopb( int &hmppcg_status_, void * __h, const cudaDevic pdata_2.waitOnEvent(kernel_event); pmean_1.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1160,7 +1160,7 @@ void hmpp_codelet__covarLoopc( int &hmppcg_status_, void * __h, const cudaDevic pdata_1.makeStreamWait(kernel_stream); psymmat.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__covarLoopc_loop0_<<>>(j1_2, pdata_1.getDeviceAddr(), psymmat.getDeviceAddr()); @@ -1170,7 +1170,7 @@ void hmpp_codelet__covarLoopc( int &hmppcg_status_, void * __h, const cudaDevic pdata_1.waitOnEvent(kernel_event); psymmat.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/FDTD-2D/CUDA/Fdtd2DCudaDefaultConfig/fdtd_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/FDTD-2D/CUDA/Fdtd2DCudaDefaultConfig/fdtd_cuda.cu index f275b8516..37719b623 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/FDTD-2D/CUDA/Fdtd2DCudaDefaultConfig/fdtd_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/FDTD-2D/CUDA/Fdtd2DCudaDefaultConfig/fdtd_cuda.cu @@ -1058,7 +1058,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ey.makeStreamWait(kernel_stream); fict.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runFdtd_loop0_<<>>(t_1, ey.getDeviceAddr(), fict.getDeviceAddr()); @@ -1068,7 +1068,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ey.waitOnEvent(kernel_event); fict.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1086,7 +1086,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ey.makeStreamWait(kernel_stream); hz.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runFdtd_loop1_<<>>(ey.getDeviceAddr(), hz.getDeviceAddr()); @@ -1096,7 +1096,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ey.waitOnEvent(kernel_event); hz.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1114,7 +1114,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ex.makeStreamWait(kernel_stream); hz.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runFdtd_loop2_<<>>(ex.getDeviceAddr(), hz.getDeviceAddr()); @@ -1124,7 +1124,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ex.waitOnEvent(kernel_event); hz.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1143,7 +1143,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ey.makeStreamWait(kernel_stream); hz.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runFdtd_loop3_<<>>(ex.getDeviceAddr(), ey.getDeviceAddr(), hz.getDeviceAddr()); @@ -1154,7 +1154,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ey.waitOnEvent(kernel_event); hz.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/FDTD-2D/CUDA/Fdtd2DCudaOptConfig_P_U1sn1sn1sn2sn1sn1sn1sn4sn/fdtd_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/FDTD-2D/CUDA/Fdtd2DCudaOptConfig_P_U1sn1sn1sn2sn1sn1sn1sn4sn/fdtd_cuda.cu index 1c53c63fa..fa6171d4c 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/FDTD-2D/CUDA/Fdtd2DCudaOptConfig_P_U1sn1sn1sn2sn1sn1sn1sn4sn/fdtd_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/FDTD-2D/CUDA/Fdtd2DCudaOptConfig_P_U1sn1sn1sn2sn1sn1sn1sn4sn/fdtd_cuda.cu @@ -1071,7 +1071,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ey.makeStreamWait(kernel_stream); fict.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runFdtd_loop0_<<>>(t_1, ey.getDeviceAddr(), fict.getDeviceAddr()); @@ -1081,7 +1081,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ey.waitOnEvent(kernel_event); fict.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1099,7 +1099,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ey.makeStreamWait(kernel_stream); hz.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runFdtd_loop1_<<>>(ey.getDeviceAddr(), hz.getDeviceAddr()); @@ -1109,7 +1109,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ey.waitOnEvent(kernel_event); hz.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1127,7 +1127,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ex.makeStreamWait(kernel_stream); hz.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runFdtd_loop2_<<>>(ex.getDeviceAddr(), hz.getDeviceAddr()); @@ -1137,7 +1137,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ex.waitOnEvent(kernel_event); hz.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1156,7 +1156,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ey.makeStreamWait(kernel_stream); hz.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runFdtd_loop3_<<>>(ex.getDeviceAddr(), ey.getDeviceAddr(), hz.getDeviceAddr()); @@ -1167,7 +1167,7 @@ void hmpp_codelet__runFdtd( int &hmppcg_status_, void * __h, const cudaDevicePr ey.waitOnEvent(kernel_event); hz.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GEMM/CUDA/GemmCudaDefaultConfig/gemm_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GEMM/CUDA/GemmCudaDefaultConfig/gemm_cuda.cu index 2d11c29ef..3524fd0af 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GEMM/CUDA/GemmCudaDefaultConfig/gemm_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GEMM/CUDA/GemmCudaDefaultConfig/gemm_cuda.cu @@ -990,7 +990,7 @@ void hmpp_codelet__runGemm( int &hmppcg_status_, void * __h, const cudaDevicePr b.makeStreamWait(kernel_stream); c.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runGemm_loop0_<<>>(a.getDeviceAddr(), b.getDeviceAddr(), c.getDeviceAddr()); @@ -1001,7 +1001,7 @@ void hmpp_codelet__runGemm( int &hmppcg_status_, void * __h, const cudaDevicePr b.waitOnEvent(kernel_event); c.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GEMM/CUDA/GemmCudaOptConfig_P_i_j_k_U1sn1sn3sn/gemm_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GEMM/CUDA/GemmCudaOptConfig_P_i_j_k_U1sn1sn3sn/gemm_cuda.cu index 1ceb38813..1ca355501 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GEMM/CUDA/GemmCudaOptConfig_P_i_j_k_U1sn1sn3sn/gemm_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GEMM/CUDA/GemmCudaOptConfig_P_i_j_k_U1sn1sn3sn/gemm_cuda.cu @@ -1014,7 +1014,7 @@ void hmpp_codelet__runGemm( int &hmppcg_status_, void * __h, const cudaDevicePr b.makeStreamWait(kernel_stream); c.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runGemm_loop0_<<>>(a.getDeviceAddr(), b.getDeviceAddr(), c.getDeviceAddr()); @@ -1025,7 +1025,7 @@ void hmpp_codelet__runGemm( int &hmppcg_status_, void * __h, const cudaDevicePr b.waitOnEvent(kernel_event); c.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GESUMMV/CUDA/GesummvCudaDefaultConfig/gesummv_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GESUMMV/CUDA/GesummvCudaDefaultConfig/gesummv_cuda.cu index 924bb52f4..4097b521b 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GESUMMV/CUDA/GesummvCudaDefaultConfig/gesummv_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GESUMMV/CUDA/GesummvCudaDefaultConfig/gesummv_cuda.cu @@ -1004,7 +1004,7 @@ void hmpp_codelet__runGesummv( int &hmppcg_status_, void * __h, const cudaDevic x1.makeStreamWait(kernel_stream); y1.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runGesummv_loop0_<<>>(a.getDeviceAddr(), b.getDeviceAddr(), tmp1.getDeviceAddr(), x1.getDeviceAddr(), y1.getDeviceAddr()); @@ -1017,7 +1017,7 @@ void hmpp_codelet__runGesummv( int &hmppcg_status_, void * __h, const cudaDevic x1.waitOnEvent(kernel_event); y1.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GESUMMV/CUDA/GesummvCudaOptConfig_P_i_j_T4_2/gesummv_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GESUMMV/CUDA/GesummvCudaOptConfig_P_i_j_T4_2/gesummv_cuda.cu index bbe85bb0b..dc233113c 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GESUMMV/CUDA/GesummvCudaOptConfig_P_i_j_T4_2/gesummv_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GESUMMV/CUDA/GesummvCudaOptConfig_P_i_j_T4_2/gesummv_cuda.cu @@ -1017,7 +1017,7 @@ void hmpp_codelet__runGesummv( int &hmppcg_status_, void * __h, const cudaDevic x1.makeStreamWait(kernel_stream); y1.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runGesummv_loop0_<<>>(a.getDeviceAddr(), b.getDeviceAddr(), tmp1.getDeviceAddr(), x1.getDeviceAddr(), y1.getDeviceAddr()); @@ -1030,7 +1030,7 @@ void hmpp_codelet__runGesummv( int &hmppcg_status_, void * __h, const cudaDevic x1.waitOnEvent(kernel_event); y1.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GRAMSCHM/CUDA/GramschmidtCudaDefaultConfig/gramschmidt_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GRAMSCHM/CUDA/GramschmidtCudaDefaultConfig/gramschmidt_cuda.cu index fc10b5932..f62b6edd6 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GRAMSCHM/CUDA/GramschmidtCudaDefaultConfig/gramschmidt_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GRAMSCHM/CUDA/GramschmidtCudaDefaultConfig/gramschmidt_cuda.cu @@ -1049,7 +1049,7 @@ void hmpp_codelet__runGramSchmidt( int &hmppcg_status_, void * __h, const cudaD pA.makeStreamWait(kernel_stream); pR.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runGramSchmidt_loop0_<<>>(k_1, pA.getDeviceAddr(), pR.getDeviceAddr()); @@ -1059,7 +1059,7 @@ void hmpp_codelet__runGramSchmidt( int &hmppcg_status_, void * __h, const cudaD pA.waitOnEvent(kernel_event); pR.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1078,7 +1078,7 @@ void hmpp_codelet__runGramSchmidt( int &hmppcg_status_, void * __h, const cudaD pQ.makeStreamWait(kernel_stream); pR.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runGramSchmidt_loop1_<<>>(k_1, pA.getDeviceAddr(), pQ.getDeviceAddr(), pR.getDeviceAddr()); @@ -1089,7 +1089,7 @@ void hmpp_codelet__runGramSchmidt( int &hmppcg_status_, void * __h, const cudaD pQ.waitOnEvent(kernel_event); pR.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1109,7 +1109,7 @@ void hmpp_codelet__runGramSchmidt( int &hmppcg_status_, void * __h, const cudaD pQ.makeStreamWait(kernel_stream); pR.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runGramSchmidt_loop2_<<>>(k_1, pA.getDeviceAddr(), pQ.getDeviceAddr(), pR.getDeviceAddr()); @@ -1120,7 +1120,7 @@ void hmpp_codelet__runGramSchmidt( int &hmppcg_status_, void * __h, const cudaD pQ.waitOnEvent(kernel_event); pR.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GRAMSCHM/CUDA/GramschmidtCudaOptConfig_P_U1__1__1__1__3sn3sn/gramschmidt_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GRAMSCHM/CUDA/GramschmidtCudaOptConfig_P_U1__1__1__1__3sn3sn/gramschmidt_cuda.cu index 6144ddca3..7f6609944 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GRAMSCHM/CUDA/GramschmidtCudaOptConfig_P_U1__1__1__1__3sn3sn/gramschmidt_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/GRAMSCHM/CUDA/GramschmidtCudaOptConfig_P_U1__1__1__1__3sn3sn/gramschmidt_cuda.cu @@ -1073,7 +1073,7 @@ void hmpp_codelet__runGramSchmidt( int &hmppcg_status_, void * __h, const cudaD pA.makeStreamWait(kernel_stream); pR.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runGramSchmidt_loop0_<<>>(k_1, pA.getDeviceAddr(), pR.getDeviceAddr()); @@ -1083,7 +1083,7 @@ void hmpp_codelet__runGramSchmidt( int &hmppcg_status_, void * __h, const cudaD pA.waitOnEvent(kernel_event); pR.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1102,7 +1102,7 @@ void hmpp_codelet__runGramSchmidt( int &hmppcg_status_, void * __h, const cudaD pQ.makeStreamWait(kernel_stream); pR.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runGramSchmidt_loop1_<<>>(k_1, pA.getDeviceAddr(), pQ.getDeviceAddr(), pR.getDeviceAddr()); @@ -1113,7 +1113,7 @@ void hmpp_codelet__runGramSchmidt( int &hmppcg_status_, void * __h, const cudaD pQ.waitOnEvent(kernel_event); pR.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1133,7 +1133,7 @@ void hmpp_codelet__runGramSchmidt( int &hmppcg_status_, void * __h, const cudaD pQ.makeStreamWait(kernel_stream); pR.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runGramSchmidt_loop2_<<>>(k_1, pA.getDeviceAddr(), pQ.getDeviceAddr(), pR.getDeviceAddr()); @@ -1144,7 +1144,7 @@ void hmpp_codelet__runGramSchmidt( int &hmppcg_status_, void * __h, const cudaD pQ.waitOnEvent(kernel_event); pR.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/MVT/CUDA/MvtCudaDefaultConfig/mvt_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/MVT/CUDA/MvtCudaDefaultConfig/mvt_cuda.cu index 6c2c1492b..4451d1307 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/MVT/CUDA/MvtCudaDefaultConfig/mvt_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/MVT/CUDA/MvtCudaDefaultConfig/mvt_cuda.cu @@ -1004,7 +1004,7 @@ void hmpp_codelet__runMvt( int &hmppcg_status_, void * __h, const cudaDevicePro x1.makeStreamWait(kernel_stream); y1.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runMvt_loop0_<<>>(a.getDeviceAddr(), x1.getDeviceAddr(), y1.getDeviceAddr()); @@ -1015,7 +1015,7 @@ void hmpp_codelet__runMvt( int &hmppcg_status_, void * __h, const cudaDevicePro x1.waitOnEvent(kernel_event); y1.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1034,7 +1034,7 @@ void hmpp_codelet__runMvt( int &hmppcg_status_, void * __h, const cudaDevicePro x2.makeStreamWait(kernel_stream); y2.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runMvt_loop1_<<>>(a.getDeviceAddr(), x2.getDeviceAddr(), y2.getDeviceAddr()); @@ -1045,7 +1045,7 @@ void hmpp_codelet__runMvt( int &hmppcg_status_, void * __h, const cudaDevicePro x2.waitOnEvent(kernel_event); y2.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/MVT/CUDA/MvtCudaOptConfig_P_T_2_2_1_2/mvt_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/MVT/CUDA/MvtCudaOptConfig_P_T_2_2_1_2/mvt_cuda.cu index 4c7c196c4..0d0caf6e0 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/MVT/CUDA/MvtCudaOptConfig_P_T_2_2_1_2/mvt_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/MVT/CUDA/MvtCudaOptConfig_P_T_2_2_1_2/mvt_cuda.cu @@ -1026,7 +1026,7 @@ void hmpp_codelet__runMvt( int &hmppcg_status_, void * __h, const cudaDevicePro x1.makeStreamWait(kernel_stream); y1.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runMvt_loop0_<<>>(a.getDeviceAddr(), x1.getDeviceAddr(), y1.getDeviceAddr()); @@ -1037,7 +1037,7 @@ void hmpp_codelet__runMvt( int &hmppcg_status_, void * __h, const cudaDevicePro x1.waitOnEvent(kernel_event); y1.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1056,7 +1056,7 @@ void hmpp_codelet__runMvt( int &hmppcg_status_, void * __h, const cudaDevicePro x2.makeStreamWait(kernel_stream); y2.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runMvt_loop1_<<>>(a.getDeviceAddr(), x2.getDeviceAddr(), y2.getDeviceAddr()); @@ -1067,7 +1067,7 @@ void hmpp_codelet__runMvt( int &hmppcg_status_, void * __h, const cudaDevicePro x2.waitOnEvent(kernel_event); y2.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYR2K/CUDA/Syr2kCudaDefaultConfig/syrtwok_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYR2K/CUDA/Syr2kCudaDefaultConfig/syrtwok_cuda.cu index 8876f4744..ffb4fc97e 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYR2K/CUDA/Syr2kCudaDefaultConfig/syrtwok_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYR2K/CUDA/Syr2kCudaDefaultConfig/syrtwok_cuda.cu @@ -1024,7 +1024,7 @@ void hmpp_codelet__runSyrTwoK( int &hmppcg_status_, void * __h, const cudaDevic #if CUDA_VERSION >= 3020 c.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runSyrTwoK_loop0_<<>>(c.getDeviceAddr()); @@ -1033,7 +1033,7 @@ void hmpp_codelet__runSyrTwoK( int &hmppcg_status_, void * __h, const cudaDevic if((hmppcg_status_ = CHECK_STATUS(cudaEventRecord(kernel_event, kernel_stream)))) return; c.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1052,7 +1052,7 @@ void hmpp_codelet__runSyrTwoK( int &hmppcg_status_, void * __h, const cudaDevic b.makeStreamWait(kernel_stream); c.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runSyrTwoK_loop1_<<>>(a.getDeviceAddr(), b.getDeviceAddr(), c.getDeviceAddr()); @@ -1063,7 +1063,7 @@ void hmpp_codelet__runSyrTwoK( int &hmppcg_status_, void * __h, const cudaDevic b.waitOnEvent(kernel_event); c.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYR2K/CUDA/Syr2kCudaOptConfig_P_U1s_1s_1s_1s_3s_/syrtwok_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYR2K/CUDA/Syr2kCudaOptConfig_P_U1s_1s_1s_1s_3s_/syrtwok_cuda.cu index 55570e221..d45f7f666 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYR2K/CUDA/Syr2kCudaOptConfig_P_U1s_1s_1s_1s_3s_/syrtwok_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYR2K/CUDA/Syr2kCudaOptConfig_P_U1s_1s_1s_1s_3s_/syrtwok_cuda.cu @@ -1042,7 +1042,7 @@ void hmpp_codelet__runSyrTwoK( int &hmppcg_status_, void * __h, const cudaDevic #if CUDA_VERSION >= 3020 c.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runSyrTwoK_loop0_<<>>(c.getDeviceAddr()); @@ -1051,7 +1051,7 @@ void hmpp_codelet__runSyrTwoK( int &hmppcg_status_, void * __h, const cudaDevic if((hmppcg_status_ = CHECK_STATUS(cudaEventRecord(kernel_event, kernel_stream)))) return; c.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1070,7 +1070,7 @@ void hmpp_codelet__runSyrTwoK( int &hmppcg_status_, void * __h, const cudaDevic b.makeStreamWait(kernel_stream); c.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runSyrTwoK_loop1_<<>>(a.getDeviceAddr(), b.getDeviceAddr(), c.getDeviceAddr()); @@ -1081,7 +1081,7 @@ void hmpp_codelet__runSyrTwoK( int &hmppcg_status_, void * __h, const cudaDevic b.waitOnEvent(kernel_event); c.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYRK/CUDA/SyrkCudaDefaultConfig/syrk_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYRK/CUDA/SyrkCudaDefaultConfig/syrk_cuda.cu index e82b6c873..40cceee6c 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYRK/CUDA/SyrkCudaDefaultConfig/syrk_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYRK/CUDA/SyrkCudaDefaultConfig/syrk_cuda.cu @@ -1019,7 +1019,7 @@ void hmpp_codelet__runSyrk( int &hmppcg_status_, void * __h, const cudaDevicePr #if CUDA_VERSION >= 3020 c.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runSyrk_loop0_<<>>(c.getDeviceAddr()); @@ -1028,7 +1028,7 @@ void hmpp_codelet__runSyrk( int &hmppcg_status_, void * __h, const cudaDevicePr if((hmppcg_status_ = CHECK_STATUS(cudaEventRecord(kernel_event, kernel_stream)))) return; c.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1046,7 +1046,7 @@ void hmpp_codelet__runSyrk( int &hmppcg_status_, void * __h, const cudaDevicePr a.makeStreamWait(kernel_stream); c.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runSyrk_loop1_<<>>(a.getDeviceAddr(), c.getDeviceAddr()); @@ -1056,7 +1056,7 @@ void hmpp_codelet__runSyrk( int &hmppcg_status_, void * __h, const cudaDevicePr a.waitOnEvent(kernel_event); c.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYRK/CUDA/SyrkCudaOptConfig_P_i_U1__1__1__1__2sn/syrk_cuda.cu b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYRK/CUDA/SyrkCudaOptConfig_P_i_U1__1__1__1__2sn/syrk_cuda.cu index ed5f79ac4..0bf87f7fb 100644 --- a/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYRK/CUDA/SyrkCudaOptConfig_P_i_U1__1__1__1__2sn/syrk_cuda.cu +++ b/src/cuda/polybench-gpu-1.0/HmppDefaultAndOptimized/SYRK/CUDA/SyrkCudaOptConfig_P_i_U1__1__1__1__2sn/syrk_cuda.cu @@ -1025,7 +1025,7 @@ void hmpp_codelet__runSyrk( int &hmppcg_status_, void * __h, const cudaDevicePr #if CUDA_VERSION >= 3020 c.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runSyrk_loop0_<<>>(c.getDeviceAddr()); @@ -1034,7 +1034,7 @@ void hmpp_codelet__runSyrk( int &hmppcg_status_, void * __h, const cudaDevicePr if((hmppcg_status_ = CHECK_STATUS(cudaEventRecord(kernel_event, kernel_stream)))) return; c.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; @@ -1052,7 +1052,7 @@ void hmpp_codelet__runSyrk( int &hmppcg_status_, void * __h, const cudaDevicePr a.makeStreamWait(kernel_stream); c.makeStreamWait(kernel_stream); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif dim3 dim_block(blockDimX__, blockDimY__); hmpp_codelet__runSyrk_loop1_<<>>(a.getDeviceAddr(), c.getDeviceAddr()); @@ -1062,7 +1062,7 @@ void hmpp_codelet__runSyrk( int &hmppcg_status_, void * __h, const cudaDevicePr a.waitOnEvent(kernel_event); c.waitOnEvent(kernel_event); #else - if ((hmppcg_status_ = CHECK_STATUS(cudaThreadSynchronize()))) return; + if ((hmppcg_status_ = CHECK_STATUS(cudaDeviceSynchronize()))) return; #endif }; diff --git a/src/cuda/proxy-apps-doe/cns/compile.bash b/src/cuda/proxy-apps-doe/cns/compile.bash index 21dc00503..5e6dca0e4 100755 --- a/src/cuda/proxy-apps-doe/cns/compile.bash +++ b/src/cuda/proxy-apps-doe/cns/compile.bash @@ -68,4 +68,7 @@ do done #nvcc -arch=sm_20 -Xptxas -v,-abi=no prototype_simple.cu $FLAGS -o cns_all -lcudart -nvcc -Xptxas -v prototype_simple.cu $FLAGS -o cns_all -lcudart +# $CUDA_CPPFLAGS comes from src/setup_environment and carries the -gencode +# list (including sm_103) plus -std=c++17; without it nvcc builds only for +# its default arch and Blackwell has to JIT from PTX. +nvcc -Xptxas -v prototype_simple.cu $FLAGS $CUDA_CPPFLAGS -o cns_all -lcudart diff --git a/src/cuda/proxy-apps-doe/comd/Makefile b/src/cuda/proxy-apps-doe/comd/Makefile index c87fc153f..2ee147e32 100755 --- a/src/cuda/proxy-apps-doe/comd/Makefile +++ b/src/cuda/proxy-apps-doe/comd/Makefile @@ -13,7 +13,7 @@ GENCODE_SM50 := -gencode=arch=compute_50,code=\"sm_50,compute_50\" GENCODE_SM60 := -gencode=arch=compute_60,code=\"sm_60,compute_60\" GENCODE_SM62 := -gencode=arch=compute_62,code=\"sm_62,compute_62\" -CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) +CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) # Precision option PREC_FLAG = -DDOUBLE diff --git a/src/cuda/proxy-apps-doe/lulesh/lulesh.cu b/src/cuda/proxy-apps-doe/lulesh/lulesh.cu index 6823ad850..c203a9a6a 100644 --- a/src/cuda/proxy-apps-doe/lulesh/lulesh.cu +++ b/src/cuda/proxy-apps-doe/lulesh/lulesh.cu @@ -112,7 +112,7 @@ __host__ inline real10 FMAX(real10 arg1,real10 arg2) { return fmaxl(a #define CUDA(call) CUDA_SAFE_CALL(call) #ifdef CUDA_SYNC_ALL -#define CUDA_DEBUGSYNC CUDA(cudaThreadSynchronize()) +#define CUDA_DEBUGSYNC CUDA(cudaDeviceSynchronize()) #else #define CUDA_DEBUGSYNC #endif diff --git a/src/cuda/proxy-apps-doe/minife_matvec_ell/Makefile b/src/cuda/proxy-apps-doe/minife_matvec_ell/Makefile index 40de28a87..465910bb6 100755 --- a/src/cuda/proxy-apps-doe/minife_matvec_ell/Makefile +++ b/src/cuda/proxy-apps-doe/minife_matvec_ell/Makefile @@ -7,7 +7,7 @@ GENCODE_SM50 := -gencode=arch=compute_50,code=\"sm_50,compute_50\" GENCODE_SM60 := -gencode=arch=compute_60,code=\"sm_60,compute_60\" GENCODE_SM62 := -gencode=arch=compute_62,code=\"sm_62,compute_62\" -CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) +CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) EXECUTABLE = $(BINDIR)/$(BINSUBDIR)/matvec diff --git a/src/cuda/proxy-apps-doe/xsbench/makefile b/src/cuda/proxy-apps-doe/xsbench/makefile index 0943faac0..de6a93af3 100755 --- a/src/cuda/proxy-apps-doe/xsbench/makefile +++ b/src/cuda/proxy-apps-doe/xsbench/makefile @@ -18,7 +18,7 @@ GENCODE_SM50 := -gencode=arch=compute_50,code=\"sm_50,compute_50\" GENCODE_SM60 := -gencode=arch=compute_60,code=\"sm_60,compute_60\" GENCODE_SM62 := -gencode=arch=compute_62,code=\"sm_62,compute_62\" -CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) +CUOPTS = $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) #=============================================================================== # Program name & source code list #=============================================================================== diff --git a/src/cuda/rodinia/2.0-ft/backprop/backprop_cuda.cu b/src/cuda/rodinia/2.0-ft/backprop/backprop_cuda.cu index bed9aa524..2d4afeaea 100755 --- a/src/cuda/rodinia/2.0-ft/backprop/backprop_cuda.cu +++ b/src/cuda/rodinia/2.0-ft/backprop/backprop_cuda.cu @@ -129,7 +129,7 @@ void bpnn_train_cuda(BPNN *net, float *eo, float *eh) in, hid); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaError_t error = cudaGetLastError(); if (error != cudaSuccess) { diff --git a/src/cuda/rodinia/2.0-ft/hotspot/timer.h b/src/cuda/rodinia/2.0-ft/hotspot/timer.h index 2ebe859ce..8f97e951b 100755 --- a/src/cuda/rodinia/2.0-ft/hotspot/timer.h +++ b/src/cuda/rodinia/2.0-ft/hotspot/timer.h @@ -5,6 +5,17 @@ /*----------- using cycle counter ------------*/ +#if defined(__aarch64__) + __inline__ uint64_t rdtsc() + { + uint64_t val; + /* CNTVCT_EL0 is the aarch64 counterpart of x86 rdtsc. It ticks at + CNTFRQ_EL0 rather than the core clock, so counts are not + comparable across architectures. */ + __asm__ __volatile__ ("mrs %0, cntvct_el0" : "=r" (val)); + return val; + } +#else __inline__ uint64_t rdtsc() { uint32_t lo, hi; @@ -12,6 +23,7 @@ __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); return (uint64_t)hi << 32 | lo; } +#endif unsigned long long start_cycles; #define startCycle() (start_cycles = rdtsc()) diff --git a/src/cuda/rodinia/2.0-ft/kmeans/kmeans_cuda.cu b/src/cuda/rodinia/2.0-ft/kmeans/kmeans_cuda.cu index 8e047ff25..3a11177d4 100755 --- a/src/cuda/rodinia/2.0-ft/kmeans/kmeans_cuda.cu +++ b/src/cuda/rodinia/2.0-ft/kmeans/kmeans_cuda.cu @@ -150,6 +150,8 @@ kmeansCuda(float **feature, /* in: [npoints][nfeatures] */ { int delta = 0; /* if point has moved */ int i,j; /* counters */ + cudaTextureObject_t t_features = 0; + cudaTextureObject_t t_features_flipped = 0; double time_mem, time_kernel, time_back; @@ -163,31 +165,29 @@ kmeansCuda(float **feature, /* in: [npoints][nfeatures] */ /* copy clusters (host to device) */ cudaMemcpy(clusters_d, clusters[0], nclusters*nfeatures*sizeof(float), cudaMemcpyHostToDevice); - /* set up texture */ - cudaChannelFormatDesc chDesc0 = cudaCreateChannelDesc(); - t_features.filterMode = cudaFilterModePoint; - t_features.normalized = false; - t_features.channelDesc = chDesc0; - - if(cudaBindTexture(NULL, &t_features, feature_d, &chDesc0, npoints*nfeatures*sizeof(float)) != CUDA_SUCCESS) + /* set up texture objects (texture references were removed in CUDA 12) */ + cudaChannelFormatDesc chDesc = cudaCreateChannelDesc(); + + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeLinear; + resDesc.res.linear.desc = chDesc; + texDesc.filterMode = cudaFilterModePoint; + texDesc.normalizedCoords = false; + texDesc.readMode = cudaReadModeElementType; + + resDesc.res.linear.devPtr = feature_d; + resDesc.res.linear.sizeInBytes = npoints*nfeatures*sizeof(float); + if(cudaCreateTextureObject(&t_features, &resDesc, &texDesc, NULL) != cudaSuccess) printf("Couldn't bind features array to texture!\n"); - cudaChannelFormatDesc chDesc1 = cudaCreateChannelDesc(); - t_features.filterMode = cudaFilterModePoint; - t_features.normalized = false; - t_features.channelDesc = chDesc1; - - if(cudaBindTexture(NULL, &t_features_flipped, feature_flipped_d, &chDesc1, npoints*nfeatures*sizeof(float)) != CUDA_SUCCESS) + resDesc.res.linear.devPtr = feature_flipped_d; + resDesc.res.linear.sizeInBytes = npoints*nfeatures*sizeof(float); + if(cudaCreateTextureObject(&t_features_flipped, &resDesc, &texDesc, NULL) != cudaSuccess) printf("Couldn't bind features_flipped array to texture!\n"); - cudaChannelFormatDesc chDesc2 = cudaCreateChannelDesc(); - t_clusters.filterMode = cudaFilterModePoint; - t_clusters.normalized = false; - t_clusters.channelDesc = chDesc2; - - if(cudaBindTexture(NULL, &t_clusters, clusters_d, &chDesc2, nclusters*nfeatures*sizeof(float)) != CUDA_SUCCESS) - printf("Couldn't bind clusters array to texture!\n"); - /* copy clusters to constant memory */ cudaMemcpyToSymbol(c_clusters,clusters[0],nclusters*nfeatures*sizeof(float),0,cudaMemcpyHostToDevice); @@ -207,9 +207,14 @@ kmeansCuda(float **feature, /* in: [npoints][nfeatures] */ membership_d, clusters_d, block_clusters_d, - block_deltas_d); + block_deltas_d, + t_features, + t_features_flipped); + + cudaDeviceSynchronize(); - cudaThreadSynchronize(); + cudaDestroyTextureObject(t_features); + cudaDestroyTextureObject(t_features_flipped); // time_kernel = omp_get_wtime() - time_kernel; // time_back = omp_get_wtime(); diff --git a/src/cuda/rodinia/2.0-ft/kmeans/kmeans_cuda_kernel.cu b/src/cuda/rodinia/2.0-ft/kmeans/kmeans_cuda_kernel.cu index 802c58393..03f89be45 100755 --- a/src/cuda/rodinia/2.0-ft/kmeans/kmeans_cuda_kernel.cu +++ b/src/cuda/rodinia/2.0-ft/kmeans/kmeans_cuda_kernel.cu @@ -11,11 +11,6 @@ #define SDATA( index) CUT_BANK_CHECKER(sdata, index) -// t_features has the layout dim0[points 0-m-1]dim1[ points 0-m-1]... -texture t_features; -// t_features_flipped has the layout point0[dim 0-n-1]point1[dim 0-n-1] -texture t_features_flipped; -texture t_clusters; __constant__ float c_clusters[ASSUMED_NR_CLUSTERS*34]; /* constant memory for cluster centers */ @@ -62,7 +57,11 @@ kmeansPoint(float *features, /* in: [npoints*nfeatures] */ int *membership, float *clusters, float *block_clusters, - int *block_deltas) + int *block_deltas, + /* t_features has the layout dim0[points 0-m-1]dim1[ points 0-m-1]... */ + cudaTextureObject_t t_features, + /* t_features_flipped has the layout point0[dim 0-n-1]point1[dim 0-n-1] */ + cudaTextureObject_t t_features_flipped) { // block ID @@ -86,7 +85,7 @@ kmeansPoint(float *features, /* in: [npoints*nfeatures] */ for (j=0; j < nfeatures; j++) { int addr = point_id + j*npoints; /* appropriate index of data point */ - float diff = (tex1Dfetch(t_features,addr) - + float diff = (tex1Dfetch(t_features,addr) - c_clusters[cluster_base_index + j]); /* distance between a data point to cluster centers */ ans += diff*diff; /* sum of squares */ } @@ -167,7 +166,7 @@ kmeansPoint(float *features, /* in: [npoints*nfeatures] */ if(threadIdx.x < nfeatures * nclusters) { // accumulate over all the elements of this threadblock for(int i = 0; i< (THREADS_PER_BLOCK); i++) { - float val = tex1Dfetch(t_features_flipped,new_base_index+i*nfeatures); + float val = tex1Dfetch(t_features_flipped,new_base_index+i*nfeatures); if(new_center_ids[i] == center_id) accumulator += val; } diff --git a/src/cuda/rodinia/2.0-ft/nn/nn_cuda.cu b/src/cuda/rodinia/2.0-ft/nn/nn_cuda.cu index 800c24d08..3900c99d8 100755 --- a/src/cuda/rodinia/2.0-ft/nn/nn_cuda.cu +++ b/src/cuda/rodinia/2.0-ft/nn/nn_cuda.cu @@ -211,7 +211,7 @@ int main(int argc, char* argv[]) //Add a and b, store in c euclid<<>>(data, x2, y2, z_d, REC_WINDOW, REC_LENGTH, LATITUDE_POS); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); //Copy data from device memory to host memory cudaMemcpy( z, z_d, sizeof(float)*REC_WINDOW, cudaMemcpyDeviceToHost ); diff --git a/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/euler3d.cu b/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/euler3d.cu index 29c015842..2386b9244 100755 --- a/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/euler3d.cu +++ b/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/euler3d.cu @@ -496,7 +496,7 @@ int main(int argc, char** argv) initialize_variables(nelr, fluxes); cudaMemset( (void*) step_factors, 0, sizeof(float)*nelr ); // make sure CUDA isn't still doing something before we start timing - cudaThreadSynchronize(); + cudaDeviceSynchronize(); // these need to be computed the first time in order to compute time step std::cout << "Starting..." << std::endl; @@ -524,7 +524,7 @@ int main(int argc, char** argv) } } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CUT_SAFE_CALL( cutStopTimer(timer) ); std::cout << (cutGetAverageTimerValue(timer)/1000.0) / iterations << " seconds per iteration" << std::endl; diff --git a/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/euler3d_double.cu b/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/euler3d_double.cu index 33f658bc4..3d88b641c 100755 --- a/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/euler3d_double.cu +++ b/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/euler3d_double.cu @@ -498,7 +498,7 @@ int main(int argc, char** argv) initialize_variables(nelr, fluxes); cudaMemset( (void*) step_factors, 0, sizeof(double)*nelr ); // make sure CUDA isn't still doing something before we start timing - cudaThreadSynchronize(); + cudaDeviceSynchronize(); // these need to be computed the first time in order to compute time step std::cout << "Starting..." << std::endl; @@ -526,7 +526,7 @@ int main(int argc, char** argv) } } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CUT_SAFE_CALL( cutStopTimer(timer) ); std::cout << (cutGetAverageTimerValue(timer)/1000.0) / iterations << " seconds per iteration" << std::endl; diff --git a/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/pre_euler3d.cu b/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/pre_euler3d.cu index 180d10485..ce0e5684c 100755 --- a/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/pre_euler3d.cu +++ b/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/pre_euler3d.cu @@ -573,7 +573,7 @@ int main(int argc, char** argv) initialize_variables(nelr, fluxes); cudaMemset( (void*) step_factors, 0, sizeof(float)*nelr ); // make sure CUDA isn't still doing something before we start timing - cudaThreadSynchronize(); + cudaDeviceSynchronize(); // these need to be computed the first time in order to compute time step std::cout << "Starting..." << std::endl; @@ -599,7 +599,7 @@ int main(int argc, char** argv) } } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CUT_SAFE_CALL( cutStopTimer(timer) ); std::cout << (cutGetAverageTimerValue(timer)/1000.0) / iterations << " seconds per iteration" << std::endl; diff --git a/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/pre_euler3d_double.cu b/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/pre_euler3d_double.cu index d41641bc6..fd504578e 100755 --- a/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/pre_euler3d_double.cu +++ b/src/cuda/rodinia/2.0-ft/no-ft-impl/cfd/pre_euler3d_double.cu @@ -580,7 +580,7 @@ int main(int argc, char** argv) initialize_variables(nelr, fluxes); cudaMemset( (void*) step_factors, 0, sizeof(double)*nelr ); // make sure CUDA isn't still doing something before we start timing - cudaThreadSynchronize(); + cudaDeviceSynchronize(); // these need to be computed the first time in order to compute time step std::cout << "Starting..." << std::endl; @@ -606,7 +606,7 @@ int main(int argc, char** argv) } } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CUT_SAFE_CALL( cutStopTimer(timer) ); std::cout << (cutGetAverageTimerValue(timer)/1000.0) / iterations << " seconds per iteration" << std::endl; diff --git a/src/cuda/rodinia/2.0-ft/no-ft-impl/gaussian/gaussian.cu b/src/cuda/rodinia/2.0-ft/no-ft-impl/gaussian/gaussian.cu index e98eb5e05..9973cafac 100755 --- a/src/cuda/rodinia/2.0-ft/no-ft-impl/gaussian/gaussian.cu +++ b/src/cuda/rodinia/2.0-ft/no-ft-impl/gaussian/gaussian.cu @@ -283,9 +283,9 @@ void ForwardSub() gettimeofday(&time_start, NULL); for (t=0; t<(Size-1); t++) { Fan1<<>>(m_cuda,a_cuda,Size,t); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); Fan2<<>>(m_cuda,a_cuda,b_cuda,Size,Size-t,t); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); checkCUDAError("Fan2"); } // end timing kernels diff --git a/src/cuda/rodinia/2.0-ft/no-ft-impl/lavaMD/kernel/kernel_gpu_cuda_wrapper.cu b/src/cuda/rodinia/2.0-ft/no-ft-impl/lavaMD/kernel/kernel_gpu_cuda_wrapper.cu index 6feab499f..5bf4cdd50 100755 --- a/src/cuda/rodinia/2.0-ft/no-ft-impl/lavaMD/kernel/kernel_gpu_cuda_wrapper.cu +++ b/src/cuda/rodinia/2.0-ft/no-ft-impl/lavaMD/kernel/kernel_gpu_cuda_wrapper.cu @@ -63,7 +63,7 @@ kernel_gpu_cuda_wrapper(par_str par_cpu, // INITIAL DRIVER OVERHEAD //====================================================================================================100 - cudaThreadSynchronize(); + cudaDeviceSynchronize(); //====================================================================================================100 // VARIABLES @@ -193,7 +193,7 @@ kernel_gpu_cuda_wrapper(par_str par_cpu, d_fv_gpu); checkCUDAError("Start"); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); time4 = get_time(); diff --git a/src/cuda/rodinia/2.0-ft/no-ft-impl/leukocyte/CUDA/find_ellipse_kernel.cu b/src/cuda/rodinia/2.0-ft/no-ft-impl/leukocyte/CUDA/find_ellipse_kernel.cu index 4596ba914..9a6df0777 100755 --- a/src/cuda/rodinia/2.0-ft/no-ft-impl/leukocyte/CUDA/find_ellipse_kernel.cu +++ b/src/cuda/rodinia/2.0-ft/no-ft-impl/leukocyte/CUDA/find_ellipse_kernel.cu @@ -113,7 +113,7 @@ float *GICOV_CUDA(int grad_m, int grad_n, float *host_grad_x, float *host_grad_y GICOV_kernel <<< num_blocks, threads_per_block >>> (grad_m, device_gicov); // Check for kernel errors - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaError_t error = cudaGetLastError(); if (error != cudaSuccess) { printf("GICOV kernel error: %s\n", cudaGetErrorString(error)); @@ -204,7 +204,7 @@ float *dilate_CUDA(int max_gicov_m, int max_gicov_n, int strel_m, int strel_n) { dilate_kernel <<< num_blocks, threads_per_block >>> (max_gicov_m, max_gicov_n, strel_m, strel_n, device_img_dilated); // Check for kernel errors - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaError_t error = cudaGetLastError(); if (error != cudaSuccess) { printf("Dilation kernel error: %s\n", cudaGetErrorString(error)); diff --git a/src/cuda/rodinia/2.0-ft/no-ft-impl/leukocyte/CUDA/track_ellipse_kernel.cu b/src/cuda/rodinia/2.0-ft/no-ft-impl/leukocyte/CUDA/track_ellipse_kernel.cu index ed9faf902..70a347544 100755 --- a/src/cuda/rodinia/2.0-ft/no-ft-impl/leukocyte/CUDA/track_ellipse_kernel.cu +++ b/src/cuda/rodinia/2.0-ft/no-ft-impl/leukocyte/CUDA/track_ellipse_kernel.cu @@ -237,7 +237,7 @@ void IMGVF_cuda(MAT **I, MAT **IMGVF, double vx, double vy, double e, int max_it (float) vx, (float) vy, (float) e, max_iterations, (float) cutoff ); // Check for kernel errors - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaError_t error = cudaGetLastError(); if (error != cudaSuccess) { printf("MGVF kernel error: %s\n", cudaGetErrorString(error)); diff --git a/src/cuda/rodinia/2.0-ft/no-ft-impl/mummergpu/src/mummergpu.cu b/src/cuda/rodinia/2.0-ft/no-ft-impl/mummergpu/src/mummergpu.cu index 7c93970d9..f26eb2d15 100755 --- a/src/cuda/rodinia/2.0-ft/no-ft-impl/mummergpu/src/mummergpu.cu +++ b/src/cuda/rodinia/2.0-ft/no-ft-impl/mummergpu/src/mummergpu.cu @@ -1426,7 +1426,7 @@ void runPrintKernel(MatchContext* ctx, #endif ); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); @@ -1444,7 +1444,7 @@ void runPrintKernel(MatchContext* ctx, (void*)d_alignments, alignmentSize, cudaMemcpyDeviceToHost)); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); stopTimer(atimer); float atime = getTimerValue(atimer); @@ -1573,7 +1573,7 @@ void getExactAlignments(MatchContext * ctx, ReferencePage * page, bool on_cpu) if (num_bind_tex_calls > 100) { - cudaThreadExit(); + cudaDeviceReset(); num_bind_tex_calls = 0; loadReference(ctx); loadQueries(ctx); @@ -2021,7 +2021,7 @@ void matchQueryBlockToReferencePage(MatchContext* ctx, { matchOnGPU(ctx, reverse_complement); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); } stopTimer(ktimer); @@ -2110,7 +2110,7 @@ int matchQueriesToReferencePage(MatchContext* ctx, ReferencePage* page) destroyQueryBlock(ctx->queries); if (num_bind_tex_calls > 100) { - cudaThreadExit(); + cudaDeviceReset(); num_bind_tex_calls = 0; loadReference(ctx); } diff --git a/src/cuda/rodinia/2.0-ft/no-ft-impl/particlefilter/ex_particle_CUDA_float_seq.cu b/src/cuda/rodinia/2.0-ft/no-ft-impl/particlefilter/ex_particle_CUDA_float_seq.cu index 1baa90a56..550dd4d24 100755 --- a/src/cuda/rodinia/2.0-ft/no-ft-impl/particlefilter/ex_particle_CUDA_float_seq.cu +++ b/src/cuda/rodinia/2.0-ft/no-ft-impl/particlefilter/ex_particle_CUDA_float_seq.cu @@ -680,7 +680,7 @@ void particleFilter(unsigned char * I, int IszX, int IszY, int Nfr, int * seed, }//end loop //block till kernels are finished - cudaThreadSynchronize(); + cudaDeviceSynchronize(); long long back_time = get_time(); cudaFree(xj_GPU); diff --git a/src/cuda/rodinia/2.0-ft/no-ft-impl/particlefilter/ex_particle_CUDA_naive_seq.cu b/src/cuda/rodinia/2.0-ft/no-ft-impl/particlefilter/ex_particle_CUDA_naive_seq.cu index 17c86512e..7650ba803 100755 --- a/src/cuda/rodinia/2.0-ft/no-ft-impl/particlefilter/ex_particle_CUDA_naive_seq.cu +++ b/src/cuda/rodinia/2.0-ft/no-ft-impl/particlefilter/ex_particle_CUDA_naive_seq.cu @@ -569,7 +569,7 @@ void particleFilter(int * I, int IszX, int IszY, int Nfr, int * seed, int Nparti //KERNEL FUNCTION CALL kernel <<< num_blocks, threads_per_block >>> (arrayX_GPU, arrayY_GPU, CDF_GPU, u_GPU, xj_GPU, yj_GPU, Nparticles); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); long long start_copy_back = get_time(); //CUDA memory copying back from GPU to CPU memory cudaMemcpy(yj, yj_GPU, sizeof(double)*Nparticles, cudaMemcpyDeviceToHost); diff --git a/src/cuda/rodinia/2.0-ft/pathfinder/pathfinder.cu b/src/cuda/rodinia/2.0-ft/pathfinder/pathfinder.cu index 2dadf1630..737a414b4 100755 --- a/src/cuda/rodinia/2.0-ft/pathfinder/pathfinder.cu +++ b/src/cuda/rodinia/2.0-ft/pathfinder/pathfinder.cu @@ -120,6 +120,7 @@ __global__ void dynproc_kernel( if(IN_RANGE(xidx, 0, cols-1)){ prev[tx] = gpuSrc[xidx]; } + __syncthreads(); // prev[] is read by neighbours below bool computed; for (int i=0; i>>(m_cuda,a_cuda,Size,t); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); Fan2<<>>(m_cuda,a_cuda,b_cuda,Size,Size-t,t); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); checkCUDAError("Fan2"); } // end timing kernels diff --git a/src/cuda/rodinia/3.1/cuda/heartwall/Makefile b/src/cuda/rodinia/3.1/cuda/heartwall/Makefile index e481cb244..ee4b4656c 100755 --- a/src/cuda/rodinia/3.1/cuda/heartwall/Makefile +++ b/src/cuda/rodinia/3.1/cuda/heartwall/Makefile @@ -1,3 +1,9 @@ +# Link straight into the shared bin dir under the final benchmark name when +# setup_environment has been sourced, and build in place otherwise. This +# replaces the post-build 'mv' the top-level Makefile used to do, which +# stranded binaries in the source tree whenever a sibling app failed. +RODINIA_OUT ?= $(if $(BINDIR),$(BINDIR)/$(BINSUBDIR),.) + GENCODE_SM10 ?= -gencode=arch=compute_10,code=\"sm_10,compute_10\" GENCODE_SM13 ?= -gencode=arch=compute_13,code=\"sm_13,compute_13\" GENCODE_SM20 ?= -gencode=arch=compute_20,code=\"sm_20,compute_20\" @@ -13,12 +19,12 @@ override OUTPUT = -DOUTPUT endif # link objects(binaries) together -heartwall: main.o ./AVI/avilib.o ./AVI/avimod.o - nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) main.o ./AVI/avilib.o ./AVI/avimod.o -I/usr/local/cuda/include -lm -o heartwall -lcudart +$(RODINIA_OUT)/heartwall-rodinia-3.1: main.o ./AVI/avilib.o ./AVI/avimod.o + nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) main.o ./AVI/avilib.o ./AVI/avimod.o -I/usr/local/cuda/include -lm -o $(RODINIA_OUT)/heartwall-rodinia-3.1 -lcudart # compile main function file into object (binary) main.o: main.cu kernel.cu define.c - nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) $(OUTPUT) $(KERNEL_DIM) main.cu -I./AVI -c -O3 -lcudart + nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) $(OUTPUT) $(KERNEL_DIM) main.cu -I./AVI -c -O3 -lcudart ./AVI/avilib.o ./AVI/avimod.o: cd AVI; make; diff --git a/src/cuda/rodinia/3.1/cuda/hotspot/Makefile_nvidia b/src/cuda/rodinia/3.1/cuda/hotspot/Makefile_nvidia index 1f7ae25a9..53798f3bf 100755 --- a/src/cuda/rodinia/3.1/cuda/hotspot/Makefile_nvidia +++ b/src/cuda/rodinia/3.1/cuda/hotspot/Makefile_nvidia @@ -34,7 +34,7 @@ ################################################################################ # Add source files here -EXECUTABLE := hotspot +EXECUTABLE := hotspot-rodinia-3.1 # CUDA source files (compiled with cudacc) CUFILES := hotspot.cu # CUDA dependency files diff --git a/src/cuda/rodinia/3.1/cuda/hotspot3D/Makefile b/src/cuda/rodinia/3.1/cuda/hotspot3D/Makefile index 0c13c10b7..f0a7d4e3d 100755 --- a/src/cuda/rodinia/3.1/cuda/hotspot3D/Makefile +++ b/src/cuda/rodinia/3.1/cuda/hotspot3D/Makefile @@ -1,12 +1,18 @@ include ../../common/make.config +# Link straight into the shared bin dir under the final benchmark name when +# setup_environment has been sourced, and build in place otherwise. This +# replaces the post-build 'mv' the top-level Makefile used to do, which +# stranded binaries in the source tree whenever a sibling app failed. +RODINIA_OUT ?= $(if $(BINDIR),$(BINDIR)/$(BINSUBDIR),.) -CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) + +CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) INCLUDE := $(CUDA_DIR)/include SRC = 3D.cu -EXE = 3D +EXE = $(RODINIA_OUT)/hotspot3D-rodinia-3.1 OUTPUT = *.out diff --git a/src/cuda/rodinia/3.1/cuda/huffman/Makefile b/src/cuda/rodinia/3.1/cuda/huffman/Makefile index 1bfdd370e..12bd91bd7 100755 --- a/src/cuda/rodinia/3.1/cuda/huffman/Makefile +++ b/src/cuda/rodinia/3.1/cuda/huffman/Makefile @@ -1,15 +1,23 @@ +# Link straight into the shared bin dir under the final benchmark name when +# setup_environment has been sourced, and build in place otherwise. This +# replaces the post-build 'mv' the top-level Makefile used to do, which +# stranded binaries in the source tree whenever a sibling app failed. +RODINIA_OUT ?= $(if $(BINDIR),$(BINDIR)/$(BINSUBDIR),.) + NVCC=nvcc CC = g++ CUDA_INCLUDEPATH=$(CUDA_INSTALL_PATH)/include -NVCC_OPTS=-O3 -lcudart -Xcompiler -m64 -g -G $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) +# -m64 is an x86-only option; aarch64/ppc64le gcc rejects it outright. +M64 := $(if $(filter x86_64,$(shell uname -m)),-m64,) +NVCC_OPTS=-O3 -lcudart $(if $(M64),-Xcompiler $(M64),) -g -G $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) -GCC_OPTS=-O3 -Wall -Wextra -m64 +GCC_OPTS=-O3 -Wall -Wextra $(M64) OBJ = main_test_cu.o stats_logger.o vlc_kernel_sm64huff.o scan.o pack_kernels.o cpuencode.o SRC = main_test_cu.cu -EXE = pavle +EXE = $(RODINIA_OUT)/huffman-rodinia-3.1 ifdef TESTING override TESTING = -DTESTING @@ -19,7 +27,7 @@ ifdef CACHECWLUT override TESTING = -DCACHECWLUT endif -pavle: $(OBJ) +$(EXE): $(OBJ) $(NVCC) $(TESTING) $(CACHECWLUT) $(NVCC_OPTS) $(OBJ) -o $(EXE) vlc_kernel_sm64huff.o: vlc_kernel_sm64huff.cu diff --git a/src/cuda/rodinia/3.1/cuda/huffman/cutil.h b/src/cuda/rodinia/3.1/cuda/huffman/cutil.h index 648041e9e..d386cfff0 100644 --- a/src/cuda/rodinia/3.1/cuda/huffman/cutil.h +++ b/src/cuda/rodinia/3.1/cuda/huffman/cutil.h @@ -735,13 +735,13 @@ #if CUDART_VERSION >= 4000 #define CUT_DEVICE_SYNCHRONIZE( ) cudaDeviceSynchronize(); #else -#define CUT_DEVICE_SYNCHRONIZE( ) cudaThreadSynchronize(); +#define CUT_DEVICE_SYNCHRONIZE( ) cudaDeviceSynchronize(); #endif #if CUDART_VERSION >= 4000 #define CUT_DEVICE_RESET( ) cudaDeviceReset(); #else -#define CUT_DEVICE_RESET( ) cudaThreadExit(); +#define CUT_DEVICE_RESET( ) cudaDeviceReset(); #endif // This is for the CUTIL bank checker diff --git a/src/cuda/rodinia/3.1/cuda/huffman/hist.cu b/src/cuda/rodinia/3.1/cuda/huffman/hist.cu index 97e40f71a..5d4e4501c 100644 --- a/src/cuda/rodinia/3.1/cuda/huffman/hist.cu +++ b/src/cuda/rodinia/3.1/cuda/huffman/hist.cu @@ -66,7 +66,9 @@ int runHisto(char* file, unsigned int* freq, unsigned int memSize, unsigned int cudaDeviceProp prop; ( cudaGetDeviceProperties( &prop, 0 ) ); int blocks = prop.multiProcessorCount; - if(!prop.deviceOverlap) + int deviceOverlap = 0; + cudaDeviceGetAttribute( &deviceOverlap, cudaDevAttrGpuOverlap, 0 ); + if(!deviceOverlap) { cout << "No overlaps, so no speedup from streams" << endl; return 0; diff --git a/src/cuda/rodinia/3.1/cuda/huffman/main_test_cu.cu b/src/cuda/rodinia/3.1/cuda/huffman/main_test_cu.cu index f14854b3d..384f4606b 100755 --- a/src/cuda/rodinia/3.1/cuda/huffman/main_test_cu.cu +++ b/src/cuda/rodinia/3.1/cuda/huffman/main_test_cu.cu @@ -45,7 +45,7 @@ int main(int argc, char* argv[]){ for (int i=1; i #include #include "helper_cuda.h" -#include #include "bucketsort.cuh" // includes, kernels #include "bucketsort_kernel.cu" @@ -39,6 +38,7 @@ float *historesult = NULL; float *l_pivotpoints = NULL; unsigned int *d_prefixoffsets = NULL; unsigned int *l_offsets = NULL; +cudaTextureObject_t h_texPivot = 0; //////////////////////////////////////////////////////////////////////////////// // Initialize the bucketsort algorithm @@ -74,6 +74,10 @@ void finish_bucketsort() free(h_offsets); free(historesult); checkCudaErrors(cudaFree(d_prefixoffsets)); + if (h_texPivot) { + checkCudaErrors(cudaDestroyTextureObject(h_texPivot)); + h_texPivot = 0; + } closeHistogram1024(); } @@ -103,7 +107,19 @@ void bucketSort(float *d_input, float *d_output, int listsize, /////////////////////////////////////////////////////////////////////////// checkCudaErrors(cudaMemcpy(l_pivotpoints, pivotPoints, (DIVISIONS)*sizeof(int), cudaMemcpyHostToDevice)); checkCudaErrors(cudaMemset((void *) d_offsets, 0, DIVISIONS * sizeof(int))); - checkCudaErrors(cudaBindTexture(0, texPivot, l_pivotpoints, DIVISIONS * sizeof(int))); + { + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeLinear; + resDesc.res.linear.devPtr = l_pivotpoints; + resDesc.res.linear.desc = cudaCreateChannelDesc(); + resDesc.res.linear.sizeInBytes = DIVISIONS * sizeof(int); + texDesc.readMode = cudaReadModeElementType; + checkCudaErrors(cudaCreateTextureObject(&h_texPivot, &resDesc, &texDesc, NULL)); + checkCudaErrors(cudaMemcpyToSymbol(texPivot, &h_texPivot, sizeof(h_texPivot))); + } // Setup block and grid dim3 threads(BUCKET_THREAD_N, 1); int blocks = ((listsize - 1) / (threads.x * BUCKET_BAND)) + 1; diff --git a/src/cuda/rodinia/3.1/cuda/hybridsort/bucketsort_kernel.cu b/src/cuda/rodinia/3.1/cuda/hybridsort/bucketsort_kernel.cu index 5b2a8aa9e..a224c3adf 100755 --- a/src/cuda/rodinia/3.1/cuda/hybridsort/bucketsort_kernel.cu +++ b/src/cuda/rodinia/3.1/cuda/hybridsort/bucketsort_kernel.cu @@ -13,7 +13,9 @@ #define BUCKET_BLOCK_MEMORY (DIVISIONS * BUCKET_WARP_N) #define BUCKET_BAND 128 -texture texPivot; +/* Texture references were removed in CUDA 12; the host fills this handle + via cudaMemcpyToSymbol so the fetch sites below are unchanged. */ +__constant__ cudaTextureObject_t texPivot; __device__ int addOffset(volatile unsigned int *s_offset, unsigned int data, unsigned int threadTag){ unsigned int count; @@ -45,11 +47,11 @@ bucketcount( float *input, int *indice, unsigned int *d_prefixoffsets, int size) int idx = DIVISIONS/2 - 1; int jump = DIVISIONS/4; - float piv = tex1Dfetch(texPivot, idx); //s_pivotpoints[idx]; + float piv = tex1Dfetch(texPivot, idx); //s_pivotpoints[idx]; while(jump >= 1){ idx = (elem < piv) ? (idx - jump) : (idx + jump); - piv = tex1Dfetch(texPivot, idx); //s_pivotpoints[idx]; + piv = tex1Dfetch(texPivot, idx); //s_pivotpoints[idx]; jump /= 2; } idx = (elem < piv) ? idx : (idx + 1); diff --git a/src/cuda/rodinia/3.1/cuda/hybridsort/helper_cuda.h b/src/cuda/rodinia/3.1/cuda/hybridsort/helper_cuda.h index a9c321fb0..d0ac133ff 100644 --- a/src/cuda/rodinia/3.1/cuda/hybridsort/helper_cuda.h +++ b/src/cuda/rodinia/3.1/cuda/hybridsort/helper_cuda.h @@ -873,7 +873,10 @@ inline int gpuDeviceInit(int devID) cudaDeviceProp deviceProp; checkCudaErrors(cudaGetDeviceProperties(&deviceProp, devID)); - if (deviceProp.computeMode == cudaComputeModeProhibited) + int computeMode = cudaComputeModeDefault; + cudaDeviceGetAttribute(&computeMode, cudaDevAttrComputeMode, devID); + + if (computeMode == cudaComputeModeProhibited) { fprintf(stderr, "Error: device is running in , no threads can use ::cudaSetDevice().\n"); return -1; @@ -916,7 +919,10 @@ inline int gpuGetMaxGflopsDeviceId() cudaGetDeviceProperties(&deviceProp, current_device); // If this GPU is not running on Compute Mode prohibited, then we can add it to the list - if (deviceProp.computeMode != cudaComputeModeProhibited) + int computeMode = cudaComputeModeDefault; + cudaDeviceGetAttribute(&computeMode, cudaDevAttrComputeMode, current_device); + + if (computeMode != cudaComputeModeProhibited) { if (deviceProp.major > 0 && deviceProp.major < 9999) { @@ -935,7 +941,10 @@ inline int gpuGetMaxGflopsDeviceId() cudaGetDeviceProperties(&deviceProp, current_device); // If this GPU is not running on Compute Mode prohibited, then we can add it to the list - if (deviceProp.computeMode != cudaComputeModeProhibited) + int computeMode = cudaComputeModeDefault; + cudaDeviceGetAttribute(&computeMode, cudaDevAttrComputeMode, current_device); + + if (computeMode != cudaComputeModeProhibited) { if (deviceProp.major == 9999 && deviceProp.minor == 9999) { @@ -946,7 +955,9 @@ inline int gpuGetMaxGflopsDeviceId() sm_per_multiproc = _ConvertSMVer2Cores(deviceProp.major, deviceProp.minor); } - unsigned long long compute_perf = (unsigned long long) deviceProp.multiProcessorCount * sm_per_multiproc * deviceProp.clockRate; + int clockRate = 0; + cudaDeviceGetAttribute(&clockRate, cudaDevAttrClockRate, current_device); + unsigned long long compute_perf = (unsigned long long) deviceProp.multiProcessorCount * sm_per_multiproc * clockRate; if (compute_perf > max_compute_perf) { diff --git a/src/cuda/rodinia/3.1/cuda/hybridsort/main.cu b/src/cuda/rodinia/3.1/cuda/hybridsort/main.cu index 1c8e5cbd9..943649e52 100755 --- a/src/cuda/rodinia/3.1/cuda/hybridsort/main.cu +++ b/src/cuda/rodinia/3.1/cuda/hybridsort/main.cu @@ -212,7 +212,7 @@ void cudaSort(float *origList, float minimum, float maximum, float4 *mergeresult = runMergeSort( newlistsize, DIVISIONS, d_origList, d_resultList, sizes, nullElements, origOffsets); //d_origList; - cudaThreadSynchronize(); + cudaDeviceSynchronize(); sdkStopTimer(&mergeTimer); sdkStopTimer(&totalTimer); diff --git a/src/cuda/rodinia/3.1/cuda/hybridsort/mergesort.cu b/src/cuda/rodinia/3.1/cuda/hybridsort/mergesort.cu index be3d88bf4..dd75ca950 100755 --- a/src/cuda/rodinia/3.1/cuda/hybridsort/mergesort.cu +++ b/src/cuda/rodinia/3.1/cuda/hybridsort/mergesort.cu @@ -14,6 +14,29 @@ #define ROW_LENGTH BLOCKSIZE * 4 #define ROWS 4096 +static cudaTextureObject_t h_tex = 0; + +/* The list texture is rebound after every level swap, so the previous + object has to be destroyed before a new one replaces it. */ +static void bindListTexture(float4 *list, cudaChannelFormatDesc channelDesc, size_t bytes) +{ + if (h_tex) { + cudaDestroyTextureObject(h_tex); + h_tex = 0; + } + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeLinear; + resDesc.res.linear.devPtr = list; + resDesc.res.linear.desc = channelDesc; + resDesc.res.linear.sizeInBytes = bytes; + texDesc.readMode = cudaReadModeElementType; + cudaCreateTextureObject(&h_tex, &resDesc, &texDesc, NULL); + cudaMemcpyToSymbol(tex, &h_tex, sizeof(h_tex)); +} + //////////////////////////////////////////////////////////////////////////////// // The mergesort algorithm //////////////////////////////////////////////////////////////////////////////// @@ -34,10 +57,6 @@ float4* runMergeSort(int listsize, int divisions, // Setup texture cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32, 32, 32, 32, cudaChannelFormatKindFloat); - tex.addressMode[0] = cudaAddressModeWrap; - tex.addressMode[1] = cudaAddressModeWrap; - tex.filterMode = cudaFilterModePoint; - tex.normalized = false; //////////////////////////////////////////////////////////////////////////// // First sort all float4 elements internally @@ -50,7 +69,7 @@ float4* runMergeSort(int listsize, int divisions, dim3 threads(THREADS, 1); int blocks = ((listsize/4)%THREADS == 0) ? (listsize/4)/THREADS : (listsize/4)/THREADS + 1; dim3 grid(blocks, 1); - cudaBindTexture(0,tex, d_origList, channelDesc, listsize*sizeof(float)); + bindListTexture(d_origList, channelDesc, listsize*sizeof(float)); mergeSortFirst<<< grid, threads >>>(d_resultList, listsize); //////////////////////////////////////////////////////////////////////////// @@ -82,7 +101,7 @@ float4* runMergeSort(int listsize, int divisions, float4 *tempList = d_origList; d_origList = d_resultList; d_resultList = tempList; - cudaBindTexture(0,tex, d_origList, channelDesc, listsize*sizeof(float)); + bindListTexture(d_origList, channelDesc, listsize*sizeof(float)); mergeSortPass <<< grid, threads >>>(d_resultList, nrElems, threadsPerDiv); nrElems *= 2; floatsperthread = (nrElems*4); @@ -103,5 +122,9 @@ float4* runMergeSort(int listsize, int divisions, mergepack <<< grid, threads >>> ((float *)d_resultList, (float *)d_origList); free(startaddr); + if (h_tex) { + cudaDestroyTextureObject(h_tex); + h_tex = 0; + } return d_origList; } diff --git a/src/cuda/rodinia/3.1/cuda/hybridsort/mergesort_kernel.cu b/src/cuda/rodinia/3.1/cuda/hybridsort/mergesort_kernel.cu index 1cb2a80c2..733aad7b2 100755 --- a/src/cuda/rodinia/3.1/cuda/hybridsort/mergesort_kernel.cu +++ b/src/cuda/rodinia/3.1/cuda/hybridsort/mergesort_kernel.cu @@ -3,9 +3,9 @@ #include -// declare texture reference for 1D float texture -texture tex; -texture txt; +/* Texture references were removed in CUDA 12; the host fills this handle + via cudaMemcpyToSymbol so the fetch sites below are unchanged. */ +__constant__ cudaTextureObject_t tex; __device__ float4 sortElem(float4 r) { float4 nr; @@ -59,7 +59,7 @@ mergeSortFirst(float4 *result, int listsize) // Thread index //int tx = threadIdx.x; if(bx*blockDim.x + threadIdx.x < listsize/4){ - float4 r = tex1Dfetch(tex, (int)(bx*blockDim.x + threadIdx.x)); + float4 r = tex1Dfetch(tex, (int)(bx*blockDim.x + threadIdx.x)); result[bx * blockDim.x + threadIdx.x] = sortElem(r); } } @@ -83,7 +83,7 @@ mergeSortPass(float4 *result, int nrElems, int threadsPerDiv) if(Bstart >= constStartAddr[division + 1]){ for(int i=0; i<(constStartAddr[division + 1] - Astart); i++) { - resStart[i] = tex1Dfetch(tex, Astart + i); + resStart[i] = tex1Dfetch(tex, Astart + i); } return; } @@ -92,8 +92,8 @@ mergeSortPass(float4 *result, int nrElems, int threadsPerDiv) int bidx = 0; int outidx = 0; float4 a, b; - a = tex1Dfetch(tex, Astart + aidx); - b = tex1Dfetch(tex, Bstart + bidx); + a = tex1Dfetch(tex, Astart + aidx); + b = tex1Dfetch(tex, Bstart + bidx); while(true)//aidx < nrElems/2)// || (bidx < nrElems/2 && (Bstart + bidx < constEndAddr[division]))) { @@ -101,8 +101,8 @@ mergeSortPass(float4 *result, int nrElems, int threadsPerDiv) * For some reason, it's faster to do the texture fetches here than * after the merge */ - float4 nextA = tex1Dfetch(tex, Astart + aidx + 1); - float4 nextB = tex1Dfetch(tex, Bstart + bidx + 1); + float4 nextA = tex1Dfetch(tex, Astart + aidx + 1); + float4 nextB = tex1Dfetch(tex, Bstart + bidx + 1); float4 na = getLowest(a,b); float4 nb = getHighest(a,b); diff --git a/src/cuda/rodinia/3.1/cuda/kmeans/Makefile b/src/cuda/rodinia/3.1/cuda/kmeans/Makefile index 8b95ba045..bdd199698 100755 --- a/src/cuda/rodinia/3.1/cuda/kmeans/Makefile +++ b/src/cuda/rodinia/3.1/cuda/kmeans/Makefile @@ -22,7 +22,7 @@ endif kmeans: cluster.o getopt.o kmeans.o kmeans_clustering.o kmeans_cuda.o rmse.o - $(CC) $(CC_FLAGS) cluster.o getopt.o kmeans.o kmeans_clustering.o kmeans_cuda.o rmse.o -o kmeans -L$(CUDA_LIB_DIR) -lcudart -lm + $(CC) $(CC_FLAGS) cluster.o getopt.o kmeans.o kmeans_clustering.o kmeans_cuda.o rmse.o -o kmeans -L$(CUDA_LIB_DIR) -lcudart -lstdc++ -lm %.o: %.[c] $(CC) $(CC_FLAGS) $< -c diff --git a/src/cuda/rodinia/3.1/cuda/kmeans/Makefile_nvidia b/src/cuda/rodinia/3.1/cuda/kmeans/Makefile_nvidia index 5d612b9dc..6a45e2f35 100755 --- a/src/cuda/rodinia/3.1/cuda/kmeans/Makefile_nvidia +++ b/src/cuda/rodinia/3.1/cuda/kmeans/Makefile_nvidia @@ -34,7 +34,7 @@ ################################################################################ # Add source files here -EXECUTABLE := kmeans +EXECUTABLE := kmeans-rodinia-3.1 # CUDA source files (compiled with cudacc) CUFILES := kmeans_cuda.cu # CUDA dependency files diff --git a/src/cuda/rodinia/3.1/cuda/kmeans/kmeans_cuda.cu b/src/cuda/rodinia/3.1/cuda/kmeans/kmeans_cuda.cu index e2e1d3cb1..8eb46b616 100755 --- a/src/cuda/rodinia/3.1/cuda/kmeans/kmeans_cuda.cu +++ b/src/cuda/rodinia/3.1/cuda/kmeans/kmeans_cuda.cu @@ -148,6 +148,9 @@ kmeansCuda(float **feature, /* in: [npoints][nfeatures] */ { int delta = 0; /* if point has moved */ int i,j; /* counters */ + cudaTextureObject_t t_features = 0; + cudaTextureObject_t t_features_flipped = 0; + /* copy membership (host to device) */ cudaMemcpy(membership_d, membership_new, npoints*sizeof(int), cudaMemcpyHostToDevice); @@ -155,33 +158,31 @@ kmeansCuda(float **feature, /* in: [npoints][nfeatures] */ /* copy clusters (host to device) */ cudaMemcpy(clusters_d, clusters[0], nclusters*nfeatures*sizeof(float), cudaMemcpyHostToDevice); - /* set up texture */ - cudaChannelFormatDesc chDesc0 = cudaCreateChannelDesc(); - t_features.filterMode = cudaFilterModePoint; - t_features.normalized = false; - t_features.channelDesc = chDesc0; - - if(cudaBindTexture(NULL, &t_features, feature_d, &chDesc0, npoints*nfeatures*sizeof(float)) != CUDA_SUCCESS) + /* set up texture objects (texture references were removed in CUDA 12) */ + cudaChannelFormatDesc chDesc = cudaCreateChannelDesc(); + + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeLinear; + resDesc.res.linear.desc = chDesc; + texDesc.filterMode = cudaFilterModePoint; + texDesc.normalizedCoords = false; + texDesc.readMode = cudaReadModeElementType; + + resDesc.res.linear.devPtr = feature_d; + resDesc.res.linear.sizeInBytes = npoints*nfeatures*sizeof(float); + if(cudaCreateTextureObject(&t_features, &resDesc, &texDesc, NULL) != cudaSuccess) printf("Couldn't bind features array to texture!\n"); - cudaChannelFormatDesc chDesc1 = cudaCreateChannelDesc(); - t_features_flipped.filterMode = cudaFilterModePoint; - t_features_flipped.normalized = false; - t_features_flipped.channelDesc = chDesc1; - - if(cudaBindTexture(NULL, &t_features_flipped, feature_flipped_d, &chDesc1, npoints*nfeatures*sizeof(float)) != CUDA_SUCCESS) + resDesc.res.linear.devPtr = feature_flipped_d; + resDesc.res.linear.sizeInBytes = npoints*nfeatures*sizeof(float); + if(cudaCreateTextureObject(&t_features_flipped, &resDesc, &texDesc, NULL) != cudaSuccess) printf("Couldn't bind features_flipped array to texture!\n"); - cudaChannelFormatDesc chDesc2 = cudaCreateChannelDesc(); - t_clusters.filterMode = cudaFilterModePoint; - t_clusters.normalized = false; - t_clusters.channelDesc = chDesc2; - - if(cudaBindTexture(NULL, &t_clusters, clusters_d, &chDesc2, nclusters*nfeatures*sizeof(float)) != CUDA_SUCCESS) - printf("Couldn't bind clusters array to texture!\n"); - /* copy clusters to constant memory */ - cudaMemcpyToSymbol("c_clusters",clusters[0],nclusters*nfeatures*sizeof(float),0,cudaMemcpyHostToDevice); + cudaMemcpyToSymbol(c_clusters,clusters[0],nclusters*nfeatures*sizeof(float),0,cudaMemcpyHostToDevice); /* setup execution parameters. @@ -197,9 +198,14 @@ kmeansCuda(float **feature, /* in: [npoints][nfeatures] */ membership_d, clusters_d, block_clusters_d, - block_deltas_d); + block_deltas_d, + t_features, + t_features_flipped); + + cudaDeviceSynchronize(); - cudaThreadSynchronize(); + cudaDestroyTextureObject(t_features); + cudaDestroyTextureObject(t_features_flipped); /* copy back membership (device to host) */ cudaMemcpy(membership_new, membership_d, npoints*sizeof(int), cudaMemcpyDeviceToHost); diff --git a/src/cuda/rodinia/3.1/cuda/kmeans/kmeans_cuda_kernel.cu b/src/cuda/rodinia/3.1/cuda/kmeans/kmeans_cuda_kernel.cu index dd0dec27e..d12015e21 100755 --- a/src/cuda/rodinia/3.1/cuda/kmeans/kmeans_cuda_kernel.cu +++ b/src/cuda/rodinia/3.1/cuda/kmeans/kmeans_cuda_kernel.cu @@ -11,11 +11,6 @@ #define SDATA( index) CUT_BANK_CHECKER(sdata, index) -// t_features has the layout dim0[points 0-m-1]dim1[ points 0-m-1]... -texture t_features; -// t_features_flipped has the layout point0[dim 0-n-1]point1[dim 0-n-1] -texture t_features_flipped; -texture t_clusters; __constant__ float c_clusters[ASSUMED_NR_CLUSTERS*34]; /* constant memory for cluster centers */ @@ -62,7 +57,11 @@ kmeansPoint(float *features, /* in: [npoints*nfeatures] */ int *membership, float *clusters, float *block_clusters, - int *block_deltas) + int *block_deltas, + /* t_features has the layout dim0[points 0-m-1]dim1[ points 0-m-1]... */ + cudaTextureObject_t t_features, + /* t_features_flipped has the layout point0[dim 0-n-1]point1[dim 0-n-1] */ + cudaTextureObject_t t_features_flipped) { // block ID @@ -86,7 +85,7 @@ kmeansPoint(float *features, /* in: [npoints*nfeatures] */ for (j=0; j < nfeatures; j++) { int addr = point_id + j*npoints; /* appropriate index of data point */ - float diff = (tex1Dfetch(t_features,addr) - + float diff = (tex1Dfetch(t_features,addr) - c_clusters[cluster_base_index + j]); /* distance between a data point to cluster centers */ ans += diff*diff; /* sum of squares */ } @@ -167,7 +166,7 @@ kmeansPoint(float *features, /* in: [npoints*nfeatures] */ if(threadIdx.x < nfeatures * nclusters) { // accumulate over all the elements of this threadblock for(int i = 0; i< (THREADS_PER_BLOCK); i++) { - float val = tex1Dfetch(t_features_flipped,new_base_index+i*nfeatures); + float val = tex1Dfetch(t_features_flipped,new_base_index+i*nfeatures); if(new_center_ids[i] == center_id) accumulator += val; } diff --git a/src/cuda/rodinia/3.1/cuda/lavaMD/kernel/kernel_gpu_cuda_wrapper.cu b/src/cuda/rodinia/3.1/cuda/lavaMD/kernel/kernel_gpu_cuda_wrapper.cu index 6feab499f..5bf4cdd50 100755 --- a/src/cuda/rodinia/3.1/cuda/lavaMD/kernel/kernel_gpu_cuda_wrapper.cu +++ b/src/cuda/rodinia/3.1/cuda/lavaMD/kernel/kernel_gpu_cuda_wrapper.cu @@ -63,7 +63,7 @@ kernel_gpu_cuda_wrapper(par_str par_cpu, // INITIAL DRIVER OVERHEAD //====================================================================================================100 - cudaThreadSynchronize(); + cudaDeviceSynchronize(); //====================================================================================================100 // VARIABLES @@ -193,7 +193,7 @@ kernel_gpu_cuda_wrapper(par_str par_cpu, d_fv_gpu); checkCUDAError("Start"); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); time4 = get_time(); diff --git a/src/cuda/rodinia/3.1/cuda/lavaMD/makefile b/src/cuda/rodinia/3.1/cuda/lavaMD/makefile index a93489169..2a7536970 100755 --- a/src/cuda/rodinia/3.1/cuda/lavaMD/makefile +++ b/src/cuda/rodinia/3.1/cuda/lavaMD/makefile @@ -1,3 +1,9 @@ +# Link straight into the shared bin dir under the final benchmark name when +# setup_environment has been sourced, and build in place otherwise. This +# replaces the post-build 'mv' the top-level Makefile used to do, which +# stranded binaries in the source tree whenever a sibling app failed. +RODINIA_OUT ?= $(if $(BINDIR),$(BINDIR)/$(BINSUBDIR),.) + include ../../common/make.config # Example @@ -16,7 +22,7 @@ C_C = gcc OMP_LIB = -lgomp OMP_FLAG = -fopenmp -CUD_C = $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) +CUD_C = $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) # OMP_FLAG = -Xcompiler paste_one_here #CUDA_FLAG = -arch sm_13 @@ -36,7 +42,7 @@ a.out: main.o \ -lcudart \ $(OMP_LIB) \ -lstdc++ \ - -o lavaMD + -o $(RODINIA_OUT)/lavaMD-rodinia-3.1 # compile function files into objects (binaries) main.o: main.h \ diff --git a/src/cuda/rodinia/3.1/cuda/leukocyte/CUDA/Makefile b/src/cuda/rodinia/3.1/cuda/leukocyte/CUDA/Makefile index 24efecff1..7e302e33d 100755 --- a/src/cuda/rodinia/3.1/cuda/leukocyte/CUDA/Makefile +++ b/src/cuda/rodinia/3.1/cuda/leukocyte/CUDA/Makefile @@ -10,7 +10,7 @@ CC_FLAGS = -g -O3 -Wall -I$(MATRIX_DIR) # CUDA compiler NVCC = $(CUDA_DIR)/bin/nvcc -NVCC_FLAGS = -I$(CUDA_DIR)/include -I$(SDK_DIR)/common/inc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) +NVCC_FLAGS = -I$(CUDA_DIR)/include -I$(SDK_DIR)/common/inc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) # Matrix library path MATRIX_DIR = ../meschach_lib diff --git a/src/cuda/rodinia/3.1/cuda/leukocyte/CUDA/find_ellipse_kernel.cu b/src/cuda/rodinia/3.1/cuda/leukocyte/CUDA/find_ellipse_kernel.cu index d6906f7b4..1a52152d9 100755 --- a/src/cuda/rodinia/3.1/cuda/leukocyte/CUDA/find_ellipse_kernel.cu +++ b/src/cuda/rodinia/3.1/cuda/leukocyte/CUDA/find_ellipse_kernel.cu @@ -113,7 +113,7 @@ float *GICOV_CUDA(int grad_m, int grad_n, float *host_grad_x, float *host_grad_y GICOV_kernel <<< num_blocks, threads_per_block >>> (grad_m, device_gicov); // Check for kernel errors - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaError_t error = cudaGetLastError(); if (error != cudaSuccess) { printf("GICOV kernel error: %s\n", cudaGetErrorString(error)); @@ -204,7 +204,7 @@ float *dilate_CUDA(int max_gicov_m, int max_gicov_n, int strel_m, int strel_n) { dilate_kernel <<< num_blocks, threads_per_block >>> (max_gicov_m, max_gicov_n, strel_m, strel_n, device_img_dilated); // Check for kernel errors - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaError_t error = cudaGetLastError(); if (error != cudaSuccess) { printf("Dilation kernel error: %s\n", cudaGetErrorString(error)); diff --git a/src/cuda/rodinia/3.1/cuda/leukocyte/CUDA/track_ellipse_kernel.cu b/src/cuda/rodinia/3.1/cuda/leukocyte/CUDA/track_ellipse_kernel.cu index 9b8c208ef..92b5de531 100755 --- a/src/cuda/rodinia/3.1/cuda/leukocyte/CUDA/track_ellipse_kernel.cu +++ b/src/cuda/rodinia/3.1/cuda/leukocyte/CUDA/track_ellipse_kernel.cu @@ -237,7 +237,7 @@ void IMGVF_cuda(MAT **I, MAT **IMGVF, double vx, double vy, double e, int max_it (float) vx, (float) vy, (float) e, max_iterations, (float) cutoff ); // Check for kernel errors - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cudaError_t error = cudaGetLastError(); if (error != cudaSuccess) { printf("MGVF kernel error: %s\n", cudaGetErrorString(error)); diff --git a/src/cuda/rodinia/3.1/cuda/lud/cuda/Makefile b/src/cuda/rodinia/3.1/cuda/lud/cuda/Makefile index 7d451ce68..b8347e77f 100755 --- a/src/cuda/rodinia/3.1/cuda/lud/cuda/Makefile +++ b/src/cuda/rodinia/3.1/cuda/lud/cuda/Makefile @@ -1,3 +1,9 @@ +# Link straight into the shared bin dir under the final benchmark name when +# setup_environment has been sourced, and build in place otherwise. This +# replaces the post-build 'mv' the top-level Makefile used to do, which +# stranded binaries in the source tree whenever a sibling app failed. +RODINIA_OUT ?= $(if $(BINDIR),$(BINDIR)/$(BINSUBDIR),.) + GENCODE_SM10 ?= -gencode=arch=compute_10,code=\"sm_10,compute_10\" GENCODE_SM13 ?= -gencode=arch=compute_13,code=\"sm_13,compute_13\" GENCODE_SM20 ?= -gencode=arch=compute_20,code=\"sm_20,compute_20\" @@ -19,7 +25,7 @@ NVCCFLAGS += -I../common \ -use_fast_math \ -lm \ -lcudart \ - $(SPACE) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) + $(SPACE) $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) CFLAGS += -I../common \ -I/usr/include/cuda \ @@ -28,7 +34,7 @@ CFLAGS += -I../common \ $(SPACE) # Add source files here -EXECUTABLE := lud_cuda +EXECUTABLE := $(RODINIA_OUT)/lud-rodinia-3.1 # Cuda source files (compiled with cudacc) CUFILES := lud_kernel.cu # C/C++ source files (compiled with gcc / c++) diff --git a/src/cuda/rodinia/3.1/cuda/mummergpu/src/Makefile b/src/cuda/rodinia/3.1/cuda/mummergpu/src/Makefile index 71af380c4..e77d508c4 100755 --- a/src/cuda/rodinia/3.1/cuda/mummergpu/src/Makefile +++ b/src/cuda/rodinia/3.1/cuda/mummergpu/src/Makefile @@ -8,10 +8,12 @@ include ../experiments/test_rule.mk CUDA_INSTALL_PATH := $(CUDA_DIR) # Compilers -NVCC := $(CUDA_INSTALL_PATH)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) +NVCC := $(CUDA_INSTALL_PATH)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) CXX := g++ -fopenmp $(PROFILE) CC := gcc -LINK := g++ -fopenmp -m64 -fPIC $(PROFILE) +# -m64 is an x86-only option; aarch64/ppc64le gcc rejects it outright. +M64 := $(if $(filter x86_64,$(shell uname -m)),-m64,) +LINK := g++ -fopenmp $(M64) -fPIC $(PROFILE) # Add source files here STATIC_LIB := libmummergpu.a @@ -33,12 +35,16 @@ ROOTBINDIR ?= $(ROOTDIR)/bin BINDIR ?= $(ROOTBINDIR) ROOTOBJDIR ?= obj LIBDIR := $(ROOTDIR)/lib -BINNAME ?= mummergpu +# Land in the shared bin dir under the final benchmark name; see the sibling +# rodinia makefiles. Replaces the top-level Makefile's post-build mv. +RODINIA_OUT ?= $(if $(BINSUBDIR),$(BINDIR)/$(BINSUBDIR),$(BINDIR)) +BINNAME ?= mummergpu-rodinia-3.1 # Includes INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/include # Libs -LIB := -L$(CUDA_LIB_DIR) -L$(LIBDIR) -lcudart -lGL -lGLU ${LIB} +# mummergpu has no OpenGL code; -lGL/-lGLU were boilerplate and need dev packages. +LIB := -L$(CUDA_LIB_DIR) -L$(LIBDIR) -lcudart ${LIB} # Warning flags CXXWARN_FLAGS := \ @@ -64,9 +70,12 @@ CWARN_FLAGS := $(CXXWARN_FLAGS) \ -Wmain \ # Compiler-specific flags -NVCCFLAGS := -Xcompiler "-m64" -CXXFLAGS := -m64 $(CXXWARN_FLAGS) -CFLAGS := -m64 $(CWARN_FLAGS) +NVCCFLAGS := $(if $(M64),-Xcompiler "$(M64)",) +# SuffixNode::id() guards with "if (this)", which is undefined behaviour: +# modern GCC assumes this != NULL and deletes the check, so the legacy +# nullptr->id() calls segfault instead of returning 0. +CXXFLAGS := $(M64) $(CXXWARN_FLAGS) -fno-delete-null-pointer-checks +CFLAGS := $(M64) $(CWARN_FLAGS) # Common flags COMMONFLAGS ?= @@ -128,7 +137,7 @@ $(OBJDIR)/%.cu_o : $(SRCDIR)%.cu makedirectories: @mkdir -p $(LIBDIR) @mkdir -p $(OBJDIR) - @mkdir -p $(BINDIR) + @mkdir -p $(RODINIA_OUT) LIBOBJS= \ $(OBJDIR)/mummergpu_gold.cpp_o \ @@ -142,8 +151,8 @@ $(LIBDIR)/libmummergpu$(LIBSUFFIX).a: $(LIBOBJS) BINOBJS= \ $(OBJDIR)/mummergpu_main.cpp_o -$(BINDIR)/mummergpu: makedirectories $(LIBDIR)/libmummergpu$(LIBSUFFIX).a $(BINOBJS) - $(LINK) -o $(BINDIR)/$(BINNAME) $(BINOBJS) -lmummergpu$(LIBSUFFIX) $(LIB) +$(RODINIA_OUT)/$(BINNAME): makedirectories $(LIBDIR)/libmummergpu$(LIBSUFFIX).a $(BINOBJS) + $(LINK) -o $(RODINIA_OUT)/$(BINNAME) $(BINOBJS) -lmummergpu$(LIBSUFFIX) $(LIB) ############################################################################## @@ -167,7 +176,7 @@ clean: rm -rf $(ROOTOBJDIR) rm -rf $(LIBDIR) -mummergpu: $(BINDIR)/mummergpu +mummergpu: $(RODINIA_OUT)/$(BINNAME) cubin: mummergpu.cubin diff --git a/src/cuda/rodinia/3.1/cuda/mummergpu/src/mummergpu.cu b/src/cuda/rodinia/3.1/cuda/mummergpu/src/mummergpu.cu index 17e46589b..bb79952c7 100755 --- a/src/cuda/rodinia/3.1/cuda/mummergpu/src/mummergpu.cu +++ b/src/cuda/rodinia/3.1/cuda/mummergpu/src/mummergpu.cu @@ -77,16 +77,57 @@ void trap_dbg() } while (0) unsigned int num_bind_tex_calls = 0; + +/* Host-side handles for the __constant__ texture objects declared in + mummergpu_kernel.cu. Kept so the objects can be destroyed on unbind. */ +cudaTextureObject_t h_reftex = 0; +cudaTextureObject_t h_qrytex = 0; +cudaTextureObject_t h_nodetex = 0; +cudaTextureObject_t h_childrentex = 0; + #define BIND_TEX(offset, tex, arr, desc, len) do { \ - CUDA_SAFE_CALL(cudaBindTexture(offset, tex, arr, desc, len)); \ + cudaResourceDesc _resDesc; \ + cudaTextureDesc _texDesc; \ + memset(&_resDesc, 0, sizeof(_resDesc)); \ + memset(&_texDesc, 0, sizeof(_texDesc)); \ + _resDesc.resType = cudaResourceTypeLinear; \ + _resDesc.res.linear.devPtr = (void*)(arr); \ + _resDesc.res.linear.desc = (desc); \ + _resDesc.res.linear.sizeInBytes = (len); \ + _texDesc.readMode = cudaReadModeElementType; \ + CUDA_SAFE_CALL(cudaCreateTextureObject(&h_##tex, &_resDesc, \ + &_texDesc, NULL)); \ + CUDA_SAFE_CALL(cudaMemcpyToSymbol(tex, &h_##tex, \ + sizeof(cudaTextureObject_t))); \ ++num_bind_tex_calls; \ } while(0) #define BIND_TEX_ARRAY(tex, arr, desc) do { \ - CUDA_SAFE_CALL(cudaBindTextureToArray(tex, arr, desc)); \ + cudaResourceDesc _resDesc; \ + cudaTextureDesc _texDesc; \ + memset(&_resDesc, 0, sizeof(_resDesc)); \ + memset(&_texDesc, 0, sizeof(_texDesc)); \ + _resDesc.resType = cudaResourceTypeArray; \ + _resDesc.res.array.array = (arr); \ + _texDesc.addressMode[0] = cudaAddressModeClamp; \ + _texDesc.addressMode[1] = cudaAddressModeClamp; \ + _texDesc.filterMode = cudaFilterModePoint; \ + _texDesc.normalizedCoords = 0; \ + _texDesc.readMode = cudaReadModeElementType; \ + CUDA_SAFE_CALL(cudaCreateTextureObject(&h_##tex, &_resDesc, \ + &_texDesc, NULL)); \ + CUDA_SAFE_CALL(cudaMemcpyToSymbol(tex, &h_##tex, \ + sizeof(cudaTextureObject_t))); \ ++num_bind_tex_calls; \ } while(0) +#define UNBIND_TEX(tex) do { \ + if (h_##tex) { \ + CUDA_SAFE_CALL(cudaDestroyTextureObject(h_##tex)); \ + h_##tex = 0; \ + } \ +} while(0) + #define CUDA_MALLOC(ptr, size) do { \ cudaMalloc(ptr, size); \ ++num_bind_tex_calls; \ @@ -568,7 +609,7 @@ void loadReferenceTexture(MatchContext* ctx) void unloadReferenceString(Reference* ref) { #if REFTEX - CUDA_SAFE_CALL(cudaUnbindTexture( reftex ) ); + UNBIND_TEX( reftex ); #endif #if REORDER_REF && REFTEX @@ -587,7 +628,7 @@ void unloadReferenceTree(MatchContext* ctx) #if REORDER_TREE // Unload nodetex #if NODETEX - CUDA_SAFE_CALL(cudaUnbindTexture( nodetex ) ); + UNBIND_TEX( nodetex ); CUDA_SAFE_CALL(cudaFreeArray((cudaArray*)(ref->d_node_tex_array))); #else CUDA_SAFE_CALL(cudaFree(ref->d_node_tex_array)); @@ -598,7 +639,7 @@ void unloadReferenceTree(MatchContext* ctx) if (ref->d_children_tex_array) { #if CHILDTEX - CUDA_SAFE_CALL(cudaUnbindTexture( childrentex ) ); + UNBIND_TEX( childrentex ); CUDA_SAFE_CALL(cudaFreeArray((cudaArray*)(ref->d_children_tex_array))); #else CUDA_SAFE_CALL(cudaFree(ref->d_children_tex_array)); @@ -609,7 +650,7 @@ void unloadReferenceTree(MatchContext* ctx) #else #if NODETEX - CUDA_SAFE_CALL(cudaUnbindTexture( nodetex ) ); + UNBIND_TEX( nodetex ); #endif CUDA_SAFE_CALL(cudaFree(ref->d_node_tex_array)); @@ -619,7 +660,7 @@ void unloadReferenceTree(MatchContext* ctx) if (ref->d_children_tex_array) { #if CHILDTEX - CUDA_SAFE_CALL(cudaUnbindTexture( childrentex ) ); + UNBIND_TEX( childrentex ); #endif CUDA_SAFE_CALL(cudaFree(ref->d_children_tex_array)); @@ -677,10 +718,6 @@ void loadReference(MatchContext* ctx) { ref->tex_width * ref->tex_node_height * sizeof(PixelOfNode), cudaMemcpyHostToDevice)); - nodetex.addressMode[0] = cudaAddressModeClamp; - nodetex.addressMode[1] = cudaAddressModeClamp; - nodetex.filterMode = cudaFilterModePoint; - nodetex.normalized = false; // access with normalized texture coordinates BIND_TEX_ARRAY(nodetex, (cudaArray*)ref->d_node_tex_array, nodeTextureDesc); @@ -718,10 +755,6 @@ void loadReference(MatchContext* ctx) { ref->tex_width * ref->tex_children_height * sizeof(PixelOfChildren), cudaMemcpyHostToDevice)); - childrentex.addressMode[0] = cudaAddressModeClamp; - childrentex.addressMode[1] = cudaAddressModeClamp; - childrentex.filterMode = cudaFilterModePoint; - childrentex.normalized = false; // access with normalized texture coordinates BIND_TEX_ARRAY(childrentex, (cudaArray*)(ref->d_children_tex_array), childrenTextureDesc); @@ -1427,7 +1460,7 @@ void runPrintKernel(MatchContext* ctx, #endif ); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); @@ -1445,7 +1478,7 @@ void runPrintKernel(MatchContext* ctx, (void*)d_alignments, alignmentSize, cudaMemcpyDeviceToHost)); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); stopTimer(atimer); float atime = getTimerValue(atimer); @@ -1574,7 +1607,7 @@ void getExactAlignments(MatchContext * ctx, ReferencePage * page, bool on_cpu) if (num_bind_tex_calls > 100) { - cudaThreadExit(); + cudaDeviceReset(); num_bind_tex_calls = 0; loadReference(ctx); loadQueries(ctx); @@ -2022,7 +2055,7 @@ void matchQueryBlockToReferencePage(MatchContext* ctx, { matchOnGPU(ctx, reverse_complement); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); } stopTimer(ktimer); @@ -2111,7 +2144,7 @@ int matchQueriesToReferencePage(MatchContext* ctx, ReferencePage* page) destroyQueryBlock(ctx->queries); if (num_bind_tex_calls > 100) { - cudaThreadExit(); + cudaDeviceReset(); num_bind_tex_calls = 0; loadReference(ctx); } diff --git a/src/cuda/rodinia/3.1/cuda/mummergpu/src/mummergpu_kernel.cu b/src/cuda/rodinia/3.1/cuda/mummergpu/src/mummergpu_kernel.cu index 13bfcb72b..4e55bc38a 100755 --- a/src/cuda/rodinia/3.1/cuda/mummergpu/src/mummergpu_kernel.cu +++ b/src/cuda/rodinia/3.1/cuda/mummergpu/src/mummergpu_kernel.cu @@ -29,7 +29,7 @@ #if COALESCED_QUERIES #define GETQCHAR(qrypos) ((queries[((qrypos) >> 2) << 4]) & ((0xFF) << (((qrypos) & 0x00000003)) << 3)) >> ((((qrypos) & 0x00000003 )) << 3) #elif QRYTEX -#define GETQCHAR(qrypos) tex1Dfetch(qrytex, qryAddr + qrypos) +#define GETQCHAR(qrypos) tex1Dfetch(qrytex, qryAddr + qrypos) #else #define GETQCHAR(qrypos) queries[qrypos] #endif @@ -127,22 +127,13 @@ #define SHIFT_QUERIES(queries, qryAddr) queries += qryAddr #endif -#if REORDER_TREE -texture nodetex; -texture childrentex; -#else -texture nodetex; -texture childrentex; -#endif - - -#if REORDER_REF -texture reftex; -#else -texture reftex; -#endif - -texture qrytex; +/* Texture references were removed in CUDA 12. These hold texture object + handles instead; the host fills them via cudaMemcpyToSymbol so that every + fetch site below keeps referring to them by the same names. */ +__constant__ cudaTextureObject_t nodetex; +__constant__ cudaTextureObject_t childrentex; +__constant__ cudaTextureObject_t reftex; +__constant__ cudaTextureObject_t qrytex; struct __align__(8) _MatchCoord { @@ -316,13 +307,13 @@ __device__ char getRef(int refpos int x = bigx >> 2; #if REFTEX - return tex2D(reftex, x, y); + return tex2D(reftex, x, y); #else return *(ref + 65536 * y + x); #endif #else #if REFTEX - return tex1Dfetch(reftex, refpos); + return tex1Dfetch(reftex, refpos); #else return ref[refpos]; #endif @@ -372,9 +363,9 @@ __device__ uint4 getNode(unsigned int cur, #if NODETEX #if REORDER_TREE - return tex2D(nodetex, cur & 0x0000FFFF, (cur & 0xFFFF0000) >> 16); + return tex2D(nodetex, cur & 0x0000FFFF, (cur & 0xFFFF0000) >> 16); #else - return tex1Dfetch(nodetex, cur); + return tex1Dfetch(nodetex, cur); #endif #else @@ -415,9 +406,9 @@ __device__ uint4 getChildren(unsigned int cur, #if CHILDTEX #if REORDER_TREE - return tex2D(childrentex, cur & 0x0000FFFF, (cur & 0xFFFF0000) >> 16); + return tex2D(childrentex, cur & 0x0000FFFF, (cur & 0xFFFF0000) >> 16); #else - return tex1Dfetch(childrentex, cur); + return tex1Dfetch(childrentex, cur); #endif #else #if REORDER_TREE @@ -925,7 +916,7 @@ mummergpuRCKernel(MatchCoord* match_coords, XPRINTF("Next edge to follow: %c (%d)\n", c, qry_match_len); _PixelOfChildren children; - children.data = tex2D(childrentex,cur.x, cur.y); + children.data = tex2D(childrentex,cur.x, cur.y); prev = cur; switch(c) @@ -955,7 +946,7 @@ mummergpuRCKernel(MatchCoord* match_coords, } { - node.data = tex2D(nodetex, cur.data & 0xFFFF, cur.data >> 16); + node.data = tex2D(nodetex, cur.data & 0xFFFF, cur.data >> 16); } XPRINTF(" Edge coordinates: %d - %d\n", MKI(node.start), MKI(node.end)); @@ -1027,7 +1018,7 @@ mummergpuRCKernel(MatchCoord* match_coords, NEXT_SUBSTRING: - node.data = tex2D(nodetex, prev.x, prev.y); + node.data = tex2D(nodetex, prev.x, prev.y); cur = node.suffix; XPRINTF(" following suffix link. mustmatch:%d qry_match_len:%d sl:(%d,%d)\n", diff --git a/src/cuda/rodinia/3.1/cuda/myocyte/Makefile b/src/cuda/rodinia/3.1/cuda/myocyte/Makefile index f26e958eb..9cf59a827 100755 --- a/src/cuda/rodinia/3.1/cuda/myocyte/Makefile +++ b/src/cuda/rodinia/3.1/cuda/myocyte/Makefile @@ -1,3 +1,9 @@ +# Link straight into the shared bin dir under the final benchmark name when +# setup_environment has been sourced, and build in place otherwise. This +# replaces the post-build 'mv' the top-level Makefile used to do, which +# stranded binaries in the source tree whenever a sibling app failed. +RODINIA_OUT ?= $(if $(BINDIR),$(BINDIR)/$(BINSUBDIR),.) + GENCODE_SM10 ?= -gencode=arch=compute_10,code=\"sm_10,compute_10\" GENCODE_SM13 ?= -gencode=arch=compute_13,code=\"sm_13,compute_13\" GENCODE_SM20 ?= -gencode=arch=compute_20,code=\"sm_20,compute_20\" @@ -17,12 +23,12 @@ GENCODE_SM62 ?= -gencode=arch=compute_62,code=\"sm_62,compute_62\" # command n # link objects(binaries) together -myocyte.out: main.o - nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) main.o \ +$(RODINIA_OUT)/myocyte-rodinia-3.1: main.o + nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) main.o \ -I/usr/local/cuda/include \ -L/usr/local/cuda/lib \ -lm -lcudart \ - -o myocyte.out + -o $(RODINIA_OUT)/myocyte-rodinia-3.1 # compile main function file into object (binary) main.o: define.c \ @@ -44,7 +50,7 @@ main.o: define.c \ kernel_fin_2.cu \ file.c \ timer.c - nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) main.cu \ + nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) main.cu \ -c -O3 -g # delete all object files diff --git a/src/cuda/rodinia/3.1/cuda/myocyte/work_2.cu b/src/cuda/rodinia/3.1/cuda/myocyte/work_2.cu index 99652db8d..140b11392 100644 --- a/src/cuda/rodinia/3.1/cuda/myocyte/work_2.cu +++ b/src/cuda/rodinia/3.1/cuda/myocyte/work_2.cu @@ -227,7 +227,7 @@ int work_2( int xmax, d_initvalu_temp, d_finavalu_temp); - // cudaThreadSynchronize(); + // cudaDeviceSynchronize(); // printf("CUDA error: %s\n", cudaGetErrorString(cudaGetLastError())); time4 = get_time(); diff --git a/src/cuda/rodinia/3.1/cuda/nn/Makefile b/src/cuda/rodinia/3.1/cuda/nn/Makefile index 7bf30cb55..a8cb02d53 100755 --- a/src/cuda/rodinia/3.1/cuda/nn/Makefile +++ b/src/cuda/rodinia/3.1/cuda/nn/Makefile @@ -1,16 +1,22 @@ +# Link straight into the shared bin dir under the final benchmark name when +# setup_environment has been sourced, and build in place otherwise. This +# replaces the post-build 'mv' the top-level Makefile used to do, which +# stranded binaries in the source tree whenever a sibling app failed. +RODINIA_OUT ?= $(if $(BINDIR),$(BINDIR)/$(BINSUBDIR),.) + include ../../common/make.config LOCAL_CC = gcc -g -O3 -Wall -CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) +CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) -all : nn hurricane_gen +all : $(RODINIA_OUT)/nn-rodinia-3.1 hurricane_gen clean : rm -rf *.o nn hurricane_gen -nn : nn_cuda.cu +$(RODINIA_OUT)/nn-rodinia-3.1 : nn_cuda.cu $(CC) -cuda nn_cuda.cu -lcudart -D__DEVICE_EMULATION__ - $(CC) -o nn nn_cuda.cu -lcudart -D__DEVICE_EMULATION__ + $(CC) -o $(RODINIA_OUT)/nn-rodinia-3.1 nn_cuda.cu -lcudart -D__DEVICE_EMULATION__ hurricane_gen : hurricane_gen.c $(LOCAL_CC) -o $@ $< -lm diff --git a/src/cuda/rodinia/3.1/cuda/nn/nn_cuda.cu b/src/cuda/rodinia/3.1/cuda/nn/nn_cuda.cu index a0531a463..65158db7d 100644 --- a/src/cuda/rodinia/3.1/cuda/nn/nn_cuda.cu +++ b/src/cuda/rodinia/3.1/cuda/nn/nn_cuda.cu @@ -96,7 +96,7 @@ int main(int argc, char* argv[]) // Scaling calculations - added by Sam Kauffman cudaDeviceProp deviceProp; cudaGetDeviceProperties( &deviceProp, 0 ); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); unsigned long maxGridX = deviceProp.maxGridSize[0]; unsigned long threadsPerBlock = min( deviceProp.maxThreadsPerBlock, DEFAULT_THREADS_PER_BLOCK ); size_t totalDeviceMemory; @@ -109,7 +109,7 @@ int main(int argc, char* argv[]) cudaMemGetInfo( &freeDeviceMemory, &totalDeviceMemory ); #endif - cudaThreadSynchronize(); + cudaDeviceSynchronize(); unsigned long usableDeviceMemory = freeDeviceMemory * 85 / 100; // 85% arbitrary throttle to compensate for known CUDA bug unsigned long maxThreads = usableDeviceMemory / 12; // 4 bytes in 3 vectors per thread if ( numRecords > maxThreads ) @@ -153,7 +153,7 @@ int main(int argc, char* argv[]) * Execute kernel */ euclid<<< gridDim, threadsPerBlock >>>(d_locations,d_distances,numRecords,lat,lng); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); //Copy data from device memory to host memory cudaMemcpy( distances, d_distances, sizeof(float)*numRecords, cudaMemcpyDeviceToHost ); diff --git a/src/cuda/rodinia/3.1/cuda/nw/Makefile b/src/cuda/rodinia/3.1/cuda/nw/Makefile index 6d9aa8ee5..369b805dd 100755 --- a/src/cuda/rodinia/3.1/cuda/nw/Makefile +++ b/src/cuda/rodinia/3.1/cuda/nw/Makefile @@ -1,6 +1,6 @@ include ../../common/make.config -CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) +CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) INCLUDE := $(CUDA_DIR)/include diff --git a/src/cuda/rodinia/3.1/cuda/nw/Makefile_nvidia b/src/cuda/rodinia/3.1/cuda/nw/Makefile_nvidia index 2fd0b98d0..9fadd9581 100755 --- a/src/cuda/rodinia/3.1/cuda/nw/Makefile_nvidia +++ b/src/cuda/rodinia/3.1/cuda/nw/Makefile_nvidia @@ -34,7 +34,7 @@ ################################################################################ # Add source files here -EXECUTABLE := needle +EXECUTABLE := nw-rodinia-3.1 # CUDA source files (compiled with cudacc) CUFILES := needle.cu # CUDA dependency files diff --git a/src/cuda/rodinia/3.1/cuda/particlefilter/Makefile b/src/cuda/rodinia/3.1/cuda/particlefilter/Makefile index c7cccf04b..82596b280 100755 --- a/src/cuda/rodinia/3.1/cuda/particlefilter/Makefile +++ b/src/cuda/rodinia/3.1/cuda/particlefilter/Makefile @@ -1,18 +1,24 @@ -#makefile - -include ../../common/make.config - -CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) - -INCLUDE := $(CUDA_DIR)/include - -all: naive float - -naive: ex_particle_CUDA_naive_seq.cu - $(CC) -I$(INCLUDE) -L$(CUDA_LIB_DIR) -g -lm -O3 -use_fast_math ex_particle_CUDA_naive_seq.cu -o particlefilter_naive - -float: ex_particle_CUDA_float_seq.cu - $(CC) -I$(INCLUDE) -L$(CUDA_LIB_DIR) -g -lm -O3 -use_fast_math ex_particle_CUDA_float_seq.cu -o particlefilter_float - -clean: - rm -f particlefilter_naive particlefilter_float +# Link straight into the shared bin dir under the final benchmark name when +# setup_environment has been sourced, and build in place otherwise. This +# replaces the post-build 'mv' the top-level Makefile used to do, which +# stranded binaries in the source tree whenever a sibling app failed. +RODINIA_OUT ?= $(if $(BINDIR),$(BINDIR)/$(BINSUBDIR),.) + +#makefile + +include ../../common/make.config + +CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) + +INCLUDE := $(CUDA_DIR)/include + +all: naive float + +naive: ex_particle_CUDA_naive_seq.cu + $(CC) -I$(INCLUDE) -L$(CUDA_LIB_DIR) -g -lm -O3 -use_fast_math ex_particle_CUDA_naive_seq.cu -o $(RODINIA_OUT)/particlefilter_naive-rodinia-3.1 + +float: ex_particle_CUDA_float_seq.cu + $(CC) -I$(INCLUDE) -L$(CUDA_LIB_DIR) -g -lm -O3 -use_fast_math ex_particle_CUDA_float_seq.cu -o $(RODINIA_OUT)/particlefilter_float-rodinia-3.1 + +clean: + rm -f particlefilter_naive particlefilter_float diff --git a/src/cuda/rodinia/3.1/cuda/pathfinder/Makefile b/src/cuda/rodinia/3.1/cuda/pathfinder/Makefile index 204da03a6..c8d0df365 100755 --- a/src/cuda/rodinia/3.1/cuda/pathfinder/Makefile +++ b/src/cuda/rodinia/3.1/cuda/pathfinder/Makefile @@ -1,15 +1,23 @@ include ../../common/make.config +# -m64 is an x86-only option; aarch64/ppc64le gcc rejects it outright. +M64 := $(if $(filter x86_64,$(shell uname -m)),-m64,) +# Link straight into the shared bin dir under the final benchmark name when +# setup_environment has been sourced, and build in place otherwise. This +# replaces the post-build 'mv' the top-level Makefile used to do, which +# stranded binaries in the source tree whenever a sibling app failed. +RODINIA_OUT ?= $(if $(BINDIR),$(BINDIR)/$(BINSUBDIR),.) -CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) + +CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) INCLUDE := $(CUDA_DIR)/include SRC = pathfinder.cu -EXE = pathfinder +EXE = $(RODINIA_OUT)/pathfinder-rodinia-3.1 release: $(CC) -c pathfinder.cu -I$(INCLUDE) - g++ -fPIC -m64 -o pathfinder pathfinder.o -L$(CUDA_INSTALL_PATH)/lib64 -lcudart + g++ -fPIC $(M64) -o pathfinder pathfinder.o -L$(CUDA_INSTALL_PATH)/lib64 -lcudart enum: $(CC) -deviceemu $(SRC) -o $(EXE) -I$(INCLUDE) -L$$(CUDA_LIB_DIR) diff --git a/src/cuda/rodinia/3.1/cuda/pathfinder_k1/Makefile b/src/cuda/rodinia/3.1/cuda/pathfinder_k1/Makefile index 204da03a6..e1ee6d7cb 100755 --- a/src/cuda/rodinia/3.1/cuda/pathfinder_k1/Makefile +++ b/src/cuda/rodinia/3.1/cuda/pathfinder_k1/Makefile @@ -1,4 +1,6 @@ include ../../common/make.config +# -m64 is an x86-only option; aarch64/ppc64le gcc rejects it outright. +M64 := $(if $(filter x86_64,$(shell uname -m)),-m64,) CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) INCLUDE := $(CUDA_DIR)/include @@ -9,7 +11,7 @@ EXE = pathfinder release: $(CC) -c pathfinder.cu -I$(INCLUDE) - g++ -fPIC -m64 -o pathfinder pathfinder.o -L$(CUDA_INSTALL_PATH)/lib64 -lcudart + g++ -fPIC $(M64) -o pathfinder pathfinder.o -L$(CUDA_INSTALL_PATH)/lib64 -lcudart enum: $(CC) -deviceemu $(SRC) -o $(EXE) -I$(INCLUDE) -L$$(CUDA_LIB_DIR) diff --git a/src/cuda/rodinia/3.1/cuda/srad/srad_v1/makefile b/src/cuda/rodinia/3.1/cuda/srad/srad_v1/makefile index 6899f1f7a..a5f8f7f1f 100755 --- a/src/cuda/rodinia/3.1/cuda/srad/srad_v1/makefile +++ b/src/cuda/rodinia/3.1/cuda/srad/srad_v1/makefile @@ -1,6 +1,12 @@ +# Link straight into the shared bin dir under the final benchmark name when +# setup_environment has been sourced, and build in place otherwise. This +# replaces the post-build 'mv' the top-level Makefile used to do, which +# stranded binaries in the source tree whenever a sibling app failed. +RODINIA_OUT ?= $(if $(BINDIR),$(BINDIR)/$(BINSUBDIR),.) + include ../../../common/make.config -CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) +CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) INCLUDE := $(CUDA_DIR)/include @@ -18,7 +24,7 @@ a.out: main.o $(CC) main.o \ -I$(INCLUDE) \ -L$(CUDA_LIB_DIR) \ - -lm -lcudart -o srad + -lm -lcudart -o $(RODINIA_OUT)/srad_v1-rodinia-3.1 # compile main function file into object (binary) main.o: main.cu \ diff --git a/src/cuda/rodinia/3.1/cuda/srad/srad_v2/Makefile b/src/cuda/rodinia/3.1/cuda/srad/srad_v2/Makefile index 7ee175d53..43a1a18af 100755 --- a/src/cuda/rodinia/3.1/cuda/srad/srad_v2/Makefile +++ b/src/cuda/rodinia/3.1/cuda/srad/srad_v2/Makefile @@ -1,6 +1,6 @@ include ../../../common/make.config -CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) +CC := $(CUDA_DIR)/bin/nvcc $(GENCODE_SM10) $(GENCODE_SM13) $(GENCODE_SM80) $(GENCODE_SM86) $(GENCODE_SM90) $(GENCODE_SM100) $(GENCODE_SM103) $(GENCODE_ARCH) $(GENCODE_SM20) $(GENCODE_SM30) $(GENCODE_SM35) $(GENCODE_SM50) $(GENCODE_SM60) $(GENCODE_SM62) $(GENCODE_SM70) $(GENCODE_SM75) INCLUDE := $(CUDA_DIR)/include diff --git a/src/cuda/rodinia/3.1/cuda/srad/srad_v2/Makefile_nvidia b/src/cuda/rodinia/3.1/cuda/srad/srad_v2/Makefile_nvidia index 305c08e3e..c53439cd1 100755 --- a/src/cuda/rodinia/3.1/cuda/srad/srad_v2/Makefile_nvidia +++ b/src/cuda/rodinia/3.1/cuda/srad/srad_v2/Makefile_nvidia @@ -5,7 +5,7 @@ ################################################################################ # Add source files here -EXECUTABLE := srad_v2 +EXECUTABLE := srad_v2-rodinia-3.1 # CUDA source files (compiled with cudacc) CUFILES := srad.cu # CUDA dependency files diff --git a/src/cuda/rodinia/3.1/cuda/srad/srad_v2/srad.cu b/src/cuda/rodinia/3.1/cuda/srad/srad_v2/srad.cu index 7a2a69eeb..fdc849763 100755 --- a/src/cuda/rodinia/3.1/cuda/srad/srad_v2/srad.cu +++ b/src/cuda/rodinia/3.1/cuda/srad/srad_v2/srad.cu @@ -237,7 +237,7 @@ runTest( int argc, char** argv) #endif } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); #ifdef OUTPUT //Printing output diff --git a/src/cuda/rodinia/3.1/cuda/streamcluster/Makefile_nvidia b/src/cuda/rodinia/3.1/cuda/streamcluster/Makefile_nvidia index 7e367a55d..f95ec8a33 100755 --- a/src/cuda/rodinia/3.1/cuda/streamcluster/Makefile_nvidia +++ b/src/cuda/rodinia/3.1/cuda/streamcluster/Makefile_nvidia @@ -34,7 +34,7 @@ ################################################################################ # Add source files here -EXECUTABLE := streamcluster +EXECUTABLE := streamcluster-rodinia-3.1 # CUDA source files (compiled with cudacc) CUFILES := streamcluster_cuda.cu # CUDA dependency files diff --git a/src/cuda/rodinia/3.1/cuda/streamcluster/streamcluster_cuda.cu b/src/cuda/rodinia/3.1/cuda/streamcluster/streamcluster_cuda.cu index 0a5379d48..b8f328c6c 100755 --- a/src/cuda/rodinia/3.1/cuda/streamcluster/streamcluster_cuda.cu +++ b/src/cuda/rodinia/3.1/cuda/streamcluster/streamcluster_cuda.cu @@ -254,7 +254,7 @@ float pgain( long x, Points *points, float z, long int *numcenters, int kmax, bo center_table_d, // in: center index table switch_membership_d // out: changes in membership ); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); // error check error = cudaGetLastError(); diff --git a/src/cuda/shoc-master/src/cuda/common/main.cpp b/src/cuda/shoc-master/src/cuda/common/main.cpp index 232afa1a4..8459a12f0 100644 --- a/src/cuda/shoc-master/src/cuda/common/main.cpp +++ b/src/cuda/shoc-master/src/cuda/common/main.cpp @@ -100,7 +100,9 @@ void EnumerateDevicesAndChoose(int chooseDevice, bool verbose) deviceProp.totalConstMem) << endl; cout << " major (hw version) = " << deviceProp.major << endl; cout << " minor (hw version) = " << deviceProp.minor << endl; - cout << " clockRate = " << deviceProp.clockRate << endl; + int clockRate = 0; // cudaDeviceProp::clockRate was removed in CUDA 13 + cudaDeviceGetAttribute(&clockRate, cudaDevAttrClockRate, device); + cout << " clockRate = " << clockRate << endl; cout << " textureAlignment = " << deviceProp.textureAlignment << endl; } diff --git a/src/cuda/shoc-master/src/cuda/level0/BusSpeedReadback.cu b/src/cuda/shoc-master/src/cuda/level0/BusSpeedReadback.cu index 7b5a3bedc..9380f8c31 100644 --- a/src/cuda/shoc-master/src/cuda/level0/BusSpeedReadback.cu +++ b/src/cuda/shoc-master/src/cuda/level0/BusSpeedReadback.cu @@ -122,7 +122,7 @@ void RunBenchmark(ResultDatabase &resultDB, cudaMemcpy(device, hostMem1, numMaxFloats*sizeof(float), cudaMemcpyHostToDevice); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); const unsigned int passes = op.getOptionInt("passes"); cudaEvent_t start, stop; diff --git a/src/cuda/shoc-master/src/cuda/level0/DeviceMemory.cu b/src/cuda/shoc-master/src/cuda/level0/DeviceMemory.cu index b637661df..320de12ad 100644 --- a/src/cuda/shoc-master/src/cuda/level0/DeviceMemory.cu +++ b/src/cuda/shoc-master/src/cuda/level0/DeviceMemory.cu @@ -25,7 +25,10 @@ __global__ void readTexels(int n, float *d_out, int width); __global__ void readTexelsInCache(int n, float *d_out); __global__ void readTexelsRandom(int n, float *d_out, int width, int height); // Texture to use for the benchmarks -texture texA; +/* Texture references were removed in CUDA 12; the host fills this handle + via cudaMemcpyToSymbol so the fetch sites below are unchanged. */ +__constant__ cudaTextureObject_t texA; +static cudaTextureObject_t h_texA = 0; // **************************************************************************** // Function: addBenchmarkSpecOptions @@ -309,10 +312,6 @@ void TestTextureMem(ResultDatabase &resultDB, OptionParser &op, double scalet) CHECK_CUDA_ERROR(); // make sure our texture behaves like we want.... - texA.normalized = false; - texA.addressMode[0] = cudaAddressModeClamp; - texA.addressMode[1] = cudaAddressModeClamp; - texA.filterMode = cudaFilterModePoint; for (int j = 0; j < nsizes; j++) { @@ -350,7 +349,8 @@ void TestTextureMem(ResultDatabase &resultDB, OptionParser &op, double scalet) // Allocate a cuda array cudaArray* cuArray; - cudaMallocArray(&cuArray, &texA.channelDesc, width, height); + cudaChannelFormatDesc texAChannelDesc = cudaCreateChannelDesc(); + cudaMallocArray(&cuArray, &texAChannelDesc, width, height); CHECK_CUDA_ERROR(); // Copy in source data @@ -358,7 +358,21 @@ void TestTextureMem(ResultDatabase &resultDB, OptionParser &op, double scalet) CHECK_CUDA_ERROR(); // Bind texture to the array - cudaBindTextureToArray(texA, cuArray); + { + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeArray; + resDesc.res.array.array = cuArray; + texDesc.addressMode[0] = cudaAddressModeClamp; + texDesc.addressMode[1] = cudaAddressModeClamp; + texDesc.filterMode = cudaFilterModePoint; + texDesc.normalizedCoords = 0; + texDesc.readMode = cudaReadModeElementType; + cudaCreateTextureObject(&h_texA, &resDesc, &texDesc, NULL); + cudaMemcpyToSymbol(texA, &h_texA, sizeof(h_texA)); + } CHECK_CUDA_ERROR(); for (int p = 0; p < passes; p++) @@ -446,7 +460,7 @@ void TestTextureMem(ResultDatabase &resultDB, OptionParser &op, double scalet) delete[] h_out; cudaFree(d_out); cudaFreeArray(cuArray); - cudaUnbindTexture(texA); + cudaDestroyTextureObject(h_texA); } cudaEventDestroy(start); cudaEventDestroy(stop); @@ -647,7 +661,7 @@ __global__ void readTexels(int n, float *d_out, int width) int width_bits = width-1; for (int i = 0; i < n; i++) { - float4 v = tex2D(texA, float(idx_x), float(idx_y)); + float4 v = tex2D(texA, float(idx_x), float(idx_y)); idx_x = (idx_x+1) & width_bits; sum += v.x; } @@ -663,7 +677,7 @@ __global__ void readTexelsInCache(int n, float *d_out) float sum = 0.0f; for (int i = 0; i < n; i++) { - float4 v = tex2D(texA, float(idx_x), float(idx_y)); + float4 v = tex2D(texA, float(idx_x), float(idx_y)); sum += v.x; } d_out[out_idx] = sum; @@ -680,7 +694,7 @@ __global__ void readTexelsRandom(int n, float *d_out, int width, int height) int height_bits = height-1; for (int i = 0; i < n; i++) { - float4 v = tex2D(texA, float(idx_x), float(idx_y)); + float4 v = tex2D(texA, float(idx_x), float(idx_y)); idx_x = (idx_x*3+29)&(width_bits); idx_y = (idx_y*5+11)&(height_bits); sum += v.x; diff --git a/src/cuda/shoc-master/src/cuda/level1/fft/fftlib.cu b/src/cuda/shoc-master/src/cuda/level1/fft/fftlib.cu index a7dc41e14..2d0072948 100644 --- a/src/cuda/shoc-master/src/cuda/level1/fft/fftlib.cu +++ b/src/cuda/shoc-master/src/cuda/level1/fft/fftlib.cu @@ -163,7 +163,7 @@ forward(void* work, const int n_ffts) (cufftComplex*)work, CUFFT_FORWARD); } printCUFFTError(res); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CHECK_CUDA_ERROR(); #else if (do_dp) @@ -174,7 +174,7 @@ forward(void* work, const int n_ffts) { FFT512_device<<>>((float2*)work); } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CHECK_CUDA_ERROR(); #endif } @@ -206,7 +206,7 @@ inverse(void* work, const int n_ffts) { norm512_device<<>>((float2*)work); } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CHECK_CUDA_ERROR(); #else if (do_dp) @@ -217,7 +217,7 @@ inverse(void* work, const int n_ffts) { IFFT512_device<<>>((float2*)work); } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CHECK_CUDA_ERROR(); // normalization built in to inverse... #endif diff --git a/src/cuda/shoc-master/src/cuda/level1/gemm/GEMM.cpp b/src/cuda/shoc-master/src/cuda/level1/gemm/GEMM.cpp index 00068e032..f2700ae15 100644 --- a/src/cuda/shoc-master/src/cuda/level1/gemm/GEMM.cpp +++ b/src/cuda/shoc-master/src/cuda/level1/gemm/GEMM.cpp @@ -228,7 +228,7 @@ void RunTest(string testName, ResultDatabase &resultDB, OptionParser &op) // Warm Up devGEMM(transa, transb, m, n, k, alpha, dA, lda, dB, ldb, beta, dC, ldc); - CUDA_SAFE_CALL(cudaThreadSynchronize()); + CUDA_SAFE_CALL(cudaDeviceSynchronize()); double cublas_time; float kernel_time = 0.0f; diff --git a/src/cuda/shoc-master/src/cuda/level1/md/MD.cu b/src/cuda/shoc-master/src/cuda/level1/md/MD.cu index e23e4b7a8..0acd3b3a3 100644 --- a/src/cuda/shoc-master/src/cuda/level1/md/MD.cu +++ b/src/cuda/shoc-master/src/cuda/level1/md/MD.cu @@ -37,13 +37,17 @@ inline int populateNeighborList(std::list& currDist, int* neighborList); // Texture caches for position info -texture posTexture; -texture posTexture_dp; +/* Texture references were removed in CUDA 12; the host fills these handles + via cudaMemcpyToSymbol so the reader structs below are unchanged. */ +__constant__ cudaTextureObject_t posTexture; +__constant__ cudaTextureObject_t posTexture_dp; +static cudaTextureObject_t h_posTexture = 0; +static cudaTextureObject_t h_posTexture_dp = 0; struct texReader_sp { __device__ __forceinline__ float4 operator()(int idx) const { - return tex1Dfetch(posTexture, idx); + return tex1Dfetch(posTexture, idx); } }; @@ -60,11 +64,11 @@ struct texReader_dp { // but since the arch doesn't support DP, it will never be called return make_double4(0., 0., 0., 0.); #else - int4 v = tex1Dfetch(posTexture_dp, idx*2); + int4 v = tex1Dfetch(posTexture_dp, idx*2); double2 a = make_double2(__hiloint2double(v.y, v.x), __hiloint2double(v.w, v.z)); - v = tex1Dfetch(posTexture_dp, idx*2 + 1); + v = tex1Dfetch(posTexture_dp, idx*2 + 1); double2 b = make_double2(__hiloint2double(v.y, v.x), __hiloint2double(v.w, v.z)); @@ -355,14 +359,36 @@ void runTest(const string& testName, ResultDatabase& resultDB, OptionParser& op) cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(); // Bind a 1D texture to the position array - CUDA_SAFE_CALL(cudaBindTexture(0, posTexture, d_position, channelDesc, - nAtom*sizeof(float4))); + { + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeLinear; + resDesc.res.linear.devPtr = d_position; + resDesc.res.linear.desc = channelDesc; + resDesc.res.linear.sizeInBytes = nAtom*sizeof(float4); + texDesc.readMode = cudaReadModeElementType; + CUDA_SAFE_CALL(cudaCreateTextureObject(&h_posTexture, &resDesc, &texDesc, NULL)); + CUDA_SAFE_CALL(cudaMemcpyToSymbol(posTexture, &h_posTexture, sizeof(h_posTexture))); + } cudaChannelFormatDesc channelDesc2 = cudaCreateChannelDesc(); // Bind a 1D texture to the position array - CUDA_SAFE_CALL(cudaBindTexture(0, posTexture_dp, d_position, - channelDesc2, nAtom*sizeof(double4))); + { + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeLinear; + resDesc.res.linear.devPtr = d_position; + resDesc.res.linear.desc = channelDesc2; + resDesc.res.linear.sizeInBytes = nAtom*sizeof(double4); + texDesc.readMode = cudaReadModeElementType; + CUDA_SAFE_CALL(cudaCreateTextureObject(&h_posTexture_dp, &resDesc, &texDesc, NULL)); + CUDA_SAFE_CALL(cudaMemcpyToSymbol(posTexture_dp, &h_posTexture_dp, sizeof(h_posTexture_dp))); + } } // Keep track of how many atoms are within the cutoff distance to @@ -404,7 +430,7 @@ void runTest(const string& testName, ResultDatabase& resultDB, OptionParser& op) <<>> (d_force, d_position, maxNeighbors, d_neighborList, cutsq, lj1, lj2, nAtom); - CUDA_SAFE_CALL(cudaThreadSynchronize()); + CUDA_SAFE_CALL(cudaDeviceSynchronize()); // Copy back forces cudaEvent_t outputTransfer_start, outputTransfer_stop; @@ -489,7 +515,10 @@ void runTest(const string& testName, ResultDatabase& resultDB, OptionParser& op) CUDA_SAFE_CALL(cudaFreeHost(force)); CUDA_SAFE_CALL(cudaFreeHost(neighborList)); // Device - CUDA_SAFE_CALL(cudaUnbindTexture(posTexture)); + if (h_posTexture) CUDA_SAFE_CALL(cudaDestroyTextureObject(h_posTexture)); + if (h_posTexture_dp) CUDA_SAFE_CALL(cudaDestroyTextureObject(h_posTexture_dp)); + h_posTexture = 0; + h_posTexture_dp = 0; CUDA_SAFE_CALL(cudaFree(d_position)); CUDA_SAFE_CALL(cudaFree(d_force)); CUDA_SAFE_CALL(cudaFree(d_neighborList)); diff --git a/src/cuda/shoc-master/src/cuda/level1/spmv/Spmv.cu b/src/cuda/shoc-master/src/cuda/level1/spmv/Spmv.cu index 6432e0f25..8899a2c17 100644 --- a/src/cuda/shoc-master/src/cuda/level1/spmv/Spmv.cu +++ b/src/cuda/shoc-master/src/cuda/level1/spmv/Spmv.cu @@ -10,21 +10,42 @@ using namespace std; -texture vecTex; // vector textures -texture vecTexD; +/* Texture references were removed in CUDA 12; the host fills these handles + via cudaMemcpyToSymbol so the reader structs below are unchanged. */ +__constant__ cudaTextureObject_t vecTex; // vector textures +__constant__ cudaTextureObject_t vecTexD; +static cudaTextureObject_t h_vecTex = 0; +static cudaTextureObject_t h_vecTexD = 0; + +template +static cudaTextureObject_t makeVecTexture(void *ptr, size_t bytes) +{ + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeLinear; + resDesc.res.linear.devPtr = ptr; + resDesc.res.linear.desc = cudaCreateChannelDesc(); + resDesc.res.linear.sizeInBytes = bytes; + texDesc.readMode = cudaReadModeElementType; + cudaTextureObject_t obj = 0; + CUDA_SAFE_CALL(cudaCreateTextureObject(&obj, &resDesc, &texDesc, NULL)); + return obj; +} // Texture Readers (used so kernels can be templated) struct texReaderSP { __device__ __forceinline__ float operator()(const int idx) const { - return tex1Dfetch(vecTex, idx); + return tex1Dfetch(vecTex, idx); } }; struct texReaderDP { __device__ __forceinline__ double operator()(const int idx) const { - int2 v = tex1Dfetch(vecTexD, idx); + int2 v = tex1Dfetch(vecTexD, idx); #if (__CUDA_ARCH__ < 130) // Devices before arch 130 don't support DP, and having the // __hiloint2double() intrinsic will cause compilation to fail. @@ -219,14 +240,14 @@ void csrTest(ResultDatabase& resultDB, OptionParser& op, floatType* h_val, if (sizeof(floatType) == sizeof(float)) { cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(); - CUDA_SAFE_CALL(cudaBindTexture(0, vecTex, d_vec, channelDesc, - numRows * sizeof(float))); + h_vecTex = makeVecTexture(d_vec, numRows * sizeof(float)); + CUDA_SAFE_CALL(cudaMemcpyToSymbol(vecTex, &h_vecTex, sizeof(h_vecTex))); suffix = "-SP"; } else { cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(); - CUDA_SAFE_CALL(cudaBindTexture(0, vecTexD, d_vec, channelDesc, - numRows * sizeof(int2))); + h_vecTexD = makeVecTexture(d_vec, numRows * sizeof(int2)); + CUDA_SAFE_CALL(cudaMemcpyToSymbol(vecTexD, &h_vecTexD, sizeof(h_vecTexD))); suffix = "-DP"; } @@ -280,7 +301,7 @@ void csrTest(ResultDatabase& resultDB, OptionParser& op, floatType* h_val, gflop / (scalarKernelTime+totalTransfer)); } zero<<>>(d_out, numRows); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); cout << "CSR Vector Kernel\n"; for (int k=0; k(); - CUDA_SAFE_CALL(cudaBindTexture(0, vecTex, d_vec, channelDesc, - numRows * sizeof(float))); + h_vecTex = makeVecTexture(d_vec, numRows * sizeof(float)); + CUDA_SAFE_CALL(cudaMemcpyToSymbol(vecTex, &h_vecTex, sizeof(h_vecTex))); } else { cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(); - CUDA_SAFE_CALL(cudaBindTexture(0, vecTexD, d_vec, channelDesc, - numRows * sizeof(int2))); + h_vecTexD = makeVecTexture(d_vec, numRows * sizeof(int2)); + CUDA_SAFE_CALL(cudaMemcpyToSymbol(vecTexD, &h_vecTexD, sizeof(h_vecTexD))); } int nBlocks = (int) ceil((floatType) cmSize / BLOCK_SIZE); int passes = op.getOptionInt("passes"); @@ -435,11 +456,11 @@ void ellPackTest(ResultDatabase& resultDB, OptionParser& op, floatType* h_val, CUDA_SAFE_CALL(cudaFree(d_cols)); if (sizeof(floatType) == sizeof(double)) { - CUDA_SAFE_CALL(cudaUnbindTexture(vecTexD)); + CUDA_SAFE_CALL(cudaDestroyTextureObject(h_vecTexD)); } else { - CUDA_SAFE_CALL(cudaUnbindTexture(vecTex)); + CUDA_SAFE_CALL(cudaDestroyTextureObject(h_vecTex)); } CUDA_SAFE_CALL(cudaEventDestroy(start)); CUDA_SAFE_CALL(cudaEventDestroy(stop)); diff --git a/src/cuda/shoc-master/src/cuda/level1/triad/Triad.cu b/src/cuda/shoc-master/src/cuda/level1/triad/Triad.cu index 3feaedea0..7cfe59db3 100644 --- a/src/cuda/shoc-master/src/cuda/level1/triad/Triad.cu +++ b/src/cuda/shoc-master/src/cuda/level1/triad/Triad.cu @@ -236,7 +236,7 @@ void RunBenchmark(ResultDatabase &resultDB, OptionParser &op) currStream = !currStream; } - cudaThreadSynchronize(); + cudaDeviceSynchronize(); double time = Timer::Stop(TH, "thread synchronize"); double triad = ((double)numMaxFloats * 2.0) / (time*1e9); diff --git a/src/cuda/shoc-master/src/cuda/level2/qtclustering/QTC.cu b/src/cuda/shoc-master/src/cuda/level2/qtclustering/QTC.cu index 441b1dd92..50399b5d4 100644 --- a/src/cuda/shoc-master/src/cuda/level2/qtclustering/QTC.cu +++ b/src/cuda/shoc-master/src/cuda/level2/qtclustering/QTC.cu @@ -22,7 +22,10 @@ #include "comm.h" -texture texDistance; +/* Texture references were removed in CUDA 12; the host fills this handle + via cudaMemcpyToSymbol so the kernel headers are unchanged. */ +__constant__ cudaTextureObject_t texDistance; +static cudaTextureObject_t h_texDistance = 0; using namespace std; @@ -400,14 +403,11 @@ void QTC(const string& name, ResultDatabase &resultDB, OptionParser& op, int mat output = pmsAllocHostBuffer(max_degree); if( can_use_texture ){ - texDistance.addressMode[0] = cudaAddressModeClamp; - texDistance.addressMode[1] = cudaAddressModeClamp; - texDistance.filterMode = cudaFilterModePoint; - texDistance.normalized = false; // do not normalize coordinates // This is the actual distance matrix (dst_matrix_elems should be "point_count^2, or point_count*max_degree) printf("Allocating: %luMB (%lux%lux%lu) bytes in texture memory\n", dst_matrix_elems*sizeof(float)/(1024*1024), dst_matrix_elems/point_count, point_count, (long unsigned int)sizeof(float)); - cudaMallocArray(&distance_matrix_txt, &texDistance.channelDesc, dst_matrix_elems/point_count, point_count); + cudaChannelFormatDesc texDistanceChannelDesc = cudaCreateChannelDesc(); + cudaMallocArray(&distance_matrix_txt, &texDistanceChannelDesc, dst_matrix_elems/point_count, point_count); }else{ allocDeviceBuffer(&distance_matrix_gmem, dst_matrix_elems*sizeof(float)); } @@ -430,7 +430,21 @@ void QTC(const string& name, ResultDatabase &resultDB, OptionParser& op, int mat if( can_use_texture ){ cudaMemcpyToArray(distance_matrix_txt, 0, 0, dist_source, dst_matrix_elems*sizeof(float), cudaMemcpyHostToDevice); CHECK_CUDA_ERROR(); - cudaBindTextureToArray(texDistance, distance_matrix_txt); + { + cudaResourceDesc resDesc; + cudaTextureDesc texDesc; + memset(&resDesc, 0, sizeof(resDesc)); + memset(&texDesc, 0, sizeof(texDesc)); + resDesc.resType = cudaResourceTypeArray; + resDesc.res.array.array = distance_matrix_txt; + texDesc.addressMode[0] = cudaAddressModeClamp; + texDesc.addressMode[1] = cudaAddressModeClamp; + texDesc.filterMode = cudaFilterModePoint; + texDesc.normalizedCoords = 0; + texDesc.readMode = cudaReadModeElementType; + cudaCreateTextureObject(&h_texDistance, &resDesc, &texDesc, NULL); + cudaMemcpyToSymbol(texDistance, &h_texDistance, sizeof(h_texDistance)); + } }else{ copyToDevice(distance_matrix_gmem, dist_source, dst_matrix_elems*sizeof(float)); } @@ -444,7 +458,7 @@ void QTC(const string& name, ResultDatabase &resultDB, OptionParser& op, int mat tpb = ( point_count > THREADSPERBLOCK )? THREADSPERBLOCK : point_count; compute_degrees<<>>((int *)indr_mtrx, (int *)degrees, point_count, max_degree); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CHECK_CUDA_ERROR(); const char *sizeStr; @@ -515,7 +529,7 @@ void QTC(const string& name, ResultDatabase &resultDB, OptionParser& op, int mat total_thread_block_count, matrix_type, can_use_texture); ///////// ----------------- Main kernel ----------------- ///////// //////////////////////////////////////////////////////////////////////////////////////////////// - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CHECK_CUDA_ERROR(); t_krn += Timer::Stop(Tkernel, "Kernel Only"); @@ -523,7 +537,7 @@ void QTC(const string& name, ResultDatabase &resultDB, OptionParser& op, int mat if( thread_block_count > 1 ){ // We are reducing 128 numbers or less, so one thread should be sufficient. reduce_card_device<<>>((int *)cardnl, thread_block_count); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CHECK_CUDA_ERROR(); } @@ -549,7 +563,7 @@ void QTC(const string& name, ResultDatabase &resultDB, OptionParser& op, int mat (int *)result, (char *)Ai_mask, (char *)clustered_pnts_mask, (int *)indr_mtrx, (int *)cardnl, (float *)dist_to_clust, (int *)degrees, point_count, max_point_count, max_degree, threshold, matrix_type, can_use_texture ); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CHECK_CUDA_ERROR(); t_trim += Timer::Stop(Ttrim, "Trim Only"); @@ -572,7 +586,7 @@ void QTC(const string& name, ResultDatabase &resultDB, OptionParser& op, int mat int Tupdt = Timer::Start(); update_clustered_pnts_mask<<>>((char *)clustered_pnts_mask, (char *)Ai_mask, max_point_count); - cudaThreadSynchronize(); + cudaDeviceSynchronize(); CHECK_CUDA_ERROR(); t_updt += Timer::Stop(Tupdt, "Update Only"); @@ -606,7 +620,7 @@ void QTC(const string& name, ResultDatabase &resultDB, OptionParser& op, int mat pmsFreeHostBuffer(indr_mtrx_host); if( can_use_texture ){ cudaFreeArray(distance_matrix_txt); - cudaUnbindTexture(texDistance); + cudaDestroyTextureObject(h_texDistance); }else{ freeDeviceBuffer(distance_matrix_gmem); } diff --git a/src/cuda/shoc-master/src/cuda/level2/qtclustering/kernels_compact_storage.h b/src/cuda/shoc-master/src/cuda/level2/qtclustering/kernels_compact_storage.h index 98e7d962b..08099808d 100644 --- a/src/cuda/shoc-master/src/cuda/level2/qtclustering/kernels_compact_storage.h +++ b/src/cuda/shoc-master/src/cuda/level2/qtclustering/kernels_compact_storage.h @@ -26,7 +26,7 @@ do{\ }\ if( tmp_pnt == (_CAND_PNT_) ){\ if( can_use_texture ){ \ - dist_to_new_point = tex2D(texDistance, float(j)+0.5f, float(latest_point)+0.5f );\ + dist_to_new_point = tex2D(texDistance, float(j)+0.5f, float(latest_point)+0.5f );\ }else{\ dist_to_new_point = compact_storage_dist_matrix[ latest_p_off + j ];\ }\ diff --git a/src/cuda/shoc-master/src/cuda/level2/qtclustering/kernels_full_storage.h b/src/cuda/shoc-master/src/cuda/level2/qtclustering/kernels_full_storage.h index 22edb2314..411f3a0f7 100644 --- a/src/cuda/shoc-master/src/cuda/level2/qtclustering/kernels_full_storage.h +++ b/src/cuda/shoc-master/src/cuda/level2/qtclustering/kernels_full_storage.h @@ -21,7 +21,7 @@ int find_closest_point_to_cluster(int seed_point, int latest_point, char *Ai_mas float curr_dist_to_clust = dist_to_clust[i+tid]; if( can_use_texture ){ - dist_to_new_point = tex2D(texDistance, float(latest_point)+0.5f, float(pnt2_indx)+0.5f ); + dist_to_new_point = tex2D(texDistance, float(latest_point)+0.5f, float(pnt2_indx)+0.5f ); }else{ dist_to_new_point = work[pnt2_indx*N0 + latest_point]; } @@ -56,7 +56,7 @@ do{ \ \ float curr_dist_to_clust = _CAND_PNT_DIST_; \ if( can_use_texture ){\ - dist_to_new_point = tex2D(texDistance, float(latest_point)+0.5f, float( (_CAND_PNT_) )+0.5f ); \ + dist_to_new_point = tex2D(texDistance, float(latest_point)+0.5f, float( (_CAND_PNT_) )+0.5f ); \ }else{\ dist_to_new_point = work[ (_CAND_PNT_) * N0 + latest_point]; \ }\ diff --git a/src/setup_environment b/src/setup_environment index 21b42af72..6683dd077 100755 --- a/src/setup_environment +++ b/src/setup_environment @@ -13,11 +13,69 @@ export GPUAPPS_ROOT="$( cd "$( dirname "$SCRIPT_PATH" )" >/dev/null 2>&1 && pwd echo GPUAPPS_ROOT=$GPUAPPS_ROOT export CUDA_PATH=$CUDA_INSTALL_PATH +if [ ! -n "$CUDA_INSTALL_PATH" ]; then + echo "ERROR *** CUDA_INSTALL_PATH not set;" + return +elif [ ! -d "$CUDA_INSTALL_PATH" ]; then + echo "ERROR *** CUDA_INSTALL_PATH=$CUDA_INSTALL_PATH invalid. directory does not exist."; + return +else + NVCC_PATH=`which nvcc`; + if [ $? != 0 ]; then + echo ""; + echo "ERROR ** nvcc (from CUDA Toolkit) was not found in PATH but required to build the ISPASS 2009 benchmarks."; + echo " Try adding $(CUDA_INSTALL_PATH)/bin/ to your PATH environment variable."; + echo ""; + return + fi +fi + export CUDA_VERSION=`nvcc --version | grep release | sed -re 's/.*release ([0-9]+\.[0-9]+).*/\1/'`; export CUDA_VERSION_MAJOR=`nvcc --version | grep release | sed -re 's/.*release ([0-9]+)\..*/\1/'`; export CUDA_VERSION_MINOR=$(nvcc --version | grep release | sed -re 's/.*release [0-9]+\.([0-9]+).*/\1/') +export CUDACXX=${CUDA_INSTALL_PATH}/bin/nvcc export CUDAHOME=$CUDA_INSTALL_PATH +# The rodinia makefiles reference these but nothing ever defined them, so their +# -L/-I expanded empty and the link failed to find libcudart. lib64 is the real +# location on every 64-bit toolkit; plain lib is the 32-bit/very-old fallback. +export CUDA_DIR=$CUDA_INSTALL_PATH +if [ -d "$CUDA_INSTALL_PATH/lib64" ]; then + export CUDA_LIB_DIR=$CUDA_INSTALL_PATH/lib64 +else + export CUDA_LIB_DIR=$CUDA_INSTALL_PATH/lib +fi + +# Several benchmarks were written against the GPU Computing SDK 4.2 cutil helpers. +# Newer toolkits removed those entirely (CUDA 11 dropped the bundled samples), so +# the ~450 KB actually needed is vendored under cuda/common/sdk-compat instead of +# downloading the 152 MB SDK installer at setup time. See that directory's NOTICE. +export GPUAPPS_SDK_DIR=$GPUAPPS_ROOT/src/cuda/common/sdk-compat +export GPUAPPS_SDK_INC=$GPUAPPS_SDK_DIR/inc +export GPUAPPS_SDK_LIB=$GPUAPPS_SDK_DIR/lib + +# Kept so any straggler referring to the old variable still resolves to headers. +export NVIDIA_COMPUTE_SDK_LOCATION=$GPUAPPS_SDK_DIR + +# The SDK only ever shipped a prebuilt libcutil_x86_64.a, which is useless on +# aarch64/ppc64le. Build the archive for whatever host we are actually on. +GPUAPPS_HOSTARCH=`uname -m` +if [ ! -f "$GPUAPPS_SDK_LIB/libcutil_$GPUAPPS_HOSTARCH.a" ]; then + echo "Building libcutil_$GPUAPPS_HOSTARCH.a from vendored SDK sources" + GPUAPPS_CUTIL_TMP=`mktemp -d` + for f in cutil bank_checker cmd_arg_reader multithreading stopwatch stopwatch_linux; do + if [ -f "$GPUAPPS_SDK_DIR/src/$f.cpp" ]; then + g++ -O2 -fPIC -I"$GPUAPPS_SDK_INC" -I"$CUDA_INSTALL_PATH/include" \ + -c "$GPUAPPS_SDK_DIR/src/$f.cpp" -o "$GPUAPPS_CUTIL_TMP/$f.o" || true + fi + done + if ls "$GPUAPPS_CUTIL_TMP"/*.o >/dev/null 2>&1; then + mkdir -p "$GPUAPPS_SDK_LIB" + ar rcs "$GPUAPPS_SDK_LIB/libcutil_$GPUAPPS_HOSTARCH.a" "$GPUAPPS_CUTIL_TMP"/*.o + fi + rm -rf "$GPUAPPS_CUTIL_TMP" +fi + export BINDIR=$GPUAPPS_ROOT/bin/$CUDA_VERSION export BINSUBDIR=release @@ -28,101 +86,92 @@ export MAKE_ARGS="" export CUDA_CPPFLAGS="" export NVCC_ADDITIONAL_ARGS="" -export CUDACXX=${CUDA_INSTALL_PATH}/bin/nvcc - -if [ $CUDA_VERSION_MAJOR -eq 4 ]; then - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_10,code=compute_10" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_13,code=compute_13" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_20,code=compute_20" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_30,code=compute_30" -fi -if [ $CUDA_VERSION_MAJOR -eq 5 ]; then - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_10,code=compute_10" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_13,code=compute_13" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_20,code=compute_20" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_30,code=compute_30" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_35,code=compute_35" -fi -if [ $CUDA_VERSION_MAJOR -eq 6 ]; then - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_10,code=compute_10" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_13,code=compute_13" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_20,code=compute_20" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_30,code=compute_30" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_35,code=compute_35" -fi -if [ $CUDA_VERSION_MAJOR -eq 7 ]; then - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_20,code=compute_20" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_30,code=compute_30" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_35,code=compute_35" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_50,code=compute_50" -fi -if [ $CUDA_VERSION_MAJOR -eq 8 ]; then - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_20,code=compute_20" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_30,code=compute_30" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_35,code=compute_35" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_50,code=compute_50" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_60,code=compute_60" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_62,code=compute_62" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -std=c++11" -fi -if [ $CUDA_VERSION_MAJOR -eq 9 ]; then - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_30,code=compute_30" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_35,code=compute_35" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_50,code=compute_50" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_60,code=compute_60" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_62,code=compute_62" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_70,code=compute_70" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -std=c++11" -fi -if [ $CUDA_VERSION_MAJOR -eq 10 ]; then - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_30,code=compute_30" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_35,code=compute_35" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_50,code=compute_50" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_60,code=compute_60" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_62,code=compute_62" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_70,code=compute_70" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_75,code=compute_75" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -std=c++11" -fi -if [ $CUDA_VERSION_MAJOR -eq 11 ]; then - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_61,code=compute_61" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_70,code=compute_70" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_75,code=compute_75" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -std=c++17" -fi -if [ $CUDA_VERSION_MAJOR -eq 12 ]; then - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_70,code=compute_70" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_75,code=compute_75" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_80,code=compute_80" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_86,code=compute_86" - if [ $CUDA_VERSION_MINOR -ge 8 ]; then - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_90,code=compute_90" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_90a,code=compute_90a" - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -gencode=arch=compute_100,code=compute_100" +################################################################################ +# GPU architecture selection +# +# Every new toolkit drops old architectures and adds new ones, so rather than +# maintaining a per-version table here (which silently produced *no* gencode +# flags once the toolkit outran the table), ask nvcc what it actually accepts +# and intersect that with the architectures we want to target. +################################################################################ + +# Architectures referenced by Makefiles anywhere in this tree. Every one of these +# gets a GENCODE_SMxx value below - either a real flag or empty - so that no +# Makefile can emit a -gencode for an architecture this toolkit rejects. +GPUAPPS_ALL_ARCHS="10 11 12 13 20 21 30 32 35 37 50 52 53 60 61 62 70 72 75 80 86 87 88 89 90 100 103 110 120 121" + +# What we'd like to build for, overridable via GPUAPPS_ARCHS="70 80" to cut build time. +# 100/103 are Blackwell datacenter (B100/B200 and B300/GB300). Without them a +# B300 runs these binaries by JIT-ing the sm_90 PTX at load time instead of +# native SASS. Trim this via GPUAPPS_ARCHS="80 90" to cut build time. +# +# sm_70 is the floor on purpose, not because older targets are unsupported by +# the toolkit. Parts of the suite have assumed Volta since the CUDA 11 era -- +# the tensor-core ubenches are the clearest case, since only defines +# nvcuda::wmma for __CUDA_ARCH__ >= 700 -- so asking a CUDA 12 toolkit for +# compute_50/60/62 breaks them. CUDA 13 cannot emit anything below sm_75 +# anyway, so this only affects older toolkits. +GPUAPPS_DESIRED_ARCHS=${GPUAPPS_ARCHS:-"70 75 80 86 90 100 103"} + +# --list-gpu-arch landed in CUDA 11; older toolkits need the static fallback below. +GPUAPPS_SUPPORTED_ARCHS=`nvcc --list-gpu-arch 2>/dev/null | sed -e 's/^compute_//' | tr '\n' ' '` +if [ -z "$GPUAPPS_SUPPORTED_ARCHS" ]; then + case $CUDA_VERSION_MAJOR in + 4) GPUAPPS_SUPPORTED_ARCHS="10 11 12 13 20 21 30" ;; + 5) GPUAPPS_SUPPORTED_ARCHS="10 11 12 13 20 21 30 35" ;; + 6) GPUAPPS_SUPPORTED_ARCHS="10 11 12 13 20 21 30 32 35 37 50" ;; + 7) GPUAPPS_SUPPORTED_ARCHS="20 21 30 32 35 37 50 52 53" ;; + 8) GPUAPPS_SUPPORTED_ARCHS="20 21 30 32 35 37 50 52 53 60 61 62" ;; + 9) GPUAPPS_SUPPORTED_ARCHS="30 32 35 37 50 52 53 60 61 62 70 72" ;; + 10) GPUAPPS_SUPPORTED_ARCHS="30 32 35 37 50 52 53 60 61 62 70 72 75" ;; + *) GPUAPPS_SUPPORTED_ARCHS="52 53 60 61 62 70 72 75 80 86 87 89 90" ;; + esac +fi + +# Build the flag set. GENCODE_SMxx is exported through MAKE_ARGS as a make +# command-line override, which beats the ?= and := defaults in every common.mk. +GPUAPPS_BUILD_ARCHS="" +for arch in $GPUAPPS_ALL_ARCHS; do + if echo " $GPUAPPS_DESIRED_ARCHS " | grep -q " $arch " && \ + echo " $GPUAPPS_SUPPORTED_ARCHS " | grep -q " $arch "; then + # Bracket syntax rather than code=\"sm_XX,compute_XX\": same SASS+PTX output, + # but contains no spaces, so passing it through MAKE_ARGS cannot be split + # into a stray make goal. PTX must stay embedded for GPGPU-Sim to run these. + gencode="-gencode=arch=compute_${arch},code=[sm_${arch},compute_${arch}]" + export MAKE_ARGS="$MAKE_ARGS GENCODE_SM${arch}=$gencode" + export CUDA_CPPFLAGS="$CUDA_CPPFLAGS $gencode" + GPUAPPS_BUILD_ARCHS="$GPUAPPS_BUILD_ARCHS $arch" + else + export MAKE_ARGS="$MAKE_ARGS GENCODE_SM${arch}=" fi - export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -std=c++17" +done +if [ -z "$GPUAPPS_BUILD_ARCHS" ]; then + echo "ERROR *** No usable GPU architectures. CUDA $CUDA_VERSION supports:" + echo " $GPUAPPS_SUPPORTED_ARCHS" + echo " but GPUAPPS_ARCHS requested: $GPUAPPS_DESIRED_ARCHS" + return fi +echo "Building for SM:$GPUAPPS_BUILD_ARCHS (CUDA $CUDA_VERSION supports: $GPUAPPS_SUPPORTED_ARCHS)" +# Host C++ standard. nvcc 12+ dropped c++11, 13 dropped c++14. +if [ $CUDA_VERSION_MAJOR -ge 12 ]; then + export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -std=c++17" +elif [ $CUDA_VERSION_MAJOR -ge 11 ]; then + export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -std=c++14" +elif [ $CUDA_VERSION_MAJOR -ge 8 ]; then + export CUDA_CPPFLAGS="$CUDA_CPPFLAGS -std=c++11" +fi - -# Turn off the gencodes for cuda versions. Above 6 - no 10 support. -# Depending on new the cuda version is, then different SMs are supported +# Feature gates consumed by the top-level Makefile to pick the app list. if [ $CUDA_VERSION_MAJOR -gt 4 ]; then export CUDA_GT_4=1 fi - -if [ $CUDA_VERSION_MAJOR -gt 6 ]; then - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM10=" - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM13=" -fi - if [ $CUDA_VERSION_MAJOR -gt 7 ]; then export CUDA_GT_7=1 export NVCC_ADDITIONAL_ARGS="--cudart shared -Wno-deprecated-gpu-targets" export MAKE_ARGS="$MAKE_ARGS GENCODE_SM20=" fi - if [ $CUDA_VERSION_MAJOR -gt 10 ]; then export CUDA_GT_10=1 export NVCC_ADDITIONAL_ARGS="--cudart shared -Wno-deprecated-gpu-targets" @@ -132,64 +181,23 @@ if [ $CUDA_VERSION_MAJOR -gt 10 ]; then export MAKE_ARGS="$MAKE_ARGS GENCODE_SM50=" fi -if [ $CUDA_VERSION_MAJOR -lt 5 ]; then - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM35=" - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM50=" - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM60=" - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM62=" -fi - - -if [ $CUDA_VERSION_MAJOR -lt 7 ]; then - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM50=" - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM60=" - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM62=" -fi - -if [ $CUDA_VERSION_MAJOR -lt 8 ]; then - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM60=" - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM62=" -fi - -if [ $CUDA_VERSION_MAJOR -lt 9 ]; then - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM70=" - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM75=" -fi - -if [ $CUDA_VERSION_MAJOR -lt 10 ]; then - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM75=" -fi - - -# 20 Deprecated in 9+ -if [ $CUDA_VERSION_MAJOR -gt 8 ]; then - export MAKE_ARGS="$MAKE_ARGS GENCODE_SM20=" +# cuDNN from the distro packages ships only the shared library, while the +# NVIDIA tarball also ships libcudnn_static.a. Pick whichever is present. +if ls $CUDA_INSTALL_PATH/lib64/libcudnn_static.a /usr/lib/*/libcudnn_static.a >/dev/null 2>&1; then + export CUDNN_LIB=cudnn_static +else + export CUDNN_LIB=cudnn fi - -export MAKE_ARGS="$MAKE_ARGS CUBLAS_LIB=cublas_static CUDNN_LIB=cudnn_static" +export MAKE_ARGS="$MAKE_ARGS CUBLAS_LIB=cublas_static CUDNN_LIB=$CUDNN_LIB" export GENCODE_FLAGS=$CUDA_CPPFLAGS export CUDA_CPPFLAGS="$CUDA_CPPFLAGS $NVCC_ADDITIONAL_ARGS" echo MAKE_ARGS=$MAKE_ARGS -if [ ! -d "$GPUAPPS_ROOT/4.2/" ]; then - echo "SDK 4.2 Not detected - installing and building" - if [ ! -f "$GPUAPPS_ROOT/gpucomputingsdk_4.2.9_linux.run" ]; then - wget http://developer.download.nvidia.com/compute/cuda/4_2/rel/sdk/gpucomputingsdk_4.2.9_linux.run -O \ - "$GPUAPPS_ROOT/gpucomputingsdk_4.2.9_linux.run" - fi - chmod u+x "$GPUAPPS_ROOT/gpucomputingsdk_4.2.9_linux.run" - "$GPUAPPS_ROOT/gpucomputingsdk_4.2.9_linux.run" -- --prefix="$GPUAPPS_ROOT/4.2" --cudaprefix="$CUDA_INSTALL_PATH" - export NVIDIA_COMPUTE_SDK_LOCATION="$GPUAPPS_ROOT/4.2" - rm "$GPUAPPS_ROOT/gpucomputingsdk_4.2.9_linux.run" - make -C "$NVIDIA_COMPUTE_SDK_LOCATION/shared" - make -C "$NVIDIA_COMPUTE_SDK_LOCATION/C/common" - make -C "$NVIDIA_COMPUTE_SDK_LOCATION/C/common" -f Makefile_paramgl - make -C "$NVIDIA_COMPUTE_SDK_LOCATION/C/common" -f Makefile_rendercheckgl -else - echo "SDK 4.2 detected" - export NVIDIA_COMPUTE_SDK_LOCATION="$GPUAPPS_ROOT/4.2" -fi +# The GPU Computing SDK 4.2 download used to be fetched and built here. It only +# ever shipped prebuilt x86_64 objects and its makefiles pass -m64, so it cannot +# build on aarch64 at all. The ~450 KB of cutil helpers actually needed is +# vendored under cuda/common/sdk-compat instead; see that directory's NOTICE. if [ ! -n "$CUDA_INSTALL_PATH" ]; then echo "ERROR *** CUDA_INSTALL_PATH not set;" return