Skip to content

Commit

Permalink
Merge pull request #3924 from psychocoderHPC/topic-pmaccHeaderChecks
Browse files Browse the repository at this point in the history
PMacc: header include validation
  • Loading branch information
steindev authored Mar 6, 2023
2 parents 0d674eb + dd1627d commit c96fc6c
Show file tree
Hide file tree
Showing 80 changed files with 933 additions and 533 deletions.
353 changes: 18 additions & 335 deletions include/pmacc/Environment.hpp

Large diffs are not rendered by default.

406 changes: 406 additions & 0 deletions include/pmacc/Environment.tpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions include/pmacc/algorithms/TypeCast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#pragma once

#include "pmacc/attribute/FunctionSpecifier.hpp"

namespace pmacc
{
namespace algorithms
Expand Down
2 changes: 2 additions & 0 deletions include/pmacc/communication/AsyncCommunication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#pragma once

#include "pmacc/eventSystem/events/EventTask.hpp"

namespace pmacc
{
namespace communication
Expand Down
2 changes: 2 additions & 0 deletions include/pmacc/communication/manager_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <stdexcept>
#include <string>

#include <mpi.h>

const int GridManagerRank = 0;

enum
Expand Down
1 change: 1 addition & 0 deletions include/pmacc/dataManagement/DataConnector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#pragma once

#include "pmacc/Environment.def"
#include "pmacc/assert.hpp"
#include "pmacc/dataManagement/AbstractInitialiser.hpp"
#include "pmacc/dataManagement/ISimulationData.hpp"
Expand Down
3 changes: 3 additions & 0 deletions include/pmacc/device/MemoryInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
#pragma once


#include "pmacc/Environment.def"
#include "pmacc/types.hpp"

#include <pmacc/communication/manager_common.hpp>

#include <cstring> // memset

#include <mpi.h>
Expand Down
1 change: 1 addition & 0 deletions include/pmacc/eventSystem/events/EventPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#pragma once

#include "pmacc/Environment.def"
#include "pmacc/debug/VerboseLog.hpp"
#include "pmacc/eventSystem/events/CudaEvent.hpp"
#include "pmacc/eventSystem/events/CudaEventHandle.hpp"
Expand Down
155 changes: 4 additions & 151 deletions include/pmacc/eventSystem/events/kernelEvents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,84 +24,19 @@

#include "pmacc/Environment.hpp"
#include "pmacc/dimensions/DataSpace.hpp"
#include "pmacc/exec/KernelLauncher.hpp"
#include "pmacc/exec/KernelMetaData.hpp"
#include "pmacc/exec/KernelWithDynSharedMem.hpp"
#include "pmacc/traits/GetNComponents.hpp"
#include "pmacc/types.hpp"

#include <string>


/* No namespace in this file since we only declare macro defines */

/*if this flag is defined all kernel calls would be checked and synchronize
* this flag must set by the compiler or inside of the Makefile
*/
#if(PMACC_SYNC_KERNEL == 1)
# define CUDA_CHECK_KERNEL_MSG(...) CUDA_CHECK_MSG(__VA_ARGS__)
#else
/*no synchronize and check of kernel calls*/
# define CUDA_CHECK_KERNEL_MSG(...) ;
#endif


namespace pmacc::exec
{
namespace detail
{
/** Kernel with dynamic shared memory
*
* This implements the possibility to define dynamic shared memory without
* specializing the needed alpaka trait BlockSharedMemDynSizeBytes for each kernel with shared memory.
* The trait BlockSharedMemDynSizeBytes is defined by PMacc for all types of KernelWithDynSharedMem.
*/
template<typename T_Kernel>
struct KernelWithDynSharedMem : public T_Kernel
{
size_t const m_dynSharedMemBytes;

KernelWithDynSharedMem(T_Kernel const& kernel, size_t const& dynSharedMemBytes)
: T_Kernel(kernel)
, m_dynSharedMemBytes(dynSharedMemBytes)
{
}
};

//! Meta data of a device kernel
class KernelMetaData
{
//! file name
std::string const m_file;
//! line number
size_t const m_line;

public:
KernelMetaData(std::string const& file, size_t const line) : m_file(file), m_line(line)
{
}

//! file name from where the kernel is called
std::string getFile() const
{
return m_file;
}

//! line number in the file where the kernel is called
size_t getLine() const
{
return m_line;
}
};


/** Object to launch the kernel functor on the device.
*
* This objects contains the kernel functor, kernel meta information and the launch parameters.
* Object is used to enqueue the kernel with user arguments on the device.
*
* @tparam T_Kernel pmacc Kernel object
*/
template<typename T_Kernel>
struct KernelLauncher;

/** Wraps a user kernel functor to prepare the execution on the device.
*
* This objects contains the kernel functor, kernel meta information.
Expand Down Expand Up @@ -149,89 +84,6 @@ namespace pmacc::exec
size_t const sharedMemByte) const -> KernelLauncher<KernelWithDynSharedMem<T_KernelFunctor>>;
/**@}*/
};


template<typename T_Kernel>
struct KernelLauncher
{
//! kernel functor
T_Kernel const m_kernel;
//! Debug meta data for the kernel functor.
KernelMetaData const m_metaData;
//! grid extents for the kernel
cupla::dim3 const m_gridExtent;
//! block extents for the kernel
cupla::dim3 const m_blockExtent;

/** kernel starter object
*
* @param kernel pmacc Kernel
*/
template<typename T_VectorGrid, typename T_VectorBlock>
HINLINE KernelLauncher(
T_Kernel const& kernel,
detail::KernelMetaData const& kernelMetaData,
T_VectorGrid const& gridExtent,
T_VectorBlock const& blockExtent)
: m_kernel(kernel)
, m_metaData(kernelMetaData)
, m_gridExtent(DataSpace<traits::GetNComponents<T_VectorGrid>::value>(gridExtent).toDim3())
, m_blockExtent(DataSpace<traits::GetNComponents<T_VectorBlock>::value>(blockExtent).toDim3())
{
}

/** Enqueue the kernel functor with the given arguments for execution.
*
* The stream into which the kernel is enqueued is automatically chosen by PMacc's event system.
*
* @tparam T_Args types of the arguments
* @param args arguments for the kernel functor
*/
template<typename... T_Args>
HINLINE void operator()(T_Args&&... args) const
{
std::string const kernelName = typeid(m_kernel).name();
std::string const kernelInfo = kernelName + std::string(" [") + m_metaData.getFile() + std::string(":")
+ std::to_string(m_metaData.getLine()) + std::string(" ]");

CUDA_CHECK_KERNEL_MSG(cuplaDeviceSynchronize(), std::string("Crash before kernel call ") + kernelInfo);

pmacc::TaskKernel* taskKernel = pmacc::Environment<>::get().Factory().createTaskKernel(kernelName);

/* The next 3 lines cast pmacc vectors or integral values used for the execution extents into alpaka
* vectors.
* Note to be cupla compatible we use currently always 3-dimensional kernels.
*
* @todo find a better way to write this part of code, in general alpaka understands PMacc vectors but
* PMacc has no easy way t cast integral numbers to an 3-dimensional vector.
*/
auto gridExtent = cupla::IdxVec3(m_gridExtent.z, m_gridExtent.y, m_gridExtent.x);
auto blockExtent = cupla::IdxVec3(m_blockExtent.z, m_blockExtent.y, m_blockExtent.x);
auto elemExtent = cupla::IdxVec3::ones();
auto workDiv
= ::alpaka::WorkDivMembers<cupla::KernelDim, cupla::IdxType>(gridExtent, blockExtent, elemExtent);

auto const kernelTask
= ::alpaka::createTaskKernel<cupla::Acc>(workDiv, m_kernel, std::forward<T_Args>(args)...);

auto cuplaStream = taskKernel->getCudaStream();
auto& stream = cupla::manager::Stream<cupla::AccDev, cupla::AccStream>::get().stream(cuplaStream);

::alpaka::enqueue(stream, kernelTask);

CUDA_CHECK_KERNEL_MSG(
cuplaGetLastError(),
std::string("Last error after kernel launch ") + kernelInfo);
CUDA_CHECK_KERNEL_MSG(
cuplaDeviceSynchronize(),
std::string("Crash after kernel launch ") + kernelInfo);
taskKernel->activateChecks();
CUDA_CHECK_KERNEL_MSG(
cuplaDeviceSynchronize(),
std::string("Crash after kernel activation") + kernelInfo);
}
};

} // namespace detail

/** Creates a kernel object.
Expand Down Expand Up @@ -292,3 +144,4 @@ namespace alpaka


#include "pmacc/eventSystem/events/kernelEvents.tpp"
#include "pmacc/exec/KernelLauncher.tpp"
2 changes: 2 additions & 0 deletions include/pmacc/eventSystem/tasks/Factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#pragma once

#include "pmacc/Environment.def"
#include "pmacc/eventSystem/events/EventTask.hpp"
#include "pmacc/eventSystem/streams/EventStream.hpp"
#include "pmacc/eventSystem/tasks/ITask.hpp"
#include "pmacc/eventSystem/tasks/TaskKernel.hpp"
Expand Down
1 change: 1 addition & 0 deletions include/pmacc/eventSystem/tasks/TaskReceive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#pragma once

#include "pmacc/Environment.hpp"
#include "pmacc/eventSystem/Manager.hpp"
#include "pmacc/eventSystem/events/EventDataReceive.hpp"
#include "pmacc/eventSystem/tasks/MPITask.hpp"

Expand Down
3 changes: 1 addition & 2 deletions include/pmacc/eventSystem/tasks/TaskReceiveMPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "pmacc/communication/ICommunicator.hpp"
#include "pmacc/eventSystem/events/EventDataReceive.hpp"
#include "pmacc/eventSystem/tasks/MPITask.hpp"
#include "pmacc/memory/buffers/Buffer.hpp"

#include <memory>

Expand All @@ -47,7 +46,7 @@ namespace pmacc

void init() override
{
Buffer<TYPE, DIM>* dst = exchange->getCommunicationBuffer();
auto* dst = exchange->getCommunicationBuffer();

this->request = Environment<DIM>::get().EnvironmentController().getCommunicator().startReceive(
exchange->getExchangeType(),
Expand Down
3 changes: 1 addition & 2 deletions include/pmacc/eventSystem/tasks/TaskSendMPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "pmacc/Environment.hpp"
#include "pmacc/communication/ICommunicator.hpp"
#include "pmacc/eventSystem/tasks/MPITask.hpp"
#include "pmacc/memory/buffers/Buffer.hpp"

#include <mpi.h>

Expand All @@ -44,7 +43,7 @@ namespace pmacc

void init() override
{
Buffer<TYPE, DIM>* src = exchange->getCommunicationBuffer();
auto* src = exchange->getCommunicationBuffer();

this->request = Environment<DIM>::get().EnvironmentController().getCommunicator().startSend(
exchange->getExchangeType(),
Expand Down
2 changes: 1 addition & 1 deletion include/pmacc/eventSystem/tasks/TaskSetValue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "pmacc/dimensions/DataSpace.hpp"
#include "pmacc/eventSystem/tasks/StreamTask.hpp"
#include "pmacc/lockstep.hpp"
#include "pmacc/lockstep/lockstep.hpp"
#include "pmacc/lockstep/WorkerCfg.hpp"
#include "pmacc/mappings/simulation/EnvironmentController.hpp"
#include "pmacc/memory/boxes/DataBox.hpp"
#include "pmacc/memory/buffers/DeviceBuffer.hpp"
Expand Down
36 changes: 36 additions & 0 deletions include/pmacc/exec/KernelLauncher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright 2022 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


namespace pmacc::exec::detail
{
/** Object to launch the kernel functor on the device.
*
* This objects contains the kernel functor, kernel meta information and the launch parameters.
* Object is used to enqueue the kernel with user arguments on the device.
*
* @tparam T_Kernel pmacc Kernel object
*/
template<typename T_Kernel>
struct KernelLauncher;
} // namespace pmacc::exec::detail
Loading

0 comments on commit c96fc6c

Please sign in to comment.