Skip to content

Commit

Permalink
Merge pull request #2927 from psychocoderHPC/topic-pmaccTypesCleanup
Browse files Browse the repository at this point in the history
cleanup `pmacc/types.hpp`
  • Loading branch information
ax3l authored Mar 23, 2019
2 parents 5bc8743 + 73fbb35 commit cbe4dbc
Show file tree
Hide file tree
Showing 14 changed files with 581 additions and 225 deletions.
49 changes: 49 additions & 0 deletions include/pmacc/attribute/Constexpr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* Copyright 2013-2019 Felix Schmitt, Heiko Burau, Rene Widera,
* Wolfgang Hoenig, Benjamin Worpitz,
* Alexander Grund
*
* This file is part of PMacc.
*
* PMacc is free software: you can redistribute it and/or modify
* it under the terms of either the GNU General Public License or
* the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PMacc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with PMacc.
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once


/**
* Visual Studio has a bug with constexpr variables being captured in lambdas as
* non-constexpr variables, causing build errors. The issue has been verified
* for versions 14.0 and 15.5 (latest at the moment) and is also reported in
* https://stackoverflow.com/questions/28763375/using-lambda-captured-constexpr-value-as-an-array-dimension
* and related issue
* https://developercommunity.visualstudio.com/content/problem/1997/constexpr-not-implicitely-captured-in-lambdas.html
*
* As a workaround (until this is fixed in VS) add a new PMACC_CONSTEXPR_CAPTURE
* macro for declaring constexpr variables that are captured in lambdas and have
* to remain constexpr inside a lambda e.g., used as a template argument. Such
* variables have to be declared with PMACC_CONSTEXPR_CAPTURE instead of
* constexpr. The macro will be replaced with just constexpr for other compilers
* and for Visual Studio with static constexpr, which makes it capture properly.
*
* Note that this macro is to be used only in very few cases, where not only a
* constexpr is captured, but also it has to remain constexpr inside a lambda.
*/
#ifdef _MSC_VER
# define PMACC_CONSTEXPR_CAPTURE static constexpr
#else
# define PMACC_CONSTEXPR_CAPTURE constexpr
#endif
45 changes: 45 additions & 0 deletions include/pmacc/attribute/Fallthrough.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Copyright 2013-2019 Felix Schmitt, Heiko Burau, Rene Widera,
* Wolfgang Hoenig, Benjamin Worpitz,
* Alexander Grund
*
* This file is part of PMacc.
*
* PMacc is free software: you can redistribute it and/or modify
* it under the terms of either the GNU General Public License or
* the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PMacc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with PMacc.
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

// compatibility macros (compiler or C++ standard version specific)
#include <boost/config.hpp>
// work-around for Boost 1.68.0
// fixed in https://github.com/boostorg/predef/pull/84
// see https://github.com/ComputationalRadiationPhysics/alpaka/pull/606
// include <boost/predef.h>
#include <alpaka/core/BoostPredef.hpp>


/** C++11 and C++14 explicit fallthrough in switch cases
*
* Use [[fallthrough]] in C++17
*/
#if (BOOST_COMP_GNUC >= BOOST_VERSION_NUMBER(7,0,0))
# define PMACC_FALLTHROUGH [[gnu::fallthrough]]
#elif BOOST_COMP_CLANG
# define PMACC_FALLTHROUGH [[clang::fallthrough]]
#else
# define PMACC_FALLTHROUGH ( (void)0 )
#endif
65 changes: 65 additions & 0 deletions include/pmacc/attribute/FunctionSpecifier.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Copyright 2013-2019 Felix Schmitt, Heiko Burau, Rene Widera,
* Wolfgang Hoenig, Benjamin Worpitz,
* Alexander Grund
*
* This file is part of PMacc.
*
* PMacc is free software: you can redistribute it and/or modify
* it under the terms of either the GNU General Public License or
* the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PMacc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with PMacc.
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <cupla/types.hpp>


#define HDINLINE ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE
#define DINLINE ALPAKA_FN_ACC ALPAKA_FN_INLINE
#define DEVICEONLY ALPAKA_FN_ACC
#define HINLINE ALPAKA_FN_HOST ALPAKA_FN_INLINE

/**
* CUDA architecture version (aka PTX ISA level)
* 0 for host compilation
*/
#ifndef __CUDA_ARCH__
# define PMACC_CUDA_ARCH 0
#else
# define PMACC_CUDA_ARCH __CUDA_ARCH__
#endif

/** PMacc global identifier for CUDA kernel */
#define PMACC_GLOBAL_KEYWORD DINLINE

/*
* Disable nvcc warning:
* calling a __host__ function from __host__ __device__ function.
*
* Usage:
* PMACC_NO_NVCC_HDWARNING
* HDINLINE function_declaration()
*
* It is not possible to disable the warning for a __host__ function
* if there are calls of virtual functions inside. For this case use a wrapper
* function.
* WARNING: only use this method if there is no other way to create runable code.
* Most cases can solved by #ifdef __CUDA_ARCH__ or #ifdef __CUDACC__.
*/
#if defined(__CUDACC__)
# define PMACC_NO_NVCC_HDWARNING _Pragma("hd_warning_disable")
#else
# define PMACC_NO_NVCC_HDWARNING
#endif
57 changes: 57 additions & 0 deletions include/pmacc/cuplaHelper/ValidateCall.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* Copyright 2013-2019 Felix Schmitt, Heiko Burau, Rene Widera,
* Wolfgang Hoenig, Benjamin Worpitz,
* Alexander Grund
*
* This file is part of PMacc.
*
* PMacc is free software: you can redistribute it and/or modify
* it under the terms of either the GNU General Public License or
* the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PMacc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with PMacc.
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <cuda_to_cupla.hpp>
#include <iostream>
#include <stdexcept>

namespace pmacc
{

/**
* Print a cuda error message including file/line info to stderr
*/
#define PMACC_PRINT_CUDA_ERROR(msg) \
std::cerr << "[CUDA] Error: <" << __FILE__ << ">:" << __LINE__ << " " << msg << std::endl

/**
* Print a cuda error message including file/line info to stderr and raises an exception
*/
#define PMACC_PRINT_CUDA_ERROR_AND_THROW(cudaError, msg) \
PMACC_PRINT_CUDA_ERROR(msg); \
throw std::runtime_error(std::string("[CUDA] Error: ") + std::string(cudaGetErrorString(cudaError)))

/**
* Captures CUDA errors and prints messages to stdout, including line number and file.
*
* @param cmd command with cudaError_t return value to check
*/
#define CUDA_CHECK(cmd) {cudaError_t error = cmd; if(error!=cudaSuccess){ PMACC_PRINT_CUDA_ERROR_AND_THROW(error, ""); }}

#define CUDA_CHECK_MSG(cmd,msg) {cudaError_t error = cmd; if(error!=cudaSuccess){ PMACC_PRINT_CUDA_ERROR_AND_THROW(error, msg); }}

#define CUDA_CHECK_NO_EXCEPT(cmd) {cudaError_t error = cmd; if(error!=cudaSuccess){ PMACC_PRINT_CUDA_ERROR(""); }}

} // namespace pmacc
35 changes: 19 additions & 16 deletions include/pmacc/debug/PMaccVerbose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,25 @@
namespace pmacc
{

/*create verbose class*/
DEFINE_VERBOSE_CLASS(PMaccVerbose)
(
/* define log lvl for later use
* e.g. log<pmaccLogLvl::NOTHING>("TEXT");*/
DEFINE_LOGLVL(0,NOTHING);
DEFINE_LOGLVL(1,MEMORY);
DEFINE_LOGLVL(2,INFO);
DEFINE_LOGLVL(4,CRITICAL);
DEFINE_LOGLVL(8,MPI);
DEFINE_LOGLVL(16,CUDA_RT);
DEFINE_LOGLVL(32,COMMUNICATION);
DEFINE_LOGLVL(64,EVENT);
)
/*set default verbose lvl (integer number)*/
(NOTHING::lvl|PMACC_VERBOSE_LVL);
/*create verbose class*/
DEFINE_VERBOSE_CLASS(PMaccVerbose)
(
/* define log lvl for later use
* e.g. log<pmaccLogLvl::NOTHING>("TEXT");*/
DEFINE_LOGLVL(0,NOTHING);
DEFINE_LOGLVL(1,MEMORY);
DEFINE_LOGLVL(2,INFO);
DEFINE_LOGLVL(4,CRITICAL);
DEFINE_LOGLVL(8,MPI);
DEFINE_LOGLVL(16,CUDA_RT);
DEFINE_LOGLVL(32,COMMUNICATION);
DEFINE_LOGLVL(64,EVENT);
)
/*set default verbose lvl (integer number)*/
(NOTHING::lvl|PMACC_VERBOSE_LVL);

//short name for access verbose types of PMacc
using ggLog = PMaccVerbose;

}

Expand Down
3 changes: 1 addition & 2 deletions include/pmacc/debug/VerboseLog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
#pragma once

#include "pmacc/debug/VerboseLogMakros.hpp"
#include "pmacc/types.hpp"

#include <boost/format.hpp>

#include <string>
#include <iostream>
#include <sstream>
#include <stdint.h>
#include <cstdint>

namespace pmacc
{
Expand Down
28 changes: 28 additions & 0 deletions include/pmacc/dimensions/Definition.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Copyright 2019 Rene Widera
*
* This file is part of PMacc.
*
* PMacc is free software: you can redistribute it and/or modify
* it under the terms of either the GNU General Public License or
* the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PMacc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with PMacc.
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once


//! Defines number of dimensions (1-3)
#define DIM1 1u
#define DIM2 2u
#define DIM3 3u
55 changes: 55 additions & 0 deletions include/pmacc/eventSystem/EventType.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* Copyright 2013-2019 Felix Schmitt, Heiko Burau, Rene Widera,
* Wolfgang Hoenig, Benjamin Worpitz,
* Alexander Grund
*
* This file is part of PMacc.
*
* PMacc is free software: you can redistribute it and/or modify
* it under the terms of either the GNU General Public License or
* the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PMacc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with PMacc.
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <cstdint>


namespace pmacc
{
namespace eventSystem
{

/**
* Internal event/task type used for notifications in the event system.
*/
enum EventType
{
FINISHED,
COPYHOST2DEVICE,
COPYDEVICE2HOST,
COPYDEVICE2DEVICE,
SENDFINISHED,
RECVFINISHED,
LOGICALAND,
SETVALUE,
GETVALUE,
KERNEL
};

} // namespace type

// for backward compatibility pull all definitions into the pmacc namespace
using namespace eventSystem;
} // namespace pmacc
Loading

0 comments on commit cbe4dbc

Please sign in to comment.