Skip to content
Snippets Groups Projects
Commit 9232232f authored by Oren's avatar Oren
Browse files

Added memory leak patch

parent c5721f26
No related branches found
No related tags found
No related merge requests found
...@@ -1169,6 +1169,30 @@ inline char* getClassName(JNIEnv* jenv, JNIContext* jniContext, const char *optE ...@@ -1169,6 +1169,30 @@ inline char* getClassName(JNIEnv* jenv, JNIContext* jniContext, const char *optE
return classNameStr; return classNameStr;
} }
const char *OSPathSeparator =
#ifdef _WIN32
"\\";
#else
"/";
#endif
char *buildFilePath(const char *basePart,const char *filePart)
{
int fullPathLength = strlen(filePart);
if(basePart!=NULL)
fullPathLength += strlen(basePart);
char *fullPath = new char[fullPathLength + 1];
if(basePart!=NULL)
{
strcpy(fullPath,basePart);
// !!! Handle os dependent separator !!!
if(fullPath[strlen(fullPath)-1]!=OSPathSeparator[0])
strcat(fullPath,OSPathSeparator);
}
strcat(fullPath,filePart);
return fullPath;
}
void writeProfile(JNIEnv* jenv, JNIContext* jniContext) { void writeProfile(JNIEnv* jenv, JNIContext* jniContext) {
// compute profile filename // compute profile filename
// indicate cpu or gpu // indicate cpu or gpu
...@@ -1276,6 +1300,10 @@ JNI_JAVA(jlong, KernelRunnerJNI, buildProgramJNI) ...@@ -1276,6 +1300,10 @@ JNI_JAVA(jlong, KernelRunnerJNI, buildProgramJNI)
#define BINARY_FILE_EXT ".aocx" #define BINARY_FILE_EXT ".aocx"
#endif #endif
// allows defining an alternative folder where bin files should be loaded from
// Usefull when running in aparapi embeded mode
#define BINARY_FOLDER_ENV_VAR "APARAPI_CL_BIN_FOLDER"
const char *sourceChars = jenv->GetStringUTFChars(source, NULL); const char *sourceChars = jenv->GetStringUTFChars(source, NULL);
//#ifdef OUTPUT_OCL_FILE //#ifdef OUTPUT_OCL_FILE
...@@ -1283,9 +1311,14 @@ JNI_JAVA(jlong, KernelRunnerJNI, buildProgramJNI) ...@@ -1283,9 +1311,14 @@ JNI_JAVA(jlong, KernelRunnerJNI, buildProgramJNI)
//#endif //#endif
#ifdef USE_BINARY_FILE #ifdef USE_BINARY_FILE
char *binFileFolder = getenv(BINARY_FOLDER_ENV_VAR);
fprintf(stderr, "Bin Folder is %s\n",binFileFolder);
char *binFileName = getClassName(jenv,jniContext,BINARY_FILE_EXT); char *binFileName = getClassName(jenv,jniContext,BINARY_FILE_EXT);
jniContext->program = CLHelper::createProgramWithBinary(jenv, jniContext->context, 1, &jniContext->deviceId, binFileName, NULL, &status); char *fullBinFilePath = buildFilePath(binFileFolder,binFileName);
fprintf(stderr, "FullBinFilePath is %s\n",fullBinFilePath);
jniContext->program = CLHelper::createProgramWithBinary(jenv, jniContext->context, 1, &jniContext->deviceId, fullBinFilePath, NULL, &status);
delete []binFileName; delete []binFileName;
delete []fullBinFilePath;
#else #else
jniContext->program = CLHelper::createProgramWithSource(jenv, jniContext->context, 1, &jniContext->deviceId, sourceChars, NULL, &status); jniContext->program = CLHelper::createProgramWithSource(jenv, jniContext->context, 1, &jniContext->deviceId, sourceChars, NULL, &status);
#endif #endif
......
...@@ -49,6 +49,17 @@ ArrayBuffer::ArrayBuffer(): ...@@ -49,6 +49,17 @@ ArrayBuffer::ArrayBuffer():
isPinned(false){ isPinned(false){
} }
ArrayBuffer::~ArrayBuffer()
{
// !!! oren fix mem leak
if(addr!=NULL)
{
acl_aligned_free(addr);//aclPtr
fprintf(stderr, "Deallocated %d bytes at address %x\n",lengthInBytes,(long)addr);
//addr = NULL;
}
}
void ArrayBuffer::unpinAbort(JNIEnv *jenv){ void ArrayBuffer::unpinAbort(JNIEnv *jenv){
// !!! oren mem test // !!! oren mem test
//jenv->ReleasePrimitiveArrayCritical((jarray)javaArray, addr,JNI_ABORT); //jenv->ReleasePrimitiveArrayCritical((jarray)javaArray, addr,JNI_ABORT);
......
...@@ -102,6 +102,7 @@ class ArrayBuffer{ ...@@ -102,6 +102,7 @@ class ArrayBuffer{
ProfileInfo write; ProfileInfo write;
ArrayBuffer(); ArrayBuffer();
~ArrayBuffer();
void unpinAbort(JNIEnv *jenv); void unpinAbort(JNIEnv *jenv);
void unpinCommit(JNIEnv *jenv); void unpinCommit(JNIEnv *jenv);
void pin(JNIEnv *jenv); void pin(JNIEnv *jenv);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment