// Copyright (c) 2012-2017 VideoStitch SAS // Copyright (c) 2018 stitchEm #include "deviceHostBuffer.hpp" #include "deviceStream.hpp" #include "../common/allocStats.hpp" #include "gpu/stream.hpp" #include namespace VideoStitch { namespace GPU { // There is no pimpl in the CUDA implementation, so there is no ::get() // template // const DeviceHostBuffer& HostBuffer::get(); template PotentialValue> HostBuffer::allocate(size_t numElements, const char* name, unsigned int flags) { unsigned int cudaFlags = cudaHostAllocDefault; if (flags & GPUHostAllocPinned) { cudaFlags |= cudaHostAllocPortable; } if (flags & GPUHostAllocHostWriteOnly) { cudaFlags |= cudaHostAllocWriteCombined; } T* buf = nullptr; size_t byteSize = numElements * sizeof(T); if (CUDA_ERROR(cudaHostAlloc((void**)&buf, byteSize, cudaFlags)).ok()) { if (buf) { hostStats.addPtr(name, (void*)buf, byteSize); return PotentialValue>(HostBuffer(nullptr, buf, numElements)); } } return PotentialValue>( {Origin::GPU, ErrType::OutOfResources, "Failed to allocate " + std::to_string(numElements * sizeof(T)) + " Bytes of host memory. Reduce the project output size and close other applications to free up RAM."}); } template Status HostBuffer::release() { if (hostData) { hostStats.deletePtr((void*)hostData); return CUDA_ERROR(cudaFreeHost((void*)hostData)); } return Status::OK(); } template std::size_t HostBuffer::getPoolSize() { return hostStats.bytesUsed(); } template std::vector HostBuffer::getPoolSizeByDevices() { return hostStats.bytesUsedByDevices(); } template class HostBuffer; template class HostBuffer; template class HostBuffer; template class HostBuffer; template class HostBuffer; template class HostBuffer; } // namespace GPU } // namespace VideoStitch