Skip to content

Commit

Permalink
Merge pull request #102 from ComputationalRadiationPhysics/dev
Browse files Browse the repository at this point in the history
Release 2.2.0crp
  • Loading branch information
ax3l committed Sep 25, 2015
2 parents 799d7d7 + ef29c73 commit 80bf2b0
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 64 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ env:

script:
- mkdir build_tmp && cd build_tmp
- cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR $TRAVIS_BUILD_DIR
- CXXFLAGS="-Werror" cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR $TRAVIS_BUILD_DIR
- make
- make install
- make examples

before_script:
- sudo add-apt-repository --yes ppa:smspillaz/cmake-2.8.12
- sudo apt-get update -qq
- sudo apt-get install -q -y cmake-data cmake
- sudo apt-get install -qq build-essential
- sudo apt-get install -qq gcc-4.4 g++-4.4
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.4
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
Change Log / Release Log for mallocMC
================================================================

2.2.0crp
-------------
**Date:** 2015-09-25

This release fixes some minor bugs that occured after the release of 2.1.0crp, adds some documentation and improves the interoperability with other projects and build systems.
We closed all issues documented in
[Milestone *2.2.0crp: Stabilizing the release*](https://github.com/ComputationalRadiationPhysics/mallocMC/issues?milestone=5&state=closed)

### Changes to mallocMC 2.1.0crp

**Features**
- the interface now provides the host function `HeapInfoVector getHeapLocations()` to obtain information about the location and size of existing mallocMC-heaps #86

**Bug fixes**
- the function `getAvailableSlots` was always required in the policy classes, although the implementations might not provide it #89

**Misc:**
- the code relied on `__TROW` being defined, which is not available in all compilers #91
- the CMake dependency increased to CMake >= 2.8.12.2 #92
- a new FindmallocMC.cmake module file is provided at https://github.com/ComputationalRadiationPhysics/cmake-modules #85
- See the full changes at https://github.com/ComputationalRadiationPhysics/mallocMC/compare/2.1.0crp...2.2.0crp


2.1.0crp
-------------
**Date:** 2015-02-11
Expand Down
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project(mallocMC)
cmake_minimum_required(VERSION 2.8.5)
cmake_minimum_required(VERSION 2.8.12.2)

# helper for libs and packages
set(CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/"
Expand Down Expand Up @@ -46,18 +46,20 @@ endif(Boost_VERSION EQUAL 105500)
# GNU
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
# new warning in gcc 4.8 (flag ignored in previous version)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs")
# ICC
# ICC
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_NO_VARIADIC_TEMPLATES")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_NO_CXX11_VARIADIC_TEMPLATES")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_NO_FENV_H")
# PGI
# PGI
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Minform=inform")
endif()
Expand Down
10 changes: 5 additions & 5 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Install
- *Debian/Ubuntu:* `sudo apt-get install libboost-dev libboost-program-options-dev`
- *Arch Linux:* `sudo pacman -S boost`
- or download from [http://www.boost.org/](http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz/download)
- `CMake` >= 2.8.5
- `CMake` >= 2.8.12.2
- *Debian/Ubuntu:* `sudo apt-get install cmake file cmake-curses-gui`
- *Arch Linux:* `sudo pacman -S cmake`
- `git` >= 1.7.9.5
Expand Down Expand Up @@ -58,17 +58,17 @@ Because we are linking to Boost and CUDA, the following **external dependencies*

If you are using CMake you can download our `FindmallocMC.cmake` module with
```bash
wget https://raw.githubusercontent.com/ComputationalRadiationPhysics/picongpu/dev/src/cmake/FindmallocMC.cmake
wget https://raw.githubusercontent.com/ComputationalRadiationPhysics/cmake-modules/dev/FindmallocMC.cmake
# read the documentation
cmake -DCMAKE_MODULE_PATH=. --help-module FindmallocMC | less
```

and use the following lines in your `CMakeLists.txt`:
```cmake
# this example will require at least CMake 2.8.5
cmake_minimum_required(VERSION 2.8.5)
# this example will require at least CMake 2.8.12.2
cmake_minimum_required(VERSION 2.8.12.2)
# add path to FindmallocMC.cmake, e.g. in the directory in cmake/
# add path to FindmallocMC.cmake, e.g., in the directory in cmake/
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/)
# find the packages that are required by mallocMC. This has to be done BEFORE
Expand Down
2 changes: 2 additions & 0 deletions src/include/mallocMC/alignmentPolicies/Shrink_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ namespace Shrink2NS{
#endif
static const uint32 dataAlignment = MALLOCMC_AP_SHRINK_DATAALIGNMENT;

// \TODO: The static_cast can be removed once the minimal dependencies of
// this project is are at least CUDA 7.0 and gcc 4.8.2
BOOST_STATIC_ASSERT(static_cast<uint32>(dataAlignment) > 0);
//dataAlignment must also be a power of 2!
BOOST_STATIC_ASSERT(dataAlignment && !(dataAlignment & (dataAlignment-1)) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ namespace DistributionPolicies{

//all the properties must be unsigned integers > 0
BOOST_STATIC_ASSERT(!std::numeric_limits<typename Properties::pagesize::type>::is_signed);

// \TODO: The static_cast can be removed once the minimal dependencies of
// this project is are at least CUDA 7.0 and gcc 4.8.2
BOOST_STATIC_ASSERT(static_cast<uint32>(pagesize) > 0);

public:
Expand Down
75 changes: 58 additions & 17 deletions src/include/mallocMC/mallocMC_hostclass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <cassert>

#include <boost/mpl/assert.hpp>
#include <vector>

namespace mallocMC{

Expand All @@ -57,6 +58,47 @@ namespace mallocMC{
static const bool providesAvailableSlots = T::CreationPolicy::providesAvailableSlots::value;
};

class HeapInfo{
public:
void* p;
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 @@ -93,9 +135,12 @@ namespace mallocMC{
typedef T_ReservePoolPolicy ReservePoolPolicy;
typedef T_AlignmentPolicy AlignmentPolicy;

typedef std::vector<HeapInfo> HeapInfoVector;

private:
typedef boost::uint32_t uint32;
void* pool;
HeapInfo heapInfos;

public:

Expand Down Expand Up @@ -129,19 +174,21 @@ namespace mallocMC{
pool = ReservePoolPolicy::setMemPool(size);
boost::tie(pool,size) = AlignmentPolicy::alignPool(pool,size);
void* h = CreationPolicy::initHeap(*this,pool,size);
heapInfos.p=pool;
heapInfos.size=size;

/*
* 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 @@ -167,23 +214,17 @@ 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);

private:
MAMC_HOST MAMC_ACCELERATOR
unsigned getAvailSlotsPoly(size_t slotSize, boost::mpl::bool_<false>){
return 0;
return detail::GetAvailableSlotsIfAvail<boost::mpl::bool_<CreationPolicy::providesAvailableSlots::value> >
::getAvailableSlots(slotSize, *this);
}

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
MAMC_HOST
HeapInfoVector getHeapLocations(){
HeapInfoVector v;
v.push_back(heapInfos);
return v;
}

};
Expand Down
22 changes: 22 additions & 0 deletions src/include/mallocMC/mallocMC_overwrites.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#pragma once

#include "mallocMC_prefixes.hpp"
#include <vector>

/** Creates a global object of a many core memory allocator
*
Expand Down Expand Up @@ -82,6 +83,12 @@ bool providesAvailableSlots(){ \
} /* end namespace mallocMC */


/** __THROW is defined in Glibc so it is not available on all platforms.
*/
#ifndef __THROW
#define __THROW
#endif

/** Create the functions malloc() and free() inside a namespace
*
* This allows for a peaceful coexistence between different functions called
Expand All @@ -103,6 +110,20 @@ void free(void* p) __THROW \
} /* end namespace mallocMC */


/** Create the function getHeapLocations inside a namespace
*
* This returns a vector of type mallocMC::HeapInfo. The HeapInfo should at least
* contain the pointer to the heap (on device) and its size.
*/
#define MALLOCMC_HEAPLOC() \
namespace mallocMC{ \
MAMC_HOST \
std::vector<mallocMC::HeapInfo> getHeapLocations() \
{ \
return mallocMC::mallocMCGlobalObject.getHeapLocations(); \
} \
} /* end namespace mallocMC */


/* if the defines do not exist (wrong CUDA version etc),
* create at least empty defines
Expand All @@ -121,4 +142,5 @@ void free(void* p) __THROW \
#define MALLOCMC_SET_ALLOCATOR_TYPE(MALLOCMC_USER_DEFINED_TYPE) \
MALLOCMC_GLOBAL_FUNCTIONS(MALLOCMC_USER_DEFINED_TYPE) \
MALLOCMC_MALLOC() \
MALLOCMC_HEAPLOC() \
MALLOCMC_AVAILABLESLOTS()
Loading

0 comments on commit 80bf2b0

Please sign in to comment.