Skip to content
Snippets Groups Projects
Commit 6495a79a authored by Michael Kuron's avatar Michael Kuron :mortar_board:
Browse files

Replace deprecated CUDA API calls

parent ddc0a76e
Branches
1 merge request!157Resolve "Replace deprecated CUDA APIs"
Pipeline #13260 passed with stages
in 4 hours, 38 minutes, and 10 seconds
...@@ -107,9 +107,6 @@ namespace cuda { ...@@ -107,9 +107,6 @@ namespace cuda {
protected: protected:
template<typename T> size_t determineNextOffset();
//** Members ********************************************************************************************** //** Members **********************************************************************************************
/*! \name Members */ /*! \name Members */
//@{ //@{
...@@ -120,11 +117,7 @@ namespace cuda { ...@@ -120,11 +117,7 @@ namespace cuda {
dim3 blockDim_; dim3 blockDim_;
std::size_t sharedMemSize_; std::size_t sharedMemSize_;
struct ParamInfo { std::vector< std::vector<char> > params_;
std::vector<char> data;
size_t offset;
};
std::vector< ParamInfo > params_;
//@} //@}
//**************************************************************************************************************** //****************************************************************************************************************
...@@ -187,10 +180,9 @@ namespace cuda { ...@@ -187,10 +180,9 @@ namespace cuda {
template<typename T> template<typename T>
void Kernel<FP>::addParam( const T & param ) void Kernel<FP>::addParam( const T & param )
{ {
ParamInfo paramInfo; std::vector<char> paramInfo;
paramInfo.data.resize( sizeof(T) ); paramInfo.resize( sizeof(T) );
std::memcpy ( &(paramInfo.data[0]), &param, sizeof(T) ); std::memcpy ( paramInfo.data(), &param, sizeof(T) );
paramInfo.offset = determineNextOffset<T>();
WALBERLA_ASSERT( checkParameter<T>( params_.size() +1 ), WALBERLA_ASSERT( checkParameter<T>( params_.size() +1 ),
"cuda::Kernel type mismatch of parameter " << params_.size() +1 ); "cuda::Kernel type mismatch of parameter " << params_.size() +1 );
...@@ -231,28 +223,21 @@ namespace cuda { ...@@ -231,28 +223,21 @@ namespace cuda {
void Kernel<FP>::operator() ( cudaStream_t stream ) const void Kernel<FP>::operator() ( cudaStream_t stream ) const
{ {
// check for correct number of parameter calls // check for correct number of parameter calls
if ( params_.size() != boost::function_traits<FuncType>::arity ) { if ( params_.size() != boost::function_traits<FuncType>::arity ) {
WALBERLA_ABORT( "Error when calling cuda::Kernel - Wrong number of arguments. " << WALBERLA_ABORT( "Error when calling cuda::Kernel - Wrong number of arguments. " <<
"Expected " << boost::function_traits<FuncType>::arity << ", received " << params_.size() ); "Expected " << boost::function_traits<FuncType>::arity << ", received " << params_.size() );
} }
// set the number of blocks and threads,
WALBERLA_CUDA_CHECK( cudaConfigureCall( gridDim_, blockDim_, sharedMemSize_, stream ) );
// register all parameters // register all parameters
std::vector<void*> args;
for( auto paramIt = params_.begin(); paramIt != params_.end(); ++paramIt ) { for( auto paramIt = params_.begin(); paramIt != params_.end(); ++paramIt ) {
const void * ptr = &(paramIt->data[0]); args.push_back( const_cast<char*>(paramIt->data()) );
WALBERLA_CUDA_CHECK( cudaSetupArgument( ptr, paramIt->data.size(), paramIt->offset ) );
} }
// .. and launch the kernel // .. and launch the kernel
static_assert( sizeof(void *) == sizeof(void (*)(void)), static_assert( sizeof(void *) == sizeof(void (*)(void)),
"object pointer and function pointer sizes must be equal" ); "object pointer and function pointer sizes must be equal" );
// dirty casting trick to circumvent compiler warning WALBERLA_CUDA_CHECK( cudaLaunchKernel( (void*) funcPtr_, gridDim_, blockDim_, args.data(), sharedMemSize_, stream ) );
// essentially the next two lines are: cudaLaunch( funcPtr_ );
void *q = (void*) &funcPtr_;
WALBERLA_CUDA_CHECK( cudaLaunch( (const char*) ( *static_cast<void **>(q) )) );
} }
...@@ -276,19 +261,6 @@ namespace cuda { ...@@ -276,19 +261,6 @@ namespace cuda {
} }
template<typename FP>
template<typename T>
size_t Kernel<FP>::determineNextOffset()
{
size_t currentOffset = 0;
if ( !params_.empty() )
currentOffset = params_.back().offset + params_.back().data.size();
size_t alignment = __alignof( T );
return (currentOffset + alignment-1) & ~(alignment-1);
}
} // namespace cuda } // namespace cuda
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment