diff --git a/src/aparapi/com.amd.aparapi.jni/build.xml b/src/aparapi/com.amd.aparapi.jni/build.xml index 7df8d34e07d6148006ad3cf1a246e681f75764d3..b1731fbaf09e913d0ba25a1126bfb8da4fe4ae28 100644 --- a/src/aparapi/com.amd.aparapi.jni/build.xml +++ b/src/aparapi/com.amd.aparapi.jni/build.xml @@ -627,6 +627,8 @@ First consider editing the properties in build.properties <arg value="src/cpp/runKernel/KernelArg.cpp" /> <arg value="src/cpp/runKernel/ProfileInfo.cpp" /> <arg value="src/cpp/runKernel/Range.cpp" /> + <!-- !!! oren change -> platform config settings --> + <arg value="src/cpp/runKernel/ConfigSettings.cpp" /> <arg value="src/cpp/invoke/OpenCLJNI.cpp" /> <arg value="src/cpp/invoke/OpenCLArgDescriptor.cpp" /> <arg value="src/cpp/invoke/OpenCLMem.cpp" /> diff --git a/src/aparapi/com.amd.aparapi.jni/build_altera_ocl_v15.xml b/src/aparapi/com.amd.aparapi.jni/build_altera_ocl_v15.xml index 941105fd9da22370c28291c8a7dc55453c1387e3..2f96bf452d8daf5662f3066d57ce885ecbb32233 100644 --- a/src/aparapi/com.amd.aparapi.jni/build_altera_ocl_v15.xml +++ b/src/aparapi/com.amd.aparapi.jni/build_altera_ocl_v15.xml @@ -666,6 +666,8 @@ First consider editing the properties in build.properties <arg value="src/cpp/runKernel/KernelArg.cpp" /> <arg value="src/cpp/runKernel/ProfileInfo.cpp" /> <arg value="src/cpp/runKernel/Range.cpp" /> + <!-- !!! oren change -> platform config settings --> + <arg value="src/cpp/runKernel/ConfigSettings.cpp" /> <arg value="src/cpp/invoke/OpenCLJNI.cpp" /> <arg value="src/cpp/invoke/OpenCLArgDescriptor.cpp" /> <arg value="src/cpp/invoke/OpenCLMem.cpp" /> diff --git a/src/aparapi/com.amd.aparapi.jni/build_intel_ocl.xml b/src/aparapi/com.amd.aparapi.jni/build_intel_ocl.xml index 65ba29b88c581555865274a249520ba1d965af95..24177f84add00a61f685f72a2169ddf68d276e80 100644 --- a/src/aparapi/com.amd.aparapi.jni/build_intel_ocl.xml +++ b/src/aparapi/com.amd.aparapi.jni/build_intel_ocl.xml @@ -603,6 +603,8 @@ First consider editing the properties in build.properties <!-- !!! oren change -> add debug info, no optimizations <arg value="-O3" /> --> + <!-- !!! oren change -> add support for ISO C++ 2011 (C++0x) requires GCC 4.3 and later --> + <arg value="-std=c++0x" /> <arg value="-O0" /> <arg value="-g" /> <arg value="-fPIC" /> @@ -625,6 +627,8 @@ First consider editing the properties in build.properties <arg value="src/cpp/runKernel/KernelArg.cpp" /> <arg value="src/cpp/runKernel/ProfileInfo.cpp" /> <arg value="src/cpp/runKernel/Range.cpp" /> + <!-- !!! oren change -> platform config settings --> + <arg value="src/cpp/runKernel/ConfigSettings.cpp" /> <arg value="src/cpp/invoke/OpenCLJNI.cpp" /> <arg value="src/cpp/invoke/OpenCLArgDescriptor.cpp" /> <arg value="src/cpp/invoke/OpenCLMem.cpp" /> diff --git a/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/Aparapi.cpp b/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/Aparapi.cpp index e9e5101e51cf08e3ea5fa73062ee6d2649220d33..0c1812626bcac623fc15cc1a87ccfb0d3b467e0e 100644 --- a/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/Aparapi.cpp +++ b/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/Aparapi.cpp @@ -1156,7 +1156,7 @@ inline char* getClassName(JNIEnv* jenv, JNIContext* jniContext, const char *optE char *charPtr = classNameStr; while(charPtr = strchr(charPtr,'$')) { - *charPtr = BINARY_FILE_SEP; + *charPtr = jniContext->platformConfigPtr->getFileSeperator();//BINARY_FILE_SEP; charPtr++; } @@ -1287,10 +1287,11 @@ inline void outputOCLFile(JNIEnv* jenv, JNIContext* jniContext, const char *sour } -inline void verifyFlow(jint &buildFlags) +inline void verifyFlow(JNIContext* jniContext, jint &buildFlags) { + PlatformConfig::Ptr platformConfigPtr = jniContext->platformConfigPtr; // verify flow support is available - if(!(PLATFORM_FLOW_SUPPORT & buildFlags)) + if(!(platformConfigPtr->getFlowSupport() & buildFlags)) { fprintf(stderr, "!!! Error requested flow(%0xd) not available !!!\n",buildFlags); throw CLException(CL_INVALID_VALUE,"buildProgramJNI() -> bad request flow"); @@ -1298,7 +1299,7 @@ inline void verifyFlow(jint &buildFlags) // check/set if default flow is requested if(buildFlags==DEFAULT_FLOW) - buildFlags = PLATFORM_DEFAULT_FLOW; + buildFlags = platformConfigPtr->getDefaultFlowSupport(); } JNI_JAVA(jlong, KernelRunnerJNI, buildProgramJNI) @@ -1319,14 +1320,14 @@ JNI_JAVA(jlong, KernelRunnerJNI, buildProgramJNI) // !!! oren change -> // verify the flow and modify if need be - verifyFlow(buildFlags); + verifyFlow(jniContext,buildFlags); //#ifdef USE_BINARY_FILE if(buildFlags & com_amd_aparapi_internal_jni_KernelRunnerJNI_JNI_FLAG_BINARY_FLOW) { 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,jniContext->platformConfigPtr->getBinFileExtension());//BINARY_FILE_EXT 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); diff --git a/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/ConfigSettings.cpp b/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/ConfigSettings.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0cd91ad6f5cb04c3075925cdcf9e637da83219c2 --- /dev/null +++ b/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/ConfigSettings.cpp @@ -0,0 +1,29 @@ +#include "ConfigSettings.h" + +/// +// Specify the different platform configuration in this file +// +// Platform parameters can be set in the following format: +// A. REGISTER_PLATFORM_CONFIG -> calls PlatformConfig(const char *name, int flowSupport, int defaultFlowSupport, const char *binFileExt, char fileSep) +// B. REGISTER_PLATFORM_CONFIG_WITH_SEARCH_STR -> calls PlatformConfig(const char *name, const char *searchStr, int flowSupport, int defaultFlowSupport, const char *binFileExt, char fileSep) + +// **************************************************************** +// Below is the default settings for any platform (unless specified otherwise in another specific configuration line) +// Note that by default we have source and binary flows, source is the default flow, '.bcl' is the binary extension and '_' is the file separator +// **************************************************************** +REGISTER_PLATFORM_CONFIG(DEFAULT_PLATFORM_CONFIG_NAME, SOURCE_FLOW | BINARY_FLOW | DEFAULT_FLOW, SOURCE_FLOW, ".bcl", '_'); +// **************************************************************** +// Altera OpenCL specific configuration +// **************************************************************** +REGISTER_PLATFORM_CONFIG(Altera, BINARY_FLOW | DEFAULT_FLOW, BINARY_FLOW, ".aocx",'.'); +// if you need a search string different then name use this form instead, it includes a search string +//REGISTER_PLATFORM_CONFIG_WITH_SEARCH_STR(Altera, "Altera SDK for OpenCL", BINARY_FLOW | DEFAULT_FLOW, BINARY_FLOW, ".aocx",'.'); +// **************************************************************** +// example for AMD ... +// **************************************************************** +REGISTER_PLATFORM_CONFIG(AMD,SOURCE_FLOW | BINARY_FLOW | DEFAULT_FLOW, SOURCE_FLOW, ".bcl", '.'); +// **************************************************************** +// example for Intel ... +// **************************************************************** +REGISTER_PLATFORM_CONFIG(Intel,SOURCE_FLOW | BINARY_FLOW | DEFAULT_FLOW, SOURCE_FLOW, ".bcl", '.'); + diff --git a/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/ConfigSettings.h b/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/ConfigSettings.h index c002386f4839c5e218b5bda9e2e5467406bfe0e6..41260ed4d03d2dcc0542197853fe5287d986c1f2 100644 --- a/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/ConfigSettings.h +++ b/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/ConfigSettings.h @@ -3,9 +3,10 @@ // !!! oren changes -> // configuration settings for building platform specific code -// TODO: consider moving parts of this to a configuration file later on and load settings dynamically +// TODO: consider moving parts of this to a configuration file lateron and load settings dynamically #include <string> +#include <cstring> #include <map> #include <tuple> #include <memory> @@ -13,7 +14,6 @@ // use values from JNI config #include "com_amd_aparapi_internal_jni_KernelRunnerJNI.h" - // auto output kernel.cl file #define OUTPUT_OCL_FILE // allows defining an alternative folder where bin files should be loaded from @@ -28,18 +28,53 @@ #define DEFAULT_FLOW com_amd_aparapi_internal_jni_KernelRunnerJNI_JNI_FLAG_DEFAULT_FLOW /////////////////////////// -#define FILE_EXT_LENGTH 8 +//#define FILE_EXT_LENGTH 8 class PlatformConfig { public: - PlatformConfig(int flowSupport, const char *fileExt, char fileSep) + + typedef std::shared_ptr<PlatformConfig> Ptr; + + PlatformConfig(const char *name, int flowSupport, int defaultFlowSupport, const char *binFileExt, char fileSep) + { + setName(name); + setSearchStr(name); // default search string is name! + setFlowSupport(flowSupport); + setDefaultFlowSupport(defaultFlowSupport); + setBinFileExtension(binFileExt); + setFileSeperator(fileSep); + } + + PlatformConfig(const char *name, const char *searchStr, int flowSupport, int defaultFlowSupport, const char *binFileExt, char fileSep) { + setName(name); + setSearchStr(searchStr); setFlowSupport(flowSupport); - setFileExtension(fileExt); + setDefaultFlowSupport(defaultFlowSupport); + setBinFileExtension(binFileExt); setFileSeperator(fileSep); } + void setName(const char *name) + { + m_name = name; + } + const char *getName() + { + return m_name.c_str(); + } + + void setSearchStr(const char *searchStr) + { + m_searchStr = searchStr; + } + + const char *getsearchStr() + { + return m_searchStr.c_str(); + } + void setFlowSupport(int flowSupport) { m_flowSupport = flowSupport; @@ -50,14 +85,24 @@ public: return m_flowSupport; } - void setFileExtension(const char *fileExt) + void setDefaultFlowSupport(int defaultFlowSupport) + { + m_defaultFlowSupport = defaultFlowSupport; + } + + int getDefaultFlowSupport() + { + return m_defaultFlowSupport; + } + + void setBinFileExtension(const char *binFileExt) { - m_fileExt = fileExt; + m_binFileExt = binFileExt; } - const char *getFileExtension() + const char *getBinFileExtension() { - return m_fileExt.c_str(); + return m_binFileExt.c_str(); } void setFileSeperator(char fileSep) @@ -73,17 +118,21 @@ public: protected: // data int m_flowSupport; + int m_defaultFlowSupport; //char m_fileExt[FILE_EXT_LENGTH]; - std::string m_fileExt; + std::string m_binFileExt; char m_fileSep; + std::string m_name; + std::string m_searchStr; // platform name search string }; class PlatformConfigFactory { public: - typedef std::shared_ptr<PlatformConfig> PlatformConfigPtr; - typedef std::pair<std::string,PlatformConfigPtr> PlatformConfigTuple; - typedef std::map<std::string,PlatformConfigTuple> PlatformConfigMap; + //typedef std::shared_ptr<PlatformConfig> PlatformConfigPtr; + //typedef std::pair<std::string,PlatformConfigPtr> PlatformConfigTuple; + //typedef std::map<std::string,PlatformConfigTuple> PlatformConfigMap; + typedef std::map<std::string,PlatformConfig::Ptr> PlatformConfigMap; static PlatformConfigFactory &getPlatformConfigFactory()//openclManager *oclMgr) { @@ -93,24 +142,49 @@ public: return *pcf; } - bool registerPlatformConfig(const char *name, PlatformConfigPtr platformConfigPtr) + bool registerPlatformConfig(const char *name, PlatformConfig::Ptr platformConfigPtr) { - m_platformConfigMap[name]=PlatformConfigTuple(name,platformConfigPtr); + //m_platformConfigMap[name]=PlatformConfigTuple(name,platformConfigPtr); + m_platformConfigMap[name]=platformConfigPtr; return true; } -#define REGISTER_PLLATFORM_CONFIG(name,platformConfigPtr) bool name##PlatformConfig=PlatformConfigFactory::getPlatformConfigFactory().register(#name,platformConfigPtr); +#define REGISTER_PLATFORM_CONFIG_BASE(name,platformConfigPtr) bool name##PlatformConfig=PlatformConfigFactory::getPlatformConfigFactory().registerPlatformConfig(#name,PlatformConfig::Ptr(platformConfigPtr)); +#define REGISTER_PLATFORM_CONFIG(name,flowSupport,defaultFlowSupport,binFileExt,fileSep) REGISTER_PLATFORM_CONFIG_BASE(name, new PlatformConfig(#name,flowSupport,defaultFlowSupport,binFileExt,fileSep)) +#define REGISTER_PLATFORM_CONFIG_WITH_SEARCH_STR(name,searchStr,flowSupport,defaultFlowSupport,binFileExt,fileSep) REGISTER_PLATFORM_CONFIG_BASE(name, new PlatformConfig(#name,searchStr,flowSupport,defaultFlowSupport,binFileExt,fileSep)) +#define DEFAULT_PLATFORM_CONFIG_NAME DEFAULT_PCN +#define NAME_TO_STR(s) #s - PlatformConfigPtr findPlatformConfigByName(const char *name) + PlatformConfig::Ptr findPlatformConfigByName(const char *name) { PlatformConfigMap::iterator itr = m_platformConfigMap.find(name); if (itr != m_platformConfigMap.end()) { - return itr->second.second; + //return itr->second.second; + return itr->second; } else - return PlatformConfigPtr(); + return PlatformConfig::Ptr(); + } + + PlatformConfig::Ptr findPlatformConfigFromFullName(const char *fullPlatformName) + { + // Requires C++11 -> leave minimum compiler support at C++0x for now ... + //for ( const auto &itr : m_platformConfigMap ) + for (PlatformConfigMap::iterator itr = m_platformConfigMap.begin(); itr != m_platformConfigMap.end(); itr++ ) + { + if(std::strstr(fullPlatformName,itr->second->getsearchStr())) + return itr->second; + } + + // if not found search for default cplatform config + return findPlatformConfigByName(NAME_TO_STR(DEFAULT_PLATFORM_CONFIG_NAME)); + } + + PlatformConfigMap &getConfigMap() + { + return m_platformConfigMap; } // data @@ -128,6 +202,7 @@ public: /////////////////////////// // Altera platform specific /////////////////////////// +/* #ifdef ALTERA_OPENCL #define PLATFORM_FLOW_SUPPORT (SOURCE_FLOW | BINARY_FLOW | DEFAULT_FLOW) #define PLATFORM_DEFAULT_FLOW BINARY_FLOW @@ -148,7 +223,7 @@ public: #define BINARY_FILE_EXT ".bcl" #define BINARY_FILE_SEP '.' #endif // ALTERA_OPENCL - +*/ #endif // CONFIG_SETTINGS_H diff --git a/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/JNIContext.cpp b/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/JNIContext.cpp index db9a5cfa498bf8a51b54915f52bf8ad7a310cc35..f2d6fd8678de7d6891e36939faff48bbe5328f3e 100644 --- a/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/JNIContext.cpp +++ b/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/JNIContext.cpp @@ -29,6 +29,12 @@ JNIContext::JNIContext(JNIEnv *jenv, jobject _kernelObject, jobject _openCLDevic if (status == CL_SUCCESS){ valid = JNI_TRUE; } + + // !!! oren change -> setup platform configuration + char platformName[512]={""}; + status = clGetPlatformInfo(platformId, CL_PLATFORM_NAME, sizeof(platformName), platformName, NULL); + platformConfigPtr = PlatformConfigFactory::getPlatformConfigFactory().findPlatformConfigFromFullName(platformName); + } void JNIContext::dispose(JNIEnv *jenv, Config* config) { diff --git a/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/JNIContext.h b/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/JNIContext.h index e22c5ff418b446c83ab6730b089240803e2d1370..99ea7608a4f1ff3b99e22df55fc271c2ce1704d7 100644 --- a/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/JNIContext.h +++ b/src/aparapi/com.amd.aparapi.jni/src/cpp/runKernel/JNIContext.h @@ -7,6 +7,8 @@ #include "ProfileInfo.h" #include "com_amd_aparapi_internal_jni_KernelRunnerJNI.h" #include "Config.h" +#include "ConfigSettings.h" + class JNIContext { private: @@ -34,6 +36,8 @@ public: jint passes; ProfileInfo *exec; FILE* profileFile; + // !!! oren change + PlatformConfig::Ptr platformConfigPtr; JNIContext(JNIEnv *jenv, jobject _kernelObject, jobject _openCLDeviceObject, jint _flags);