Skip to content
Snippets Groups Projects
Commit bd31f59c authored by Maximillian Bensch's avatar Maximillian Bensch
Browse files

Memdebug: count memory allocs

parent 0edfa5d2
No related branches found
No related tags found
No related merge requests found
......@@ -194,6 +194,8 @@ cl_int clFFT_1DTwistPlannar(clFFT_Plan Plan, cl_command_queue queue, cl_mem arra
void clFFT_DumpPlan( clFFT_Plan plan, FILE *file);
size_t getMallocSize( void );
#ifdef __cplusplus
}
#endif
......
......@@ -79,9 +79,10 @@ allocateTemporaryBufferInterleaved(cl_fft_plan *plan, cl_uint batchSize)
size_t tmpLength = plan->n.x * plan->n.y * plan->n.z * batchSize * 2 * sizeof(cl_float);
if(plan->tempmemobj)
mallocsize -= sizeof(plan->tempmemobj);
clReleaseMemObject(plan->tempmemobj);
plan->tempmemobj = clCreateBuffer(plan->context, CL_MEM_READ_WRITE, tmpLength, NULL, &err);
plan->tempmemobj = CreateBuffer(plan->context, CL_MEM_READ_WRITE, tmpLength, NULL, &err);
}
return err;
}
......@@ -97,13 +98,15 @@ allocateTemporaryBufferPlannar(cl_fft_plan *plan, cl_uint batchSize)
size_t tmpLength = plan->n.x * plan->n.y * plan->n.z * batchSize * sizeof(cl_float);
if(plan->tempmemobj_real)
mallocsize -= sizeof(plan->tempmemobj_real);
clReleaseMemObject(plan->tempmemobj_real);
if(plan->tempmemobj_imag)
mallocsize -= sizeof(plan->tempmemobj_imag);
clReleaseMemObject(plan->tempmemobj_imag);
plan->tempmemobj_real = clCreateBuffer(plan->context, CL_MEM_READ_WRITE, tmpLength, NULL, &err);
plan->tempmemobj_imag = clCreateBuffer(plan->context, CL_MEM_READ_WRITE, tmpLength, NULL, &terr);
plan->tempmemobj_real = CreateBuffer(plan->context, CL_MEM_READ_WRITE, tmpLength, NULL, &err);
plan->tempmemobj_imag = CreateBuffer(plan->context, CL_MEM_READ_WRITE, tmpLength, NULL, &terr);
err |= terr;
}
return err;
......
......@@ -70,6 +70,7 @@
using namespace std;
extern size_t mallocsize;
typedef enum kernel_dir_t
{
cl_fft_kernel_x,
......@@ -186,4 +187,6 @@ typedef struct
void FFT1D(cl_fft_plan *plan, cl_fft_kernel_dir dir);
cl_mem CreateBuffer (cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret);
#endif
......@@ -76,6 +76,8 @@ using namespace std;
extern void getKernelWorkDimensions(cl_fft_plan *plan, cl_fft_kernel_info *kernelInfo, cl_int *batchSize, size_t *gWorkItems, size_t *lWorkItems);
size_t mallocsize = 0;
static void
getBlockConfigAndKernelString(cl_fft_plan *plan)
{
......@@ -162,27 +164,32 @@ destroy_plan(cl_fft_plan *Plan)
}
if(Plan->tempmemobj)
{
mallocsize -= sizeof(Plan->tempmemobj);
clReleaseMemObject(Plan->tempmemobj);
Plan->tempmemobj = NULL;
}
if(Plan->tempmemobj_real)
{
mallocsize -= sizeof(Plan->tempmemobj_real);
clReleaseMemObject(Plan->tempmemobj_real);
Plan->tempmemobj_real = NULL;
}
if(Plan->tempmemobj_imag)
{
mallocsize -= sizeof(Plan->tempmemobj_imag);
clReleaseMemObject(Plan->tempmemobj_imag);
Plan->tempmemobj_imag = NULL;
}
if(Plan->cossin_LUT_d1)
{
mallocsize -= sizeof(Plan->cossin_LUT_d1);
clReleaseMemObject(Plan->cossin_LUT_d1);
}
if(Plan->cossin_LUT_d2)
{
mallocsize -= sizeof(Plan->cossin_LUT_d2);
clReleaseMemObject(Plan->cossin_LUT_d2);
}
......@@ -310,7 +317,7 @@ int precomputeSinCosLUTs(cl_fft_plan * plan,cl_int *error_code) {
tmpLUT_cossin1[i*2] =(float)cos(PI2 * (float) i / (float)N);
tmpLUT_cossin1[i*2+1]=(float)sin(PI2 * (float) i / (float)N);
}
plan->cossin_LUT_d1 = clCreateBuffer(plan->context,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, plan->N1*2*sizeof(float),tmpLUT_cossin1, &err);
plan->cossin_LUT_d1 = CreateBuffer(plan->context,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, plan->N1*2*sizeof(float),tmpLUT_cossin1, &err);
if( err != CL_SUCCESS)
{
......@@ -327,7 +334,7 @@ int precomputeSinCosLUTs(cl_fft_plan * plan,cl_int *error_code) {
tmpLUT_cossin2[2*i] =(float)cos(PI2 * (float) i / (float) plan->N2);
tmpLUT_cossin2[2*i+1]=(float)sin(PI2 * (float) i / (float) plan->N2);
}
plan->cossin_LUT_d2 = clCreateBuffer(plan->context,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, plan->N2*2*sizeof(float),tmpLUT_cossin2, &err);
plan->cossin_LUT_d2 = CreateBuffer(plan->context,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, plan->N2*2*sizeof(float),tmpLUT_cossin2, &err);
if( err != CL_SUCCESS)
{
if(error_code)
......@@ -526,3 +533,16 @@ void clFFT_DumpPlan( clFFT_Plan Plan, FILE *file)
}
fprintf(out, "%s\n", plan->kernel_string->c_str());
}
cl_mem CreateBuffer (cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret)
{
cl_mem ret = clCreateBuffer(context, flags, size, host_ptr, errcode_ret);
mallocsize += size;
return ret;
}
size_t getMallocSize( void )
{
return mallocsize;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment