Esempio n. 1
0
    /**
     * destructor
     */
    virtual ~MappedBufferIntern()
    {
        __startOperation(ITask::TASK_CUDA);
        __startOperation(ITask::TASK_HOST);

        if (pointer && ownPointer)
        {
#if( PMACC_CUDA_ENABLED == 1 )
/* cupla 0.1.0 does not support the function cudaHostAlloc to create mapped memory.
 * Therefore we need to call the native CUDA function cudaFreeHost to free memory.
 * Due to the renaming of cuda functions with cupla via macros we need to remove
 * the renaming to get access to the native cuda function.
 * @todo this is a workaround please fix me. We need to investigate if
 * it is possible to have mapped/unified memory in alpaka.
 *
 * corresponding alpaka issues:
 *   https://github.com/ComputationalRadiationPhysics/alpaka/issues/296
 *   https://github.com/ComputationalRadiationPhysics/alpaka/issues/612
 */
#   undef cudaFreeHost
            CUDA_CHECK((cuplaError_t)cudaFreeHost(pointer));
// re-introduce the cupla macro
#   define cudaFreeHost(...) cuplaFreeHost(__VA_ARGS__)
#else
            __deleteArray(pointer);
#endif
        }
    }
Esempio n. 2
0
 void reset(bool preserveData = true)
 {
     __startOperation(ITask::TASK_HOST);
     this->setCurrentSize(this->getDataSpace().productOfComponents());
     if (!preserveData)
         memset(pointer, 0, this->getDataSpace().productOfComponents() * sizeof (TYPE));
 }
Esempio n. 3
0
 void reset(bool preserveData = true)
 {
     __startOperation(ITask::TASK_HOST);
     setCurrentSize(this->getDataSpace().getElementCount());
     if (!preserveData)
         memset(pointer, 0, this->getDataSpace().getElementCount() * sizeof (TYPE));
 }
Esempio n. 4
0
 DataBoxType getDataBox()
 {
     __startOperation(ITask::TASK_CUDA);
     TYPE* dPointer;
     cudaHostGetDevicePointer(&dPointer, pointer, 0);
     return DataBoxType(PitchedBox<TYPE, DIM > (dPointer, DataSpace<DIM > (),
                                                this->data_space, this->data_space[0] * sizeof (TYPE)));
 }
Esempio n. 5
0
 void setValue(const TYPE& value)
 {
     __startOperation(ITask::TASK_HOST);
     size_t current_size = this->getCurrentSize();
     for (size_t i = 0; i < current_size; i++)
     {
         pointer[i] = value;
     }
 }
Esempio n. 6
0
    const cudaPitchedPtr getCudaPitched() const
    {
        __startOperation(ITask::TASK_CUDA);
        TYPE* dPointer;
        cudaHostGetDevicePointer(&dPointer, pointer, 0);

        /* on 1D memory we have no size for y, therefore we set y to 1 to
         * get a valid cudaPitchedPtr
         */
        int size_y=1;
        if(DIM>DIM1)
            size_y= this->data_space[1];

        return make_cudaPitchedPtr(dPointer,
                                   this->data_space.x() * sizeof (TYPE),
                                   this->data_space.x(),
                                   size_y
                                   );
    }
Esempio n. 7
0
 /**
  * Returns the current size pointer.
  *
  * @return pointer to current size
  */
 virtual size_t* getCurrentSizePointer()
 {
     __startOperation(ITask::TASK_HOST);
     return this->current_size;
 }
Esempio n. 8
0
 /*! sets the current size (count of elements)
  * @param newsize new current size
  */
 virtual void setCurrentSize(const size_t newsize)
 {
     __startOperation(ITask::TASK_HOST);
     assert(static_cast<size_t>(newsize) <= static_cast<size_t>(data_space.productOfComponents()));
     *current_size = newsize;
 }
Esempio n. 9
0
 /*! returns the current size (count of elements)
  * @return current size
  */
 virtual size_t getCurrentSize()
 {
     __startOperation(ITask::TASK_HOST);
     return *current_size;
 }
Esempio n. 10
0
 DataBoxType getHostDataBox()
 {
     __startOperation(ITask::TASK_HOST);
     return DataBoxType(PitchedBox<TYPE, DIM > (pointer, DataSpace<DIM > (),
                                                this->data_space, this->data_space[0] * sizeof (TYPE)));
 }
Esempio n. 11
0
 /*! Get device pointer of memory
  *
  * This pointer is shifted by the offset, if this buffer points to other
  * existing buffer
  *
  * @return device pointer to memory
  */
 TYPE* getPointer()
 {
     __startOperation(ITask::TASK_HOST);
     return (TYPE*) this->getCudaPitched().ptr;
 }
Esempio n. 12
0
 TYPE* getPointer()
 {
     __startOperation(ITask::TASK_HOST);
     return pointer;
 }
Esempio n. 13
0
 /*! sets the current size (count of elements)
  * @param newsize new current size
  */
 virtual void setCurrentSize(size_t newsize)
 {
     __startOperation(ITask::TASK_HOST); 
     assert(static_cast<size_t>(newsize) <= static_cast<size_t>(data_space.getElementCount()));
     *current_size = newsize;
 }