Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unconditional usage of getAvailableSlotsHost #89

Merged
merged 1 commit into from
Jul 7, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 43 additions & 20 deletions src/include/mallocMC/mallocMC_hostclass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,42 @@ namespace mallocMC{
size_t size;
};

namespace detail{

/**
* @brief Template class to call getAvailableSlots[Host|Accelerator] if the CreationPolicy provides it.
*
* Returns 0 else.
*
* @tparam T_CreationPolicy The desired type of a CreationPolicy
* @tparam T_ProvidesAvailableSlotsHost If the CreationPolicy provides getAvailableSlotsHost
*/
template<typename T_ProvidesAvailableSlotsHost>
struct GetAvailableSlotsIfAvail
{
template<typename T_Allocator>
MAMC_HOST MAMC_ACCELERATOR
static unsigned getAvailableSlots(size_t slotSize, T_Allocator &){
return 0;
}
};
template<>
struct GetAvailableSlotsIfAvail<
boost::mpl::bool_<true> >
{
template<typename T_Allocator>
MAMC_HOST MAMC_ACCELERATOR
static unsigned getAvailableSlots(size_t slotSize, T_Allocator & alloc){
#ifdef __CUDA_ARCH__
return alloc.getAvailableSlotsAccelerator(slotSize);
#else
return alloc.getAvailableSlotsHost(slotSize, alloc);
#endif
}
};

}

/**
* @brief "HostClass" that combines all policies to a useful allocator
*
Expand Down Expand Up @@ -144,15 +180,15 @@ namespace mallocMC{
/*
* This is a workaround for a bug with getAvailSlotsPoly:
* Due to some problems with conditional compilation (possibly a CUDA bug),
* this host function must explicitly be used from inside a host
* getAvailableSlotsHost must explicitly be used from inside a host
* function at least once. Doing it here guarantees that it is executed
* and that this execution happens on the host. Usually, simply defining
* this inside a host function (without actually executing it) would be
* sufficient. However, due to the template nature of policy based
* design, functions are only compiled if they are actually used.
*/
if(CreationPolicy::providesAvailableSlots::value)
CreationPolicy::getAvailableSlotsHost(1024,*this); //actual slot size does not matter
detail::GetAvailableSlotsIfAvail<boost::mpl::bool_<CreationPolicy::providesAvailableSlots::value> >
::getAvailableSlots(1024, *this); //actual slot size does not matter

return h;
}
Expand All @@ -178,7 +214,10 @@ namespace mallocMC{
// polymorphism over the availability of getAvailableSlots
MAMC_HOST MAMC_ACCELERATOR
unsigned getAvailableSlots(size_t slotSize){
return getAvailSlotsPoly(slotSize, boost::mpl::bool_<CreationPolicy::providesAvailableSlots::value>());
slotSize = AlignmentPolicy::applyPadding(slotSize);

return detail::GetAvailableSlotsIfAvail<boost::mpl::bool_<CreationPolicy::providesAvailableSlots::value> >
::getAvailableSlots(slotSize, *this);
}

MAMC_HOST
Expand All @@ -188,22 +227,6 @@ namespace mallocMC{
return v;
}

private:
MAMC_HOST MAMC_ACCELERATOR
unsigned getAvailSlotsPoly(size_t slotSize, boost::mpl::bool_<false>){
return 0;
}

MAMC_HOST MAMC_ACCELERATOR
unsigned getAvailSlotsPoly(size_t slotSize, boost::mpl::bool_<true>){
slotSize = AlignmentPolicy::applyPadding(slotSize);
#ifdef __CUDA_ARCH__
return CreationPolicy::getAvailableSlotsAccelerator(slotSize);
#else
return CreationPolicy::getAvailableSlotsHost(slotSize,*this);
#endif
}

};

} //namespace mallocMC