예제 #1
0
CUDARunner::~CUDARunner()
{
	DeallocateResources();

	cuModuleUnload(m_module);
	cuCtxDestroy(m_context);
}
예제 #2
0
const bool CUDARunner::AllocateResources(const int numb, const int numt)
{
	bool allocated=true;
	CUresult rval;
	DeallocateResources();

	m_in=(cuda_in *)malloc(sizeof(cuda_in));
	m_out=(cuda_out *)malloc(numb*numt*sizeof(cuda_out));

	rval=cuMemAlloc(&m_devin,sizeof(cuda_in));
	if(rval!=CUDA_SUCCESS)
	{
		printf("Error %d allocating CUDA memory\n",rval);
		m_devin=0;
		allocated=false;
	}
	rval=cuMemAlloc(&m_devout,numb*numt*sizeof(cuda_out));
	if(rval!=CUDA_SUCCESS)
	{
		printf("Error %d allocating CUDA memory\n",rval);
		m_devout=0;
		allocated=false;
	}

	printf("Done allocating CUDA resources for (%d,%d)\n",numb,numt);
	return allocated;
}
예제 #3
0
void CUDARunner::AllocateResources(const int numb, const int numt)
{
	DeallocateResources();

	m_in=(cuda_in *)malloc(sizeof(cuda_in));
	m_out=(cuda_out *)malloc(numb*numt*sizeof(cuda_out));

	cutilSafeCall(cudaMalloc((void **)&m_devin,sizeof(cuda_in)));
	cutilSafeCall(cudaMalloc((void **)&m_devout,numb*numt*sizeof(cuda_out)));

	printf("Done allocating CUDA resources for (%d,%d)\n",numb,numt);
}
예제 #4
0
void RemoteCUDARunner::AllocateResources(const int numb, const int numt)
{
	DeallocateResources();

	m_in=(remote_cuda_in *)malloc(sizeof(remote_cuda_in));
	m_out=(remote_cuda_out *)malloc(numb*numt*sizeof(remote_cuda_out));
	m_metahash=(unsigned char *)malloc(numb*numt*GetStepIterations());

	cutilSafeCall(cudaMalloc((void **)&m_devin,sizeof(remote_cuda_in)));
	cutilSafeCall(cudaMalloc((void **)&m_devout,numb*numt*sizeof(remote_cuda_out)));
	cutilSafeCall(cudaMalloc((void **)&m_devmetahash,numb*numt*GetStepIterations()));

	std::cout << "Done allocating CUDA resources for (" << numb << "," << numt << ")" << std::endl;
}
예제 #5
0
파일: memBuffer.cpp 프로젝트: yanma/tnvme
void
MemBuffer::InitOffset1stPage(uint32_t bufSize, uint32_t offset1stPg,
                             bool initMem, uint8_t initVal)
{
    int err;
    uint32_t realBufSize;
    uint32_t align = sysconf(_SC_PAGESIZE);


    LOG_NRM(
        "Init buffer; size: 0x%08X, offset: 0x%08X, init: %d, value: 0x%02X",
        bufSize, offset1stPg, initMem, initVal);
    if (offset1stPg % sizeof(uint32_t) != 0) {
        throw FrmwkEx(HERE, "Offset into page 1 not aligned to: 0x%02lX",
                      sizeof(uint32_t));
    }

    // Support resizing/reallocation
    if (mRealBaseAddr != NULL)
        DeallocateResources();
    mAllocByNewOperator = false;  // using posix_memalign()

    // All memory is allocated page aligned, offsets into the 1st page requires
    // asking for more memory than the caller desires and then tracking the
    // virtual pointer into the real allocation as a side affect.
    mVirBufSize = bufSize;
    realBufSize = (bufSize + offset1stPg);
    err = posix_memalign((void **)&mRealBaseAddr, align, realBufSize);
    if (err) {
        InitMemberVariables();
        throw FrmwkEx(HERE, "Memory allocation failed with error code: 0x%02X",
                      err);
    }
    mVirBaseAddr = (mRealBaseAddr + offset1stPg);
    if (offset1stPg)
        mAlignment = offset1stPg;
    else
        mAlignment = align;

    if (initMem)
        memset(mVirBaseAddr, initVal, mVirBufSize);
}
예제 #6
0
파일: memBuffer.cpp 프로젝트: yanma/tnvme
void
MemBuffer::InitAlignment(uint32_t bufSize, uint32_t align, bool initMem,
                         uint8_t initVal, volatile uint8_t *srcBuffer)
{
    int err;

    LOG_NRM("Init buffer; size: 0x%08X, align: 0x%08X, init: %d, value: 0x%02X",
            bufSize, align, initMem, initVal);
    if (align % sizeof(void *) != 0) {
        throw FrmwkEx(HERE, "Req'd alignment 0x%08X, is not modulo 0x%02lX",
                      align, sizeof(void *));
    }

    // Support resizing/reallocation
    if (mRealBaseAddr != NULL)
        DeallocateResources();
    mAllocByNewOperator = false;  // using posix_memalign()

    mVirBufSize = bufSize;
    err = posix_memalign((void **)&mRealBaseAddr, align, mVirBufSize);
    if (err) {
        InitMemberVariables();
        throw FrmwkEx(HERE, "Memory allocation failed with error code: 0x%02X",
                      err);
    }
    mVirBaseAddr = mRealBaseAddr;
    mAlignment = align;

    if (srcBuffer != NULL) {
        //memcpy(mVirBaseAddr, buffer, bufSize );
        for(uint32_t dataIndex = 0; dataIndex < bufSize; dataIndex++) {
            mVirBaseAddr[dataIndex] = (volatile uint8_t) srcBuffer[dataIndex];
        }
    }
    else if (initMem) {
        memset(mVirBaseAddr, initVal, mVirBufSize);
    }
}
예제 #7
0
파일: memBuffer.cpp 프로젝트: yanma/tnvme
void
MemBuffer::Init(uint32_t bufSize, bool initMem, uint8_t initVal)
{
    LOG_NRM("Init buffer; size: 0x%08X, init: %d, value: 0x%02X",
            bufSize, initMem, initVal);

    // Support resizing/reallocation
    if (mRealBaseAddr != NULL)
        DeallocateResources();
    mAllocByNewOperator = true;

    mVirBufSize = bufSize;
    mRealBaseAddr = new (nothrow) uint8_t[mVirBufSize];
    if (mRealBaseAddr == NULL) {
        InitMemberVariables();
        throw FrmwkEx(HERE, "Memory allocation failed");
    }
    mVirBaseAddr = mRealBaseAddr;
    mAlignment = 0;

    if (initMem)
        memset(mVirBaseAddr, initVal, mVirBufSize);
}
예제 #8
0
RemoteCUDARunner::~RemoteCUDARunner()
{
	DeallocateResources();
	cutilSafeCall(cudaThreadExit());
}
예제 #9
0
파일: Texture.cpp 프로젝트: pboechat/FastCG
Texture::~Texture()
{
	DeallocateResources();
}
예제 #10
0
파일: memBuffer.cpp 프로젝트: yanma/tnvme
MemBuffer::~MemBuffer()
{
    DeallocateResources();
}