Commit a272c837 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Replacing source code files from CUDA samples.

parent e57c9cbb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ option(BUILD_TESTS "Build tests" OFF)
option(BUILD_MATRIX_TESTS "Build tests for matrix formats" OFF)
option(BUILD_PYTHON "Compile the Python bindings" OFF)
option(BUILD_DOC "Build examples included in the documentation" OFF)
set(CUDA_SAMPLES_PATH "none" CACHE STRING "Path to CUDA Samples - it is used only for some benchmarking.")

# install paths relative to the cmake's prefix
set( TNL_TARGET_INCLUDE_DIRECTORY "include/TNL" )
@@ -253,6 +254,9 @@ if( ${WITH_CUDA} )
        endif()
        set( CMAKE_EXECUTABLE_SUFFIX "${executable_suffix_backup}" )
    endif()
    if( NOT CUDA_SAMPLES_DIR STREQUAL "none" )
      set( CUDA_SAMPLES_FLAGS "-I${CUDA_SAMPLES_DIR}/common/inc")
    endif()
endif()


@@ -407,6 +411,7 @@ message( " CMAKE_SHARED_LINKER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}" )
message( "   CMAKE_SHARED_LINKER_FLAGS_DEBUG = ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" )
message( "   CMAKE_SHARED_LINKER_FLAGS_RELEASE = ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}" )
message( "   CUDA_NVCC_FLAGS = ${CUDA_NVCC_FLAGS}" )
message( "   CUDA_SAMPLES_FLAGS = ${CUDA_SAMPLES_FLAGS}" )
message( "   GMP_LIBRARIES = ${GMP_LIBRARIES}" )
if( MPI_CXX_FOUND AND ${WITH_MPI} )
   message( "   MPI_CXX_COMPILE_OPTIONS = ${MPI_CXX_COMPILE_OPTIONS}" )
+12 −0
Original line number Diff line number Diff line
@@ -39,6 +39,13 @@ BUILD_TESTS="no"
BUILD_MATRIX_TESTS="no"
BUILD_DOC="no"

# external dependencies
CUDA_SAMPLES_DIR=none

if [[ x"$CUDA_SAMPLES_PATH" != "x" ]]; then
   CUDA_SAMPLES_DIR=${CUDA_SAMPLES_PATH}
fi

function print_usage()
{
    cat << EOF
@@ -85,6 +92,9 @@ Options for the 'tests' and 'matrix-tests' targets:
    --tests-jobs=NUM                      Number of processes to be used for the unit tests. It is $TEST_JOBS by default.
    --with-coverage=yes/no                Enables code coverage reports for unit tests (lcov is required). '$WITH_COVERAGE' by default.
    --with-system-gtest=yes/no            Use GTest installed in the local system and do not download the latest version. '$WITH_SYSTEM_GTEST' by default.

External dependencies:
   --cuda-samples-dir=PATH                CUDA samples are used by some reference algorithms used in benchmarks. '$CUDA_SAMPLES_PATH` by default.
EOF
}

@@ -120,6 +130,7 @@ for option in "$@"; do
        --with-coverage=*     ) WITH_COVERAGE="${option#*=}" ;;
        --with-ci-flags=*     ) WITH_CI_FLAGS="${option#*=}" ;;
        --with-system-gtest=* ) WITH_SYSTEM_GTEST="${option#*=}" ;;
        --cuda-samples-path=*  ) CUDA_SAMPLES_DIR="${option#*=}" ;;
        -*                    )
            echo "Unknown option $option. Use --help for more information." >&2
            exit 1
@@ -216,6 +227,7 @@ cmake_command=(
         -DBUILD_MATRIX_TESTS=${BUILD_MATRIX_TESTS}
         -DBUILD_PYTHON=${BUILD_PYTHON}
         -DBUILD_DOC=${BUILD_DOC}
         -DCUDA_SAMPLES_DIR=${CUDA_SAMPLES_DIR}
)

# Skip running cmake if it was already run and the cmake command is the same.
+1 −1
Original line number Diff line number Diff line
if( BUILD_CUDA )
    CUDA_ADD_EXECUTABLE( tnl-benchmark-sort tnl-benchmark-sort.cu OPTIONS -Xcompiler -Wno-error=switch,-Wno-error=sign-compare)
    CUDA_ADD_EXECUTABLE( tnl-benchmark-sort tnl-benchmark-sort.cu OPTIONS -Xcompiler -Wno-error=switch,-Wno-error=sign-compare ${CUDA_SAMPLES_FLAGS} )
    # Source code of reference algorithms contains warning which turn into errers with CI/CD compiler flags. Therefore we use -Wno-error to turn it off.
    TARGET_LINK_LIBRARIES( tnl-benchmark-sort ${CUDA_cusparse_LIBRARY} ${CUDA_cudadevrt_LIBRARY} )
else()
+5 −5
Original line number Diff line number Diff line
@@ -217,8 +217,8 @@ inline __device__ void compareInclusive(Type &idata, Type &idata2, volatile Type
}

#include <assert.h>
#include "helpers/helper_cuda.h"
#include "helpers/scan_common.h"
#include <helper_cuda.h>
#include <../../6_Advanced/scan/scan_common.h>

//All three kernels run 512 threads per workgroup
//Must be a power of two
@@ -654,9 +654,9 @@ size_t scanInclusiveLarge(


#include <thrust/scan.h>
#include "helpers/helper_cuda.h"
#include "helpers/helper_timer.h"
#include "helpers/scan_common.h"
#include <helper_cuda.h>
#include <helper_timer.h>
#include <../../6_Advanced/scan/scan_common.h>

extern __shared__ uint sMemory[];

+0 −151
Original line number Diff line number Diff line
/*
* 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 <exception>
#include <stdexcept>
#include <iostream>
#include <stdlib.h>

//! Exception wrapper.
//! @param Std_Exception Exception out of namespace std for easy typing.
template<class Std_Exception>
class Exception : public Std_Exception
{
    public:

        //! @brief Static construction interface
        //! @return Alwayss throws ( Located_Exception<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<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<class Exception_Typ>
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<std::runtime_error>::throw_it( __FILE__, __LINE__, msg)

//! Logic exception in program, e.g. an assert failed
#define LOGIC_EXCEPTION( msg) \
    Exception<std::logic_error>::throw_it( __FILE__, __LINE__, msg)

//! Out of range exception
#define RANGE_EXCEPTION( msg) \
    Exception<std::range_error>::throw_it( __FILE__, __LINE__, msg)

////////////////////////////////////////////////////////////////////////////////
//! Implementation

// includes, system
#include <sstream>

////////////////////////////////////////////////////////////////////////////////
//! Static construction interface.
//! @param  Exception causing code fragment (file and line) and detailed infos.
////////////////////////////////////////////////////////////////////////////////
/*static*/ template<class Std_Exception>
void
Exception<Std_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<class Std_Exception>
void
Exception<Std_Exception>::
throw_it(const char *file, const int line, const std::string &msg)
{
    throw_it(file, line, msg.c_str());
}

////////////////////////////////////////////////////////////////////////////////
//! Constructor, default (private).
////////////////////////////////////////////////////////////////////////////////
template<class Std_Exception>
Exception<Std_Exception>::Exception() :
    Exception("Unknown Exception.\n")
{ }

////////////////////////////////////////////////////////////////////////////////
//! Constructor, standard (private).
//! String returned by what().
////////////////////////////////////////////////////////////////////////////////
template<class Std_Exception>
Exception<Std_Exception>::Exception(const std::string &s) :
    Std_Exception(s)
{ }

////////////////////////////////////////////////////////////////////////////////
//! Destructor
////////////////////////////////////////////////////////////////////////////////
template<class Std_Exception>
Exception<Std_Exception>::~Exception() throw() { }

// functions, exported

#endif // #ifndef _EXCEPTION_H_
Loading