//----------------------------------------------------------------------------- void getPlatformDevice(int* platform, int* device) { char* platformString = getEnvString("OCL_PLATFORM"); char* deviceString = getEnvString("OCL_DEVICE"); if(platformString == NULL) *platform = 0; else *platform = atoi(platformString); if(deviceString == NULL) *device = 0; else *device = atoi(deviceString); }
//----------------------------------------------------------------------------- size_t* getNewSize(const char* suffix, const char* kernelName, size_t dimensions) { unsigned int suffixLength = strlen(suffix); // Read the environment variable: kernelName_suffix. size_t kernelNameSize = strlen(kernelName); size_t envVarSize = kernelNameSize + suffixLength; char varName[envVarSize]; memset(varName, 0, envVarSize); strncpy(varName, kernelName, kernelNameSize); strncat(varName, suffix, suffixLength); char* envVarValue = getEnvString(varName); if(envVarValue == NULL) { free(envVarValue); return NULL; } size_t* newSize = (size_t*) malloc(dimensions * sizeof(size_t)); memset(newSize, 0, dimensions * sizeof(size_t)); if(dimensions == 1) newSize[0] = (size_t) atoi(envVarValue); else if(dimensions == 2) parseList(envVarValue, newSize, newSize + 1); free(envVarValue); return newSize; }
void gemm(DATA_TYPE *A, DATA_TYPE *B, DATA_TYPE *C, DATA_TYPE* result) { int i, j, k; char *reps = getEnvString("OCL_REPETITIONS"); int intReps = 1; if (reps != NULL) { intReps = atoi(reps); } for (i = 0; i < 128; i++) { for (j = 0; j < 128; j++) { for (int rep = 0; rep < intReps; ++rep) { C[i * NJ + j] *= BETA; for (k = 0; k < NK; ++k) { C[i * NJ + j] += ALPHA * A[i * NK + k] * B[k * NJ + j]; } } // std::cout << C[i * NJ + j] << " " << result[i * NJ + j] << "\n"; assert(fabs(C[i * NJ + j] - result[i * NJ + j]) < 1 && "Error!"); } } std::cout << "Ok!\n"; }
/* Tokens: ARCH Build architecture (64) GCC_ARCH ARCH mapped to gcc -arch switches (x86_64) CC Compiler (cc) DEBUG Debug compilation options (-g, -Zi -Od) INC Include directory out/inc LIB Library directory (out/lib, xcode/VS: out/bin) LIBS Libraries required to link with ESP OBJ Name of compiled source (out/lib/view-MD5.o) MOD Output module (view_MD5.dylib) SHLIB Host Shared library (.lib, .so) SHOBJ Host Shared Object (.dll, .so) SRC Source code for view or controller (already templated) TMP Temp directory VS Visual Studio directory WINSDK Windows SDK directory */ PUBLIC char *espExpandCommand(EspRoute *eroute, cchar *command, cchar *source, cchar *module) { MprBuf *buf; MaAppweb *appweb; cchar *cp, *outputModule, *os, *arch, *profile; char *tmp; if (command == 0) { return 0; } appweb = MPR->appwebService; outputModule = mprTrimPathExt(module); maParsePlatform(appweb->platform, &os, &arch, &profile); buf = mprCreateBuf(-1, -1); for (cp = command; *cp; ) { if (*cp == '$') { if (matchToken(&cp, "${ARCH}")) { /* Target architecture (x86|mips|arm|x64) */ mprPutStringToBuf(buf, arch); } else if (matchToken(&cp, "${GCC_ARCH}")) { /* Target architecture mapped to GCC mtune|mcpu values */ mprPutStringToBuf(buf, getMappedArch(arch)); } else if (matchToken(&cp, "${INC}")) { /* Include directory for the configuration */ mprPutStringToBuf(buf, mprJoinPath(appweb->platformDir, "inc")); } else if (matchToken(&cp, "${LIBPATH}")) { /* Library directory for Appweb libraries for the target */ mprPutStringToBuf(buf, mprJoinPath(appweb->platformDir, "bin")); } else if (matchToken(&cp, "${LIBS}")) { /* Required libraries to link. These may have nested ${TOKENS} */ mprPutStringToBuf(buf, espExpandCommand(eroute, getLibs(os), source, module)); } else if (matchToken(&cp, "${MOD}")) { /* Output module path in the cache without extension */ mprPutStringToBuf(buf, outputModule); } else if (matchToken(&cp, "${OBJ}")) { /* Output object with extension (.o) in the cache directory */ mprPutStringToBuf(buf, mprJoinPathExt(outputModule, getObjExt(os))); } else if (matchToken(&cp, "${OS}")) { /* Target architecture (freebsd|linux|macosx|windows|vxworks) */ mprPutStringToBuf(buf, os); } else if (matchToken(&cp, "${SHLIB}")) { /* .dll, .so, .dylib */ mprPutStringToBuf(buf, getShlibExt(os)); } else if (matchToken(&cp, "${SHOBJ}")) { /* .dll, .so, .dylib */ mprPutStringToBuf(buf, getShobjExt(os)); } else if (matchToken(&cp, "${SRC}")) { /* View (already parsed into C code) or controller source */ mprPutStringToBuf(buf, source); } else if (matchToken(&cp, "${TMP}")) { if ((tmp = getenv("TMPDIR")) == 0) { if ((tmp = getenv("TMP")) == 0) { tmp = getenv("TEMP"); } } mprPutStringToBuf(buf, tmp ? tmp : "."); } else if (matchToken(&cp, "${VS}")) { mprPutStringToBuf(buf, getVisualStudio()); } else if (matchToken(&cp, "${VXCPU}")) { mprPutStringToBuf(buf, getVxCPU(arch)); } else if (matchToken(&cp, "${WINSDK}")) { mprPutStringToBuf(buf, getWinSDK()); /* These vars can be configured from environment variables. NOTE: the default esp.conf includes "esp->vxworks.conf" which has EspEnv definitions for the configured VxWorks toolchain */ } else if (matchToken(&cp, "${CC}")) { mprPutStringToBuf(buf, getEnvString(eroute, "CC", getCompilerPath(os, arch))); } else if (matchToken(&cp, "${LINK}")) { mprPutStringToBuf(buf, getEnvString(eroute, "LINK", "")); } else if (matchToken(&cp, "${CFLAGS}")) { mprPutStringToBuf(buf, getEnvString(eroute, "CFLAGS", "")); } else if (matchToken(&cp, "${DEBUG}")) { mprPutStringToBuf(buf, getEnvString(eroute, "DEBUG", getDebug())); } else if (matchToken(&cp, "${LDFLAGS}")) { mprPutStringToBuf(buf, getEnvString(eroute, "LDFLAGS", "")); } else if (matchToken(&cp, "${WIND_BASE}")) { mprPutStringToBuf(buf, getEnvString(eroute, "WIND_BASE", WIND_BASE)); } else if (matchToken(&cp, "${WIND_HOME}")) { mprPutStringToBuf(buf, getEnvString(eroute, "WIND_HOME", WIND_HOME)); } else if (matchToken(&cp, "${WIND_HOST_TYPE}")) { mprPutStringToBuf(buf, getEnvString(eroute, "WIND_HOST_TYPE", WIND_HOST_TYPE)); } else if (matchToken(&cp, "${WIND_PLATFORM}")) { mprPutStringToBuf(buf, getEnvString(eroute, "WIND_PLATFORM", WIND_PLATFORM)); } else if (matchToken(&cp, "${WIND_GNU_PATH}")) { mprPutStringToBuf(buf, getEnvString(eroute, "WIND_GNU_PATH", WIND_GNU_PATH)); } else if (matchToken(&cp, "${WIND_CCNAME}")) { mprPutStringToBuf(buf, getEnvString(eroute, "WIND_CCNAME", getCompilerName(os, arch))); } else { mprPutCharToBuf(buf, *cp++); } } else { mprPutCharToBuf(buf, *cp++); } } mprAddNullToBuf(buf); return sclone(mprGetBufStart(buf)); }