Skip to content

Commit

Permalink
Handle mem alloc failures gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
krrishnarraj committed Jan 31, 2015
1 parent ad6675a commit af4e943
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kr.clpeak"
android:versionCode="3"
android:versionCode="4"
android:versionName="1.0" android:installLocation="auto">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Expand Down
6 changes: 3 additions & 3 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ uint roundToPowOf2(uint number, int maxPower)
int i;

if ((maxPower > 0) && (number > (1 << maxPower)))
return 1 << maxPower;
return (1 << maxPower);

for (i=1 ; i < 8*sizeof(int) ; i++)
for (i=1 ; i < (8*sizeof(int)) ; i++)
if ((1 << i) > number)
break;

return 1 << (i-1);
return (1 << (i-1));
}
10 changes: 6 additions & 4 deletions src/global_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ int clPeak::runGlobalBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, d
{
float timed_lo, timed_go, timed, gbps;
cl::NDRange globalSize, localSize;
float *arr = NULL;

if(!isGlobalBW)
return 0;
Expand All @@ -24,11 +25,11 @@ int clPeak::runGlobalBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, d
numItems = roundToPowOf2(maxItems);
}

float *arr = new float[numItems];
populate(arr, numItems);

try
{
arr = new float[numItems];
populate(arr, numItems);

log->print(NEWLINE TAB TAB "Global memory bandwidth (GBPS)" NEWLINE);
log->xmlOpenTag("global_memory_bandwidth");
log->xmlAppendAttribs("unit", "gbps");
Expand Down Expand Up @@ -147,6 +148,8 @@ int clPeak::runGlobalBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, d
log->xmlRecord("float16", gbps);
///////////////////////////////////////////////////////////////////////////
log->xmlCloseTag(); // global_memory_bandwidth

if(arr) delete [] arr;
}
catch(cl::Error error)
{
Expand All @@ -159,7 +162,6 @@ int clPeak::runGlobalBandwidthTest(cl::CommandQueue &queue, cl::Program &prog, d
return -1;
}

if(arr) delete [] arr;
return 0;
}

7 changes: 3 additions & 4 deletions src/transfer_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ int clPeak::runTransferBandwidthTest(cl::CommandQueue &queue, cl::Program &prog,
cl::Context ctx = queue.getInfo<CL_QUEUE_CONTEXT>();
int iters = devInfo.transferBWIters;
Timer timer;
float *arr = NULL;

cl_uint maxItems = devInfo.maxAllocSize / sizeof(float) / 2;
cl_uint numItems;
Expand All @@ -22,10 +23,9 @@ int clPeak::runTransferBandwidthTest(cl::CommandQueue &queue, cl::Program &prog,
numItems = roundToPowOf2(maxItems);
}

float *arr = new float[numItems];

try
{
arr = new float[numItems];
cl::Buffer clBuffer = cl::Buffer(ctx, (CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR), (numItems * sizeof(float)));

log->print(NEWLINE TAB TAB "Transfer bandwidth (GBPS)" NEWLINE);
Expand Down Expand Up @@ -245,7 +245,7 @@ int clPeak::runTransferBandwidthTest(cl::CommandQueue &queue, cl::Program &prog,
///////////////////////////////////////////////////////////////////////////
log->xmlCloseTag(); // transfer_bandwidth


if(arr) delete [] arr;
}
catch(cl::Error error)
{
Expand All @@ -258,7 +258,6 @@ int clPeak::runTransferBandwidthTest(cl::CommandQueue &queue, cl::Program &prog,
return -1;
}

if(arr) delete [] arr;
return 0;
}

0 comments on commit af4e943

Please sign in to comment.