Commit 70f4830b authored by 刘劭荣(20软)'s avatar 刘劭荣(20软)

减少GPU CPU交换时间

parent e1eaf4a8
...@@ -41,6 +41,7 @@ drr::drr(std::string input) ...@@ -41,6 +41,7 @@ drr::drr(std::string input)
image = reader->GetOutput(); image = reader->GetOutput();
ImageType::SizeType sizeCT = image->GetLargestPossibleRegion().GetSize(); ImageType::SizeType sizeCT = image->GetLargestPossibleRegion().GetSize();
InputImageType::SpacingType ctPixelSpacing = image->GetSpacing();
//free(cpp_object3D); //free(cpp_object3D);
cpp_object3D = (float*)malloc(sizeof(float)*sizeCT[0] * sizeCT[1] * sizeCT[2]); cpp_object3D = (float*)malloc(sizeof(float)*sizeCT[0] * sizeCT[1] * sizeCT[2]);
for (int i = 0; i < sizeCT[0]; i++) for (int i = 0; i < sizeCT[0]; i++)
...@@ -53,7 +54,15 @@ drr::drr(std::string input) ...@@ -53,7 +54,15 @@ drr::drr(std::string input)
cpp_object3D[k + j * (sizeCT[2]) + i * (sizeCT[1] * sizeCT[2])] = image->GetPixel(index); cpp_object3D[k + j * (sizeCT[2]) + i * (sizeCT[1] * sizeCT[2])] = image->GetPixel(index);
} }
int SizeCT[3];
SizeCT[0] = sizeCT[0];
SizeCT[1] = sizeCT[1];
SizeCT[2] = sizeCT[2];
float PixelSpacingCT[3];
PixelSpacingCT[0] = ctPixelSpacing[0];
PixelSpacingCT[1] = ctPixelSpacing[1];
PixelSpacingCT[2] = ctPixelSpacing[2];
loadDICOMInGPUMemory(cpp_object3D, SizeCT, PixelSpacingCT);
std::cout << "itk readfile :" << (double)clock() / CLOCKS_PER_SEC - time << std::endl; std::cout << "itk readfile :" << (double)clock() / CLOCKS_PER_SEC - time << std::endl;
} }
...@@ -61,7 +70,6 @@ drr::drr(std::string input) ...@@ -61,7 +70,6 @@ drr::drr(std::string input)
drr::~drr() drr::~drr()
{ {
freeDICOMFromGPUMemory(); freeDICOMFromGPUMemory();
freeAuxiliaryVariablesInGPUMemory();
} }
float* drr::cudaDRR(float rx, float ry, float rz, int dx, int dy, float threshold) float* drr::cudaDRR(float rx, float ry, float rz, int dx, int dy, float threshold)
...@@ -231,9 +239,12 @@ float* drr::cudaDRR(float rx, float ry, float rz, int dx, int dy, float threshol ...@@ -231,9 +239,12 @@ float* drr::cudaDRR(float rx, float ry, float rz, int dx, int dy, float threshol
cudaPara.numThreads = 1024; cudaPara.numThreads = 1024;
cudaPara.numBlocks = (int)ceil((float)output_size[0] * output_size[1] / 1024); cudaPara.numBlocks = (int)ceil((float)output_size[0] * output_size[1] / 1024);
loadDICOMInGPUMemory(image3d.image, image3d.SizeCT, image3d.PixelSpacingCT);
loadOuputVariablesInGPUMemory((int)output_size[0],(int)output_size[1]); loadOuputVariablesInGPUMemory((int)output_size[0],(int)output_size[1]);
float* object2d = calculateDRRwithCUDA(cudaPara, para); float* object2d = calculateDRRwithCUDA(cudaPara, para);
freeAuxiliaryVariablesInGPUMemory();
return object2d; return object2d;
//////////////以下代码为保存DRR到硬盘 //////////////以下代码为保存DRR到硬盘
......
...@@ -18,6 +18,7 @@ void socketManager::get_CUDAdrr(const char * path) ...@@ -18,6 +18,7 @@ void socketManager::get_CUDAdrr(const char * path)
{ {
if (rd != NULL) { if (rd != NULL) {
// 析构 释放GPU内存 // 析构 释放GPU内存
rd->~drr();
rd = NULL; rd = NULL;
} }
rd = new drr(path); rd = new drr(path);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment