// Searches all platforms for the first platform whose name // contains the search string (case-insensitive). cl_platform_id findPlatform(const char *platform_name_search) { cl_int status; std::string search = platform_name_search; std::transform(search.begin(), search.end(), search.begin(), tolower); // Get number of platforms. cl_uint num_platforms; status = clGetPlatformIDs(0, NULL, &num_platforms); checkError(status, "Query for number of platforms failed"); // Get a list of all platform ids. scoped_array<cl_platform_id> pids(num_platforms); status = clGetPlatformIDs(num_platforms, pids, NULL); checkError(status, "Query for all platform ids failed"); // For each platform, get name and compare against the search string. for(unsigned i = 0; i < num_platforms; ++i) { std::string name = getPlatformName(pids[i]); // Convert to lower case. std::transform(name.begin(), name.end(), name.begin(), tolower); if(name.find(search) != std::string::npos) { // Found! return pids[i]; } } // No platform found. return NULL; }
ClPlatform::ClPlatform(const cl_platform_id id) : mId(id), mName(getPlatformName(id)), mVendor(getPlatformVendor(id)), mProfile(getPlatformProfile(id)), mVersion(getPlatformVersion(id)), mDevices(getPlatformDevices(id)) { }
static int _testGetPlatformName(void) { CharString p = getPlatformName(); #if LINUX assertCharStringContains(p, "Linux"); #elif MACOSX assertCharStringContains(p, "Mac OS X"); #elif WINDOWS assertCharStringContains(p, "Windows"); #else assertCharStringEquals(p, "Unsupported platform"); #endif freeCharString(p); return 0; }
Array<T> triangleSolve(const Array<T> &A, const Array<T> &b, const af_mat_prop options) { trsm_func<T> gpu_trsm; Array<T> B = copyArray<T>(b); int N = B.dims()[0]; int NRHS = B.dims()[1]; const cl::Buffer* A_buf = A.get(); cl::Buffer* B_buf = B.get(); cl_event event = 0; cl_command_queue queue = getQueue()(); std::string pName = getPlatformName(getDevice()); if(pName.find("NVIDIA") != std::string::npos && (options & AF_MAT_UPPER)) { Array<T> AT = transpose<T>(A, true); cl::Buffer* AT_buf = AT.get(); gpu_trsm(clblasColumnMajor, clblasLeft, clblasLower, clblasConjTrans, options & AF_MAT_DIAG_UNIT ? clblasUnit : clblasNonUnit, N, NRHS, scalar<T>(1), (*AT_buf)(), AT.getOffset(), AT.strides()[1], (*B_buf)(), B.getOffset(), B.strides()[1], 1, &queue, 0, nullptr, &event); } else { gpu_trsm(clblasColumnMajor, clblasLeft, options & AF_MAT_LOWER ? clblasLower : clblasUpper, clblasNoTrans, options & AF_MAT_DIAG_UNIT ? clblasUnit : clblasNonUnit, N, NRHS, scalar<T>(1), (*A_buf)(), A.getOffset(), A.strides()[1], (*B_buf)(), B.getOffset(), B.strides()[1], 1, &queue, 0, nullptr, &event); } return B; }
void CLWrapper::initPlatformIds(){ platformIdCount = 0; clGetPlatformIDs(0, nullptr, &platformIdCount); if (platformIdCount == 0) { std::cerr << "CLWrapper: No OpenCL platform found" << std::endl; std::getchar(); std::exit; } else if (verbose) std::cout << "CLWrapper: Found " << platformIdCount << " platform(s)" << std::endl; platformIds.resize(platformIdCount); clGetPlatformIDs(platformIdCount, platformIds.data(), nullptr); if (verbose) for (cl_uint i = 0; i < platformIdCount; ++i) std::cout << "CLWrapper: \t (" << (i + 1) << ") : " << getPlatformName(platformIds[i]) << std::endl; }
void CLWrapper::initDevices(){ deviceIdCount = 0; clGetDeviceIDs(platformIds[platformIds.size() - 1], CL_DEVICE_TYPE_ALL, 0, nullptr, &deviceIdCount); if (deviceIdCount == 0) { std::cerr << "CLWrapper: No OpenCL devices found" << std::endl; std::getchar(); std::exit; } else if (verbose) std::cout << "CLWrapper: Found " << deviceIdCount << " device(s) for " + getPlatformName(platformIds[platformIds.size() - 1]) << std::endl; deviceIds.resize(deviceIdCount); clGetDeviceIDs(platformIds[platformIds.size() - 1], CL_DEVICE_TYPE_ALL, deviceIdCount, deviceIds.data(), nullptr); if (verbose) for (cl_uint i = 0; i < deviceIdCount; ++i) std::cout << "CLWrapper: \t (" << (i + 1) << ") : " << getDeviceName(deviceIds[i]) << std::endl; }
static void printWelcomeMessage(int argc, char** argv) { CharString stringBuffer = newCharString(); CharString versionString = buildInfoGetVersionString(); char* space; int i; logInfo("%s initialized, build %ld", versionString->data, buildInfoGetDatestamp()); // Recycle to use for the platform name freeCharString(stringBuffer); freeCharString(versionString); if(isExecutable64Bit()) { logWarn("Running in 64-bit mode, this is experimental. Hold on to your hats!"); } // Prevent a bunch of silly work in case the log level isn't debug if(isLogLevelAtLeast(LOG_DEBUG)) { stringBuffer = getPlatformName(); logDebug("Host platform is %s (%s)", getShortPlatformName(), stringBuffer->data); logDebug("Application is %d-bit", isExecutable64Bit() ? 64 : 32); freeCharString(stringBuffer); stringBuffer = newCharString(); for(i = 1; i < argc; i++) { space = strchr(argv[i], ' '); if(space != NULL) { charStringAppendCString(stringBuffer, "\""); } charStringAppendCString(stringBuffer, argv[i]); if(space != NULL) { charStringAppendCString(stringBuffer, "\""); } charStringAppendCString(stringBuffer, " "); } logDebug("Launched with options: %s", stringBuffer->data); freeCharString(stringBuffer); } }
static void processPlatformAttribute(wxXmlNode *node) { wxString s; bool isok; wxXmlNode *c = node->GetChildren(); while (c) { isok = false; if (!c->GetAttribute("platform", &s)) isok = true; else { wxStringTokenizer tkn(s, " |"); while (!isok && tkn.HasMoreTokens()) { if (tkn.GetNextToken().compare(getPlatformName()) == 0) isok = true; } } if (isok) { processPlatformAttribute(c); c = c->GetNext(); } else { wxXmlNode *c2 = c->GetNext(); node->RemoveChild(c); delete c; c = c2; } } }
// Initializes the OpenCL objects. bool init_opencl(const int maxInputSize, const int maxOutputSize, const int maxWeightSize, const int maxBiasSize) { cl_int status; if (!setCwdToExeDir()) { return false; } // Get the OpenCL platform. platform = findPlatform("Altera"); if (platform == NULL) { printf("ERROR: Unable to find Altera OpenCL platform.\n"); return false; } printf("Platform: %s\n", getPlatformName(platform).c_str()); // Query the available OpenCL devices. scoped_array<cl_device_id> devices; cl_uint num_devices; devices.reset(getDevices(platform, CL_DEVICE_TYPE_ALL, &num_devices)); // We'll just use the first device. device = devices[0]; printf("Device: %s\n", getDeviceName(device).c_str()); // Create the context. context = clCreateContext(NULL, 1, &device, &oclContextCallback, NULL, &status); checkError(status, "Failed to create context"); // Create the command queue. queue = clCreateCommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE, &status); checkError(status, "Failed to create command queue"); // Create the program. std::string binary_file = getBoardBinaryFile("waifu2x", device); printf("Using AOCX: %s\n", binary_file.c_str()); program = createProgramFromBinary(context, binary_file.c_str(), &device, 1); // Build the program that was just created. status = clBuildProgram(program, 0, NULL, "", NULL, NULL); checkError(status, "Failed to build program"); // Create the kernel - name passed in here must match kernel name in the // original CL file, that was compiled into an AOCX file using the AOC tool const char *kernel_name = "waifu2x"; // Kernel name, as defined in the CL file kernel = clCreateKernel(program, kernel_name, &status); checkError(status, "Failed to create kernel"); input_buf = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_BANK_1_ALTERA, maxInputSize * sizeof(float), NULL, &status); checkError(status, "Failed to create buffer for input"); weight_buf = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_BANK_2_ALTERA, maxWeightSize * sizeof(float), NULL, &status); checkError(status, "Failed to create buffer for weight"); bias_buf = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_BANK_2_ALTERA, maxBiasSize * sizeof(double), NULL, &status); checkError(status, "Failed to create buffer for bias"); output_buf = clCreateBuffer(context, CL_MEM_WRITE_ONLY | CL_MEM_BANK_1_ALTERA, maxOutputSize * sizeof(float), NULL, &status); checkError(status, "Failed to create buffer for output"); return true; }
void Device::print() { const int cpu_features = getCPUFeatures(); std::cout << std::endl; std::cout << "Embree Ray Tracing Kernels " << RTC_VERSION_STRING << " (" << RTC_HASH << ")" << std::endl; std::cout << " Compiler : " << getCompilerName() << std::endl; std::cout << " Build : "; #if defined(DEBUG) std::cout << "Debug " << std::endl; #else std::cout << "Release " << std::endl; #endif std::cout << " Platform : " << getPlatformName() << std::endl; std::cout << " CPU : " << stringOfCPUModel(getCPUModel()) << " (" << getCPUVendor() << ")" << std::endl; std::cout << " Threads : " << getNumberOfLogicalThreads() << std::endl; std::cout << " ISA : " << stringOfCPUFeatures(cpu_features) << std::endl; std::cout << " Targets : " << supportedTargetList(cpu_features) << std::endl; const bool hasFTZ = _mm_getcsr() & _MM_FLUSH_ZERO_ON; const bool hasDAZ = _mm_getcsr() & _MM_DENORMALS_ZERO_ON; std::cout << " MXCSR : " << "FTZ=" << hasFTZ << ", DAZ=" << hasDAZ << std::endl; std::cout << " Config" << std::endl; std::cout << " Threads : " << (numThreads ? toString(numThreads) : std::string("default")) << std::endl; std::cout << " ISA : " << stringOfCPUFeatures(enabled_cpu_features) << std::endl; std::cout << " Targets : " << supportedTargetList(enabled_cpu_features) << " (supported)" << std::endl; std::cout << " " << getEnabledTargets() << " (compile time enabled)" << std::endl; std::cout << " Features: " << getEmbreeFeatures() << std::endl; std::cout << " Tasking : "; #if defined(TASKING_TBB) std::cout << "TBB" << TBB_VERSION_MAJOR << "." << TBB_VERSION_MINOR << " "; std::cout << "TBB_header_interface_" << TBB_INTERFACE_VERSION << " TBB_lib_interface_" << tbb::TBB_runtime_interface_version() << " "; #endif #if defined(TASKING_INTERNAL) std::cout << "internal_tasking_system "; #endif #if defined(TASKING_PPL) std::cout << "PPL "; #endif std::cout << std::endl; /* check of FTZ and DAZ flags are set in CSR */ if (!hasFTZ || !hasDAZ) { #if !defined(_DEBUG) if (State::verbosity(1)) #endif { std::cout << std::endl; std::cout << "================================================================================" << std::endl; std::cout << " WARNING: \"Flush to Zero\" or \"Denormals are Zero\" mode not enabled " << std::endl << " in the MXCSR control and status register. This can have a severe " << std::endl << " performance impact. Please enable these modes for each application " << std::endl << " thread the following way:" << std::endl << std::endl << " #include \"xmmintrin.h\"" << std::endl << " #include \"pmmintrin.h\"" << std::endl << std::endl << " _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);" << std::endl << " _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);" << std::endl; std::cout << "================================================================================" << std::endl; std::cout << std::endl; } } std::cout << std::endl; }
RTCORE_API void rtcInit(const char* cfg) { cout << "in rtcInit " << endl; Lock<MutexSys> lock(g_mutex); TRACE(rtcInit); CATCH_BEGIN; if (g_initialized) { g_mutex.unlock(); process_error(RTC_INVALID_OPERATION,"already initialized"); g_mutex.lock(); return; } g_initialized = true; /* reset global state */ initSettings(); if (cfg != NULL) { size_t pos = 0; do { std::string tok = parseIdentifier (cfg,pos); if (tok == "threads" && parseSymbol(cfg,'=',pos)) { g_numThreads = parseInt(cfg,pos); #if defined(__MIC__) if (!(g_numThreads == 1 || (g_numThreads % 4) == 0)) { g_mutex.unlock(); process_error(RTC_INVALID_OPERATION,"Xeon Phi supports only number of threads % 4 == 0, or threads == 1"); g_mutex.lock(); return; } #endif } else if (tok == "isa" && parseSymbol (cfg,'=',pos)) { std::string isa = parseIdentifier (cfg,pos); if (isa == "sse" ) cpu_features = SSE; else if (isa == "sse2") cpu_features = SSE2; else if (isa == "sse3") cpu_features = SSE3; else if (isa == "ssse3") cpu_features = SSSE3; else if (isa == "sse41") cpu_features = SSE41; else if (isa == "sse42") cpu_features = SSE42; else if (isa == "avx") cpu_features = AVX; else if (isa == "avxi") cpu_features = AVXI; else if (isa == "avx2") cpu_features = AVX2; } else if ((tok == "tri_accel" || tok == "accel") && parseSymbol (cfg,'=',pos)) g_tri_accel = parseIdentifier (cfg,pos); else if ((tok == "tri_builder" || tok == "builder") && parseSymbol (cfg,'=',pos)) g_tri_builder = parseIdentifier (cfg,pos); else if ((tok == "tri_traverser" || tok == "traverser") && parseSymbol (cfg,'=',pos)) g_tri_traverser = parseIdentifier (cfg,pos); else if ((tok == "tri_accel_mb" || tok == "accel_mb") && parseSymbol (cfg,'=',pos)) g_tri_accel = parseIdentifier (cfg,pos); else if ((tok == "tri_builder_mb" || tok == "builder_mb") && parseSymbol (cfg,'=',pos)) g_tri_builder = parseIdentifier (cfg,pos); else if ((tok == "tri_traverser_mb" || tok == "traverser_mb") && parseSymbol (cfg,'=',pos)) g_tri_traverser = parseIdentifier (cfg,pos); else if (tok == "hair_accel" && parseSymbol (cfg,'=',pos)) g_hair_accel = parseIdentifier (cfg,pos); else if (tok == "hair_builder" && parseSymbol (cfg,'=',pos)) g_hair_builder = parseIdentifier (cfg,pos); else if (tok == "hair_traverser" && parseSymbol (cfg,'=',pos)) g_hair_traverser = parseIdentifier (cfg,pos); else if (tok == "hair_builder_replication_factor" && parseSymbol (cfg,'=',pos)) g_hair_builder_replication_factor = parseInt (cfg,pos); else if (tok == "verbose" && parseSymbol (cfg,'=',pos)) g_verbose = parseInt (cfg,pos); else if (tok == "benchmark" && parseSymbol (cfg,'=',pos)) g_benchmark = parseInt (cfg,pos); else if (tok == "flags") { g_scene_flags = 0; if (parseSymbol (cfg,'=',pos)) { do { std::string flag = parseIdentifier (cfg,pos); if (flag == "static" ) g_scene_flags |= RTC_SCENE_STATIC; else if (flag == "dynamic") g_scene_flags |= RTC_SCENE_DYNAMIC; else if (flag == "compact") g_scene_flags |= RTC_SCENE_COMPACT; else if (flag == "coherent") g_scene_flags |= RTC_SCENE_COHERENT; else if (flag == "incoherent") g_scene_flags |= RTC_SCENE_INCOHERENT; else if (flag == "high_quality") g_scene_flags |= RTC_SCENE_HIGH_QUALITY; else if (flag == "robust") g_scene_flags |= RTC_SCENE_ROBUST; } while (parseSymbol (cfg,',',pos)); } } } while (findNext (cfg,',',pos)); } if (g_verbose >= 1) { std::cout << "Embree Ray Tracing Kernels " << __EMBREE_VERSION__ << " (" << __DATE__ << ")" << std::endl; std::cout << " Compiler : " << getCompilerName() << std::endl; std::cout << " Platform : " << getPlatformName() << std::endl; std::cout << " CPU : " << stringOfCPUFeatures(getCPUFeatures()) << std::endl; std::cout << " Features : "; #if defined(__USE_RAY_MASK__) std::cout << "raymasks "; #endif #if defined (__BACKFACE_CULLING__) std::cout << "backfaceculling "; #endif #if defined(__INTERSECTION_FILTER__) std::cout << "intersection_filter "; #endif #if defined(__BUFFER_STRIDE__) std::cout << "bufferstride "; #endif std::cout << std::endl; #if defined (__MIC__) #if defined(__BUFFER_STRIDE__) std::cout << " WARNING: enabled 'bufferstride' support will lower BVH build performance" << std::endl; #endif #endif } /* CPU has to support at least SSE2 */ #if !defined (__MIC__) if (!has_feature(SSE2)) { g_mutex.unlock(); process_error(RTC_UNSUPPORTED_CPU,"CPU does not support SSE2"); g_mutex.lock(); return; } #endif g_error = createTls(); g_error_function = NULL; init_globals(); cout << "in rtcInit(), BVH4Register() " << endl; #if !defined(__MIC__) cout << "BVH4Register()" << endl; BVH4Register(); #else cout << "BVH4iRegister() " << endl; BVH4iRegister(); #endif cout << "BVH4MBRegister() " << endl; BVH4MBRegister(); BVH4HairRegister(); #if defined(__TARGET_AVX__) cout << "BVH8Register() " << endl; if (has_feature(AVX)) { BVH8Register(); } #endif InstanceIntersectorsRegister(); //if (g_verbose >= 2) printSettings(); TaskScheduler::create(g_numThreads); cout << " end rtcInit " << endl; CATCH_END; }
void initKernBootStruct( void ) { Node *node; int nameLen; static int init_done = 0; if ( !init_done ) { bootArgs = (boot_args *)malloc(sizeof(boot_args)); bootArgsPreLion = (boot_args_pre_lion *)malloc(sizeof(boot_args_pre_lion)); bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t)); if (bootArgs == 0 || bootInfo == 0) stop("Couldn't allocate boot info\n"); bzero(bootArgs, sizeof(boot_args)); bzero(bootArgsPreLion, sizeof(boot_args_pre_lion)); bzero(bootInfo, sizeof(PrivateBootInfo_t)); // Get system memory map. Also update the size of the // conventional/extended memory for backwards compatibility. bootInfo->memoryMapCount = getMemoryMap( bootInfo->memoryMap, kMemoryMapCountMax, (unsigned long *) &bootInfo->convmem, (unsigned long *) &bootInfo->extmem ); if ( bootInfo->memoryMapCount == 0 ) { // BIOS did not provide a memory map, systems with // discontiguous memory or unusual memory hole locations // may have problems. bootInfo->convmem = getConventionalMemorySize(); bootInfo->extmem = getExtendedMemorySize(); } bootInfo->configEnd = bootInfo->config; bootArgs->Video.v_display = VGA_TEXT_MODE; DT__Initialize(); node = DT__FindNode("/", true); if (node == 0) { stop("Couldn't create root node"); } getPlatformName(platformName); nameLen = strlen(platformName) + 1; DT__AddProperty(node, "compatible", nameLen, platformName); DT__AddProperty(node, "model", nameLen, platformName); gMemoryMapNode = DT__FindNode("/chosen/memory-map", true); bootArgs->Version = kBootArgsVersion; bootArgs->Revision = kBootArgsRevision; bootArgsPreLion->Version = kBootArgsPreLionVersion; bootArgsPreLion->Revision = kBootArgsPreLionRevision; init_done = 1; } }
Int32 MainApplication::run(int argc, char **argv) { //Get the date/time run _DateTimeRun = boost::posix_time::second_clock::local_time(); //Get the path to the command BoostPath CommandPath(argv[0]); if(!CommandPath.is_complete() && !CommandPath.has_root_directory()) { CommandPath = boost::filesystem::complete(CommandPath); } CommandPath.normalize(); //Parse the Program arguments boost::program_options::variables_map OptionsVariableMap; try { boost::program_options::store(boost::program_options::command_line_parser(argc, argv). options(_OptionsDescription). #ifdef __APPLE__ extra_parser(procSerialNumParser). #endif positional(_PositionalOptions).run(), OptionsVariableMap); boost::program_options::notify(OptionsVariableMap); } catch(boost::program_options::error& e) { std::cout << "Error parsing command line: " << e.what() << std::endl; printCommandLineHelp(); } //Check for the help argument if(OptionsVariableMap.count("help")) { printCommandLineHelp(); return 1; } //Setup the Logging LogLevel KELogLevel(LOG_NOTICE); if(OptionsVariableMap.count("log-level")) { KELogLevel = OptionsVariableMap["log-level"].as<LogLevel>(); } _LogFilePath = getLoggingDir() / BoostPath(boost::posix_time::to_iso_string(_DateTimeRun) + ".log"); //ISO date/time format if(OptionsVariableMap.count("log-file")) { _LogFilePath = BoostPath(OptionsVariableMap["log-file"].as<std::string>()); } if(OptionsVariableMap.count("disable-log")) { _EnableLogging = false; } if(OptionsVariableMap.count("disable-file-log")) { _LogToFile = false; } initializeLogging(_LogFilePath); osgLogP->setLogLevel(KELogLevel, true); osgLogP->setHeaderElem((LOG_TYPE_HEADER | LOG_FUNCNAME_HEADER), true); //Check if the last run crashed if(didCrashLastExecution()) { handleCrashLastExecution(); } //Create a file to indicate if a crash occurs createCrashIndicationFile(); // Set up Settings //Check for the settings file if(OptionsVariableMap.count("settings-file")) { setSettingsLoadFile(BoostPath(OptionsVariableMap["settings-file"].as<std::string>())); } else { //Use default location setSettingsLoadFile(getUserAppDataDir() / BoostPath("KEDefaultSettings.xml")); } loadSettings(getSettingsLoadFile()); //Cleanup the Logging Directory cleanupLoggingDir(); //If the settings aren't being overriden by the command-line options //then set the logging with the settings values if(!OptionsVariableMap.count("log-level")) { osgLogP->setLogLevel(static_cast<LogLevel>(getSettings().get<UInt8>("logging.level")), true); } osgLogP->setHeaderElem(getSettings().get<UInt32>("logging.header_elements"), true); //Initialize OpenSG initOpenSG(argc,argv); //Log information about the Engine { PLOG << "Starting Kabala Engine:" << std::endl; OSG::indentLog(4,PLOG); PLOG << "Arguments: "; for(UInt32 i(0) ; i<argc ; ++i) { PLOG << argv[i] << " "; } PLOG << std::endl; OSG::indentLog(4,PLOG); PLOG << "System:" << std::endl; OSG::indentLog(8,PLOG); PLOG << "Operating System: " << getPlatformName() << std::endl; OSG::indentLog(8,PLOG); PLOG << "Processor: " << getPlatformProcessors() << std::endl; OSG::indentLog(8,PLOG); PLOG << "RAM: " << getPlatformRAM() << std::endl; OSG::indentLog(4,PLOG); PLOG << "Time: " << to_simple_string(_DateTimeRun) << std::endl; OSG::indentLog(4,PLOG); PLOG << "Version: " << getKabalaEngineVersion() << std::endl; OSG::indentLog(8,PLOG); PLOG << "Revision: " << getKabalaEngineBuildRepositoryRevision() << std::endl; OSG::indentLog(8,PLOG); PLOG << "Build Type: " << getKabalaEngineBuildType() << std::endl; OSG::indentLog(4,PLOG); PLOG << "Working Directory: " << boost::filesystem::current_path().string() << std::endl; OSG::indentLog(4,PLOG); PLOG << "Executable Directory: " << CommandPath.parent_path().string() << std::endl; OSG::indentLog(4,PLOG); PLOG << "Settings File: " << getSettingsLoadFile().string() << std::endl; OSG::indentLog(4,PLOG); PLOG << "Logging: " << (_EnableLogging ? "Enabled" : "Disabled" ) << std::endl; if(_EnableLogging) { OSG::indentLog(8,PLOG); PLOG << "Log File: " << (_LogToFile ? _LogFilePath.string() : "Disabled" ) << std::endl; } } //Check if the Data Directory exists if(!boost::filesystem::exists(getSettings().get<BoostPath>("basic.data.directory"))) { BoostPath DataDirPath(getSettings().get<BoostPath>("basic.data.directory")); DataDirPath = boost::filesystem::complete(DataDirPath); DataDirPath.normalize(); SWARNING << "Could not find Application Data directory: \"" << DataDirPath.string() << "\" specified in the Settings file because the directory doesn't exist." << std::endl; //Try to find the data directory in a few locations std::vector<BoostPath> PathsToTry; #ifdef __APPLE__ PathsToTry.push_back(CommandPath.parent_path() / BoostPath("../Resources") / EngineAppDataDirectory); //Path to try for OS X Bundles PathsToTry.push_back(CommandPath.parent_path() / BoostPath("../Resources/share") / EngineAppDataDirectory); //Path to try for OS X Bundles #endif PathsToTry.push_back(BoostPath("/usr/local/share") / EngineAppDataDirectory); PathsToTry.push_back(BoostPath("/usr/share") / EngineAppDataDirectory); PathsToTry.push_back(CommandPath.parent_path() / EngineAppDataDirectory); PathsToTry.push_back(CommandPath.parent_path() / BoostPath("..") / EngineAppDataDirectory); PathsToTry.push_back(CommandPath.parent_path() / BoostPath("../share") / EngineAppDataDirectory); for(UInt32 i(0) ; i<PathsToTry.size() ; ++i) { SNOTICE << "Looking for Data directory in: " << PathsToTry[i].string() << std::endl; if(boost::filesystem::exists(PathsToTry[i])) { PNOTICE << "FOUND" << std::endl; PathsToTry[i].normalize(); getSettings().put("basic.data.directory",PathsToTry[i]); break; } else { PNOTICE << "NOT FOUND" << std::endl; } } } if(!boost::filesystem::exists(getSettings().get<BoostPath>("basic.data.directory"))) { SWARNING << "Could not find Application Data directory: \"" << getSettings().get<BoostPath>("basic.data.directory").string() << "\" because the directory doesn't exist." << std::endl; } else { SLOG << "Using Application Data directory: \"" << getSettings().get<BoostPath>("basic.data.directory").string() << "\"" << std::endl; } // Set up Window WindowEventProducerUnrecPtr MainWindow(createNativeWindow()); setMainWindow(MainWindow); setName(getMainWindow(),"__KABALA_ENGINE_WINDOW_EVENT_PRODUCER"); //If Fullscreen option -> Fullscreen if(OptionsVariableMap.count("fullscreen")) { getMainWindow()->setFullscreen(true); } //If no-fullscreen -> not Fullscreen else if(OptionsVariableMap.count("no-fullscreen")) { getMainWindow()->setFullscreen(false); } //else -> use the value in the settings else { getMainWindow()->setFullscreen(getSettings().get<bool>("basic.window.fullscreen")); } getMainWindow()->initWindow(); _WindowClosingConnection = getMainWindow()->connectWindowClosing(boost::bind(&MainApplication::handleWindowClosing, this, _1)); _WindowClosedConnection = getMainWindow()->connectWindowClosed(boost::bind(&MainApplication::handleWindowClosed, this, _1)); // Initialize the LookAndFeelManager to enable default settings KELookAndFeel::the()->init(); //Open Window Vec2f WindowSize(getSettings().get<Vec2f>("basic.window.size")); if(getSettings().get<Vec2f>("basic.window.size").x() <= 1.0f ) { WindowSize[0] = getMainWindow()->getDesktopSize().x() * getSettings().get<Vec2f>("basic.window.size").x(); } if(getSettings().get<Vec2f>("basic.window.size").y() <= 1.0f ) { WindowSize[1] = getMainWindow()->getDesktopSize().y() * getSettings().get<Vec2f>("basic.window.size").y(); } Pnt2f WindowPos(getSettings().get<Pnt2f>("basic.window.position")); if(getSettings().get<Pnt2f>("basic.window.position").x() < 0.0f ) { WindowPos[0] = (getMainWindow()->getDesktopSize().x() - WindowSize.x()) * 0.5f; } if(getSettings().get<Pnt2f>("basic.window.position").y() < 0.0f ) { WindowPos[1] = (getMainWindow()->getDesktopSize().y() - WindowSize.y()) * 0.5f; } getMainWindow()->openWindow(WindowPos, WindowSize, "Kabala Engine"); //Store a pointer to the application thread //_ApplicationThread = dynamic_cast<OSG::Thread *>(OSG::ThreadManager::getAppThread()); //Create the rendering thread //_RenderThread = OSG::dynamic_pointer_cast<OSG::Thread>(OSG::ThreadManager::the()->getThread("__KABALA_ENGINE_RENDER_THREAD", true)); //Create the loading thread //_LoadingThread = OSG::dynamic_pointer_cast<OSG::Thread>(OSG::ThreadManager::the()->getThread("__KABALA_ENGINE_LOADING_THREAD", true)); //Draw the loading thread activateLoadingScreen(); //Load the Project file, if given if(OptionsVariableMap.count("project-file")) { loadProject(BoostPath(OptionsVariableMap["project-file"].as<std::string>())); } else if(getSettings().get<bool>("basic.load_most_recent_project")) { boost::optional<BoostPath> LastOpenedProjectFile = getSettings().get_optional<BoostPath>("basic.last_opened_project"); if(LastOpenedProjectFile) { loadProject(LastOpenedProjectFile.get()); commitChanges(); } } if(getProject() == NULL) { //Project Failed to load, or file didn't exist ProjectRecPtr NewProject = createDefaultProject(); setProject(NewProject); } //Detach the loading screen detachLoadingScreen(); #ifdef BUILD_WITH_WORLD_BUILDER if(OptionsVariableMap.count("builder")) { attachBuilder(); } else #endif if(OptionsVariableMap.count("play")) { attachPlayer(); if(OptionsVariableMap.count("debug")) { dynamic_cast<ApplicationPlayer*>(getPlayerMode())->enableDebug(true); } } else { #ifdef BUILD_WITH_WORLD_BUILDER if(getSettings().get<std::string>("basic.initial_mode").compare(std::string("builder")) == 0) { attachBuilder(); } else #endif if(getSettings().get<std::string>("basic.initial_mode").compare(std::string("play")) == 0) { attachPlayer(); if(OptionsVariableMap.count("debug") || getSettings().get<bool>("player.debugger.initially_active")) { dynamic_cast<ApplicationPlayer*>(getPlayerMode())->enableDebug(true); } } else { attachStartScreen(); } } //Start the render thread on aspect 1 //_RenderThread->runFunction(MainApplication::mainRenderLoop, 1, NULL); //Start the loading thread on aspect 2 //_LoadingThread->runFunction(MainApplication::mainLoadingLoop, 2, NULL); //Main Loop getMainWindow()->mainLoop(); //Exited Main Loop //Save Settings saveSettings(getSettingsLoadFile()); SLOG << "Stopping Kabala Engine" << std::endl; OSG::indentLog(4,PLOG); PLOG << "Time: " << to_simple_string(boost::posix_time::second_clock::local_time()) << std::endl; //OSG exit OSG::osgExit(); //Uninitialize logging uninitializeLogging(); //Create a file to indicate if a crash occurs removeCrashIndicationFile(); return 0; }
std::string IDE::getSettingsFilename() { return "settings." + getPlatformName() + ".lua"; }
Array<T> leastSquares(const Array<T> &a, const Array<T> &b) { int M = a.dims()[0]; int N = a.dims()[1]; int K = b.dims()[1]; int MN = std::min(M, N); Array<T> B = createEmptyArray<T>(dim4()); trsm_func<T> gpu_trsm; cl_event event; cl_command_queue queue = getQueue()(); if (M < N) { #define UNMQR 0 // FIXME: UNMQR == 1 should be faster but does not work // Least squres for this case is solved using the following // solve(A, B) == matmul(Q, Xpad); // Where: // Xpad == pad(Xt, N - M, 1); // Xt == tri_solve(R1, B); // R1 == R(seq(M), seq(M)); // transpose(A) == matmul(Q, R); // QR is performed on the transpose of A Array<T> A = transpose<T>(a, true); #if UNMQR B = padArray<T, T>(b, dim4(N, K), scalar<T>(0)); B.resetDims(dim4(M, K)); #else B = copyArray<T>(b); #endif int NB = magma_get_geqrf_nb<T>(A.dims()[1]); int NUM = (2*MN + ((M+31)/32)*32)*NB; Array<T> tmp = createEmptyArray<T>(dim4(NUM)); std::vector<T> h_tau(MN); int info = 0; cl::Buffer *dA = A.get(); cl::Buffer *dT = tmp.get(); cl::Buffer *dB = B.get(); magma_geqrf3_gpu<T>(A.dims()[0], A.dims()[1], (*dA)(), A.getOffset(), A.strides()[1], &h_tau[0], (*dT)(), tmp.getOffset(), getQueue()(), &info); A.resetDims(dim4(M, M)); magmablas_swapdblk<T>(MN-1, NB, (*dA)(), A.getOffset(), A.strides()[1], 1, (*dT)(), tmp.getOffset() + MN * NB, NB, 0, queue); gpu_trsm(clblasColumnMajor, clblasLeft, clblasUpper, clblasConjTrans, clblasNonUnit, B.dims()[0], B.dims()[1], scalar<T>(1), (*dA)(), A.getOffset(), A.strides()[1], (*dB)(), B.getOffset(), B.strides()[1], 1, &queue, 0, nullptr, &event); magmablas_swapdblk<T>(MN - 1, NB, (*dT)(), tmp.getOffset() + MN * NB, NB, 0, (*dA)(), A.getOffset(), A.strides()[1], 1, queue); #if UNMQR int lwork = (B.dims()[0]-A.dims()[0]+NB)*(B.dims()[1]+2*NB); std::vector<T> h_work(lwork); B.resetDims(dim4(N, K)); magma_unmqr_gpu<T>(MagmaLeft, MagmaNoTrans, B.dims()[0], B.dims()[1], A.dims()[0], (*dA)(), A.getOffset(), A.strides()[1], &h_tau[0], (*dB)(), B.getOffset(), B.strides()[1], &h_work[0], lwork, (*dT)(), tmp.getOffset(), NB, queue, &info); #else A.resetDims(dim4(N, M)); magma_ungqr_gpu<T>(A.dims()[0], A.dims()[1], std::min(M, N), (*dA)(), A.getOffset(), A.strides()[1], &h_tau[0], (*dT)(), tmp.getOffset(), NB, queue, &info); B = matmul(A, B, AF_MAT_NONE, AF_MAT_NONE); #endif } else if (M > N) { // Least squres for this case is solved using the following // solve(A, B) == tri_solve(R1, Bt); // Where: // R1 == R(seq(N), seq(N)); // Bt == matmul(transpose(Q1), B); // Q1 == Q(span, seq(N)); // A == matmul(Q, R); Array<T> A = copyArray<T>(a); B = copyArray(b); int MN = std::min(M, N); int NB = magma_get_geqrf_nb<T>(M); int NUM = (2*MN + ((N+31)/32)*32)*NB; Array<T> tmp = createEmptyArray<T>(dim4(NUM)); std::vector<T> h_tau(NUM); int info = 0; cl::Buffer *A_buf = A.get(); cl::Buffer *B_buf = B.get(); cl::Buffer *dT = tmp.get(); magma_geqrf3_gpu<T>(M, N, (*A_buf)(), A.getOffset(), A.strides()[1], &h_tau[0], (*dT)(), tmp.getOffset(), getQueue()(), &info); int NRHS = B.dims()[1]; int lhwork = (M - N + NB) * (NRHS + NB) + NRHS * NB; std::vector<T> h_work(lhwork); h_work[0] = scalar<T>(lhwork); magma_unmqr_gpu<T>(MagmaLeft, MagmaConjTrans, M, NRHS, N, (*A_buf)(), A.getOffset(), A.strides()[1], &h_tau[0], (*B_buf)(), B.getOffset(), B.strides()[1], &h_work[0], lhwork, (*dT)(), tmp.getOffset(), NB, queue, &info); magmablas_swapdblk<T>(MN - 1, NB, (*A_buf)(), A.getOffset(), A.strides()[1], 1, (*dT)(), tmp.getOffset() + NB * MN, NB, 0, queue); std::string pName = getPlatformName(getDevice()); if(pName.find("NVIDIA") != std::string::npos) { Array<T> AT = transpose<T>(A, true); cl::Buffer* AT_buf = AT.get(); gpu_trsm(clblasColumnMajor, clblasLeft, clblasLower, clblasConjTrans, clblasNonUnit, N, NRHS, scalar<T>(1), (*AT_buf)(), AT.getOffset(), AT.strides()[1], (*B_buf)(), B.getOffset(), B.strides()[1], 1, &queue, 0, nullptr, &event); } else { gpu_trsm(clblasColumnMajor, clblasLeft, clblasUpper, clblasNoTrans, clblasNonUnit, N, NRHS, scalar<T>(1), (*A_buf)(), A.getOffset(), A.strides()[1], (*B_buf)(), B.getOffset(), B.strides()[1], 1, &queue, 0, nullptr, &event); } B.resetDims(dim4(N, K)); } return B; }
int processBootOptions() { const char * cp = gBootArgs; const char * val = 0; const char * kernel; int cnt; int userCnt; int cntRemaining; char * argP; char uuidStr[64]; BOOL uuidSet = NO; char * configKernelFlags; char * valueBuffer; valueBuffer = (char *)malloc(VALUE_SIZE); skipblanks( &cp ); // Update the unit and partition number. if ( gBootVolume ) { if ( gBootVolume->flags & kBVFlagForeignBoot ) { readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, (void *) 0x7c00 ); // // Setup edx, and signal intention to chain load the // foreign booter. // chainbootdev = gBootVolume->biosdev; chainbootflag = 1; return 1; } bootInfo->kernDev &= ~((B_UNITMASK << B_UNITSHIFT ) | (B_PARTITIONMASK << B_PARTITIONSHIFT)); bootInfo->kernDev |= MAKEKERNDEV( 0, /* unit */ BIOS_DEV_UNIT(gBootVolume), /* partition */ gBootVolume->part_no ); } // Load config table specified by the user, or use the default. if (getValueForBootKey( cp, "config", &val, &cnt ) == FALSE) { val = 0; cnt = 0; } loadSystemConfig(val, cnt); if ( !sysConfigValid ) return -1; // Use the kernel name specified by the user, or fetch the name // in the config table, or use the default if not specified. // Specifying a kernel name on the command line, or specifying // a non-default kernel name in the config file counts as // overriding the kernel, which causes the kernelcache not // to be used. gOverrideKernel = NO; if (( kernel = extractKernelName((char **)&cp) )) { strcpy( bootInfo->bootFile, kernel ); gOverrideKernel = YES; } else { if ( getValueForKey( kKernelNameKey, &val, &cnt ) ) { strlcpy( bootInfo->bootFile, val, cnt+1 ); if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) { gOverrideKernel = YES; } } else { strcpy( bootInfo->bootFile, kDefaultKernel ); } } cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space argP = bootArgs->CommandLine; // Get config table kernel flags, if not ignored. if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) == TRUE || getValueForKey( kKernelFlagsKey, &val, &cnt ) == FALSE) { val = ""; cnt = 0; } configKernelFlags = (char *)malloc(cnt + 1); strlcpy(configKernelFlags, val, cnt + 1); if (processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, 0)) { // boot-uuid was set either on the command-line // or in the config file. uuidSet = YES; } else { if (GetFSUUID(bootInfo->bootFile, uuidStr) == 0) { verbose("Setting boot-uuid to: %s\n", uuidStr); copyArgument(kBootUUIDKey, uuidStr, strlen(uuidStr), &argP, &cntRemaining); uuidSet = YES; } } if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice)) { cnt = 0; if ( getValueForKey( kBootDeviceKey, &val, &cnt)) { valueBuffer[0] = '*'; cnt++; strlcpy(valueBuffer + 1, val, cnt); val = valueBuffer; } else { if (uuidSet) { val = "*uuid"; cnt = 5; } else { // Don't set "rd=.." if there is no boot device key // and no UUID. val = ""; cnt = 0; } } if (cnt > 0) { copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining); } strlcpy( gRootDevice, val, (cnt + 1)); } if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gPlatformName)) { getPlatformName(gPlatformName); copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining); } if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) && !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) { if (gBootMode & kBootModeSafe) { copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining); } } // Store the merged kernel flags and boot args. cnt = strlen(configKernelFlags); if (cnt) { if (cnt > cntRemaining) { error("Warning: boot arguments too long, truncating\n"); cnt = cntRemaining; } strncpy(argP, configKernelFlags, cnt); argP[cnt++] = ' '; cntRemaining -= cnt; } userCnt = strlen(cp); if (userCnt > cntRemaining) { error("Warning: boot arguments too long, truncating\n"); userCnt = cntRemaining; } strncpy(&argP[cnt], cp, userCnt); argP[cnt+userCnt] = '\0'; gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt ) || getValueForKey( kSingleUserModeFlag, &val, &cnt ); gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt ) ) ? kBootModeSafe : kBootModeNormal; if ( getValueForKey( kOldSafeModeFlag, &val, &cnt ) ) { gBootMode = kBootModeSafe; } if ( getValueForKey( kMKextCacheKey, &val, &cnt ) ) { strlcpy(gMKextName, val, cnt + 1); } free(configKernelFlags); free(valueBuffer); return 0; }
void initKernBootStruct( void ) { static int init_done = 0; if ( !init_done ) { int convmem; // conventional memory int extmem; // extended memory unsigned long memoryMapCount = 0; bootArgs = (boot_args *)malloc(sizeof(boot_args)); bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t)); if (bootArgs == NULL || bootInfo == NULL) { stop("Couldn't allocate boot info\n"); return; } else { bzero(bootArgs, sizeof(boot_args)); bzero(bootInfo, sizeof(PrivateBootInfo_t)); // Get system memory map. Also update the size of the // conventional/extended memory for backwards compatibility. memoryMapCount = getMemoryMap( memoryMap, kMemoryMapCountMax, (unsigned long *) &convmem, (unsigned long *) &extmem ); if ( memoryMapCount == 0 ) { // BIOS did not provide a memory map, systems with // discontiguous memory or unusual memory hole locations // may have problems. convmem = getConventionalMemorySize(); extmem = getExtendedMemorySize(); } bootArgs->Video.v_display = VGA_TEXT_MODE; DT__Initialize(); { Node *node; node = DT__FindNode("/", true); if (node == 0) { stop("Couldn't create root node"); return; } getPlatformName(platformName, sizeof(platformName)); { int nameLen; nameLen = strlen(platformName) + 1; DT__AddProperty(node, "compatible", nameLen, platformName); DT__AddProperty(node, "model", nameLen, platformName); } } Node *gMemoryMapNode = DT__FindNode("/chosen/memory-map", true); set_env(envConvMem, convmem); set_env(envExtMem, extmem); set_env(envMemoryMap, (uint32_t)memoryMap); set_env(envMemoryMapCnt, memoryMapCount); set_env(envMemoryMapNode, (uint32_t)gMemoryMapNode); init_done = 1; } } }
jstring Java_opencl_executor_Executor_getPlatformName(JNIEnv * env, jclass) { auto name = getPlatformName(); return env->NewStringUTF(name.c_str()); }