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

allocating page-aligned memory #210

Merged
merged 1 commit into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define XMIPP_LIBRARIES_DATA_RECONSTRUCT_FOURIER_BUFFER_DATA_H_

#include "reconstruct_fourier_projection_traverse_space.h"
#include "core/utils/memory_utils.h"

/**
* Struct holding data for calculating Fourier Reconstruction
Expand All @@ -51,31 +52,31 @@ struct RecFourierBufferData
hasFFTs(hasFFTs), hasCTFs(hasCTFs),
fftSizeX(fftSizeX), fftSizeY(fftSizeY), paddedImgSize(paddedImgSize),
maxNoOfImages(maxNoOfImages),noOfSymmetries(noOfSymmetries), noOfImages(0) {
spaces = new RecFourierProjectionTraverseSpace[maxNoOfImages * noOfSymmetries];
spaces = memoryUtils::page_aligned_alloc<RecFourierProjectionTraverseSpace>(maxNoOfImages * noOfSymmetries, false);
if (hasFFTs) {
paddedImages = NULL;
FFTs = new float[fftSizeX * fftSizeY * maxNoOfImages * 2](); // *2 since it's complex
paddedImages = nullptr;
FFTs = memoryUtils::page_aligned_alloc<float>(fftSizeX * fftSizeY * maxNoOfImages * 2, true); // *2 since it's complex
} else {
FFTs = NULL;
paddedImages = new float[paddedImgSize * paddedImgSize * maxNoOfImages]();
FFTs = nullptr;
paddedImages = memoryUtils::page_aligned_alloc<float>(paddedImgSize * paddedImgSize * maxNoOfImages, true);
}

if (hasCTFs) {
CTFs = new float[fftSizeX * fftSizeY * maxNoOfImages]();
modulators = new float[fftSizeX * fftSizeY * maxNoOfImages]();
CTFs = memoryUtils::page_aligned_alloc<float>(fftSizeX * fftSizeY * maxNoOfImages, true);
modulators = memoryUtils::page_aligned_alloc<float>(fftSizeX * fftSizeY * maxNoOfImages, true);
} else {
CTFs = modulators = NULL;
CTFs = modulators = nullptr;
}
};

~RecFourierBufferData() {
delete[] FFTs;
delete[] CTFs;
delete[] paddedImages;
delete[] modulators;
FFTs = CTFs = paddedImages = modulators = NULL;
free(FFTs);
free(CTFs);
free(paddedImages);
free(modulators);
FFTs = CTFs = paddedImages = modulators = nullptr;

delete[] spaces;
free(spaces);
spaces = NULL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ void* ProgRecFourierGPU::threadRoutine(void* threadArgs) {
GPU::setDevice(parent->device);

// allocate buffer
threadParams->buffer = new RecFourierBufferData( ! parent->fftOnGPU, hasCTF,
void *rawMem = memoryUtils::page_aligned_alloc<RecFourierBufferData>(1, false);
threadParams->buffer = new(rawMem) RecFourierBufferData( ! parent->fftOnGPU, hasCTF, // placement of the object to specific location
parent->maxVolumeIndexX / 2, parent->maxVolumeIndexYZ, parent->paddedImgSize,
parent->bufferSize, (int)parent->R_repository.size());
pinMemory(threadParams->buffer);
Expand Down Expand Up @@ -455,8 +456,10 @@ void* ProgRecFourierGPU::threadRoutine(void* threadArgs) {

// clean after itself
releaseWrapper(threadParams->gpuStream);
threadParams->buffer->~RecFourierBufferData(); // <- explicit destructor call
free(rawMem);
unpinMemory(threadParams->buffer);
delete threadParams->buffer;
free(threadParams->buffer);
threadParams->buffer = NULL;
threadParams->selFile = NULL;
barrier_wait( &parent->barrier );// notify that thread finished
Expand Down