static void set_type(PyTensorType& type_obj, Backend backend, ScalarType scalarType) { auto baseType = globalContext().type_registry[static_cast<int>(backend)][static_cast<int>(scalarType)].get(); type_obj.aten_type = baseType ? torch::autograd::VariableType::getType(*baseType) : nullptr; type_obj.layout = torch::getLayout(backend); type_obj.dtype = torch::getDtype(scalarType); type_obj.is_cuda = (backend == at::Backend::CUDA || backend == at::Backend::SparseCUDA); }
int main(int argc, char **argv) { CompilerOptions opts; for (int a=1;a<argc;a++) { if (argv[a][0]=='-') { if (strcmp(argv[a],"-o")==0) { if ((a+1)<argc) { opts.outputFile=argv[a+1]; } else { return Usage(); } a+=1; continue; } if (strcmp(argv[a],"-s")==0) { if ((a+1)<argc) { opts.symbolModifier=argv[a+1]; } else { return Usage(); } a+=1; continue; } if (strcmp(argv[a],"-t")==0) { opts.traceUnimplemented=1; } if (strcmp(argv[a],"-n")==0) { opts.generateDisassembly=0; } if (strcmp(argv[a],"-v")==0) { std::cout << "edl.exe " << EDL_COMPILER_VERSION << ":" << EDL_LANGUAGE_VERSION << std::endl; return 0; } if (strcmp(argv[a], "-g") == 0) { #if !defined(EDL_PLATFORM_ARM) opts.generateDebug = 1; #endif } if (strcmp(argv[a],"-h")==0 || strcmp(argv[a],"--help")==0) { return Usage(); } if (strncmp(argv[a],"-O",2)==0) { if (strlen(argv[a])==3) { opts.optimisationLevel=argv[a][2]-'0'; } else { return Usage(); } } } else { if (opts.inputFile==nullptr) { opts.inputFile=argv[a]; } else { return Usage(); } } } if (opts.inputFile == nullptr) { return Usage(); } if (resetFileInput(opts.inputFile) != 0) { std::cerr << "Unable to open " << opts.inputFile << " for reading." << std::endl; return 2; } int lexerError=yyparse(); if (lexerError || g_ProgramBlock==0) { std::cerr << "Error : Unable to parse input" << std::endl; return 1; } GlobalContext globalContext(opts); if (!globalContext.generateCode(*g_ProgramBlock)) { std::cerr << "Compilation Failed" << std::endl; return 2; } return 0; }
bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage) { if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":/cppeditor/CppEditor.mimetypes.xml"), errorMessage)) return false; addAutoReleasedObject(new CppEditorFactory); addAutoReleasedObject(new CppOutlineWidgetFactory); addAutoReleasedObject(new CppTypeHierarchyFactory); addAutoReleasedObject(new CppIncludeHierarchyFactory); addAutoReleasedObject(new CppSnippetProvider); m_quickFixProvider = new CppQuickFixAssistProvider; addAutoReleasedObject(m_quickFixProvider); registerQuickFixes(this); Context context(Constants::CPPEDITOR_ID); ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT); Command *cmd; ActionContainer *cppToolsMenu = ActionManager::actionContainer(CppTools::Constants::M_TOOLS_CPP); cmd = ActionManager::command(CppTools::Constants::SWITCH_HEADER_SOURCE); contextMenu->addAction(cmd); cmd = ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR); contextMenu->addAction(cmd); cppToolsMenu->addAction(cmd); QAction *openPreprocessorDialog = new QAction(tr("Additional Preprocessor Directives..."), this); cmd = ActionManager::registerAction(openPreprocessorDialog, Constants::OPEN_PREPROCESSOR_DIALOG, context); cmd->setDefaultKeySequence(QKeySequence()); connect(openPreprocessorDialog, SIGNAL(triggered()), this, SLOT(showPreProcessorDialog())); cppToolsMenu->addAction(cmd); QAction *switchDeclarationDefinition = new QAction(tr("Switch Between Function Declaration/Definition"), this); cmd = ActionManager::registerAction(switchDeclarationDefinition, Constants::SWITCH_DECLARATION_DEFINITION, context, true); cmd->setDefaultKeySequence(QKeySequence(tr("Shift+F2"))); connect(switchDeclarationDefinition, SIGNAL(triggered()), this, SLOT(switchDeclarationDefinition())); contextMenu->addAction(cmd); cppToolsMenu->addAction(cmd); cmd = ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR_IN_NEXT_SPLIT); cppToolsMenu->addAction(cmd); QAction *openDeclarationDefinitionInNextSplit = new QAction(tr("Open Function Declaration/Definition in Next Split"), this); cmd = ActionManager::registerAction(openDeclarationDefinitionInNextSplit, Constants::OPEN_DECLARATION_DEFINITION_IN_NEXT_SPLIT, context, true); cmd->setDefaultKeySequence(QKeySequence(Utils::HostOsInfo::isMacHost() ? tr("Meta+E, Shift+F2") : tr("Ctrl+E, Shift+F2"))); connect(openDeclarationDefinitionInNextSplit, SIGNAL(triggered()), this, SLOT(openDeclarationDefinitionInNextSplit())); cppToolsMenu->addAction(cmd); m_findUsagesAction = new QAction(tr("Find Usages"), this); cmd = ActionManager::registerAction(m_findUsagesAction, Constants::FIND_USAGES, context); cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U"))); connect(m_findUsagesAction, SIGNAL(triggered()), this, SLOT(findUsages())); contextMenu->addAction(cmd); cppToolsMenu->addAction(cmd); m_openTypeHierarchyAction = new QAction(tr("Open Type Hierarchy"), this); cmd = ActionManager::registerAction(m_openTypeHierarchyAction, Constants::OPEN_TYPE_HIERARCHY, context); cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+Shift+T") : tr("Ctrl+Shift+T"))); connect(m_openTypeHierarchyAction, SIGNAL(triggered()), this, SLOT(openTypeHierarchy())); contextMenu->addAction(cmd); cppToolsMenu->addAction(cmd); m_openIncludeHierarchyAction = new QAction(tr("Open Include Hierarchy"), this); cmd = Core::ActionManager::registerAction(m_openIncludeHierarchyAction, Constants::OPEN_INCLUDE_HIERARCHY, context); cmd->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+Shift+I") : tr("Ctrl+Shift+I"))); connect(m_openIncludeHierarchyAction, SIGNAL(triggered()), this, SLOT(openIncludeHierarchy())); contextMenu->addAction(cmd); cppToolsMenu->addAction(cmd); // Refactoring sub-menu Context globalContext(Core::Constants::C_GLOBAL); Command *sep = contextMenu->addSeparator(globalContext); sep->action()->setObjectName(QLatin1String(Constants::M_REFACTORING_MENU_INSERTION_POINT)); contextMenu->addSeparator(globalContext); m_renameSymbolUnderCursorAction = new QAction(tr("Rename Symbol Under Cursor"), this); cmd = ActionManager::registerAction(m_renameSymbolUnderCursorAction, Constants::RENAME_SYMBOL_UNDER_CURSOR, context); cmd->setDefaultKeySequence(QKeySequence(tr("CTRL+SHIFT+R"))); connect(m_renameSymbolUnderCursorAction, SIGNAL(triggered()), this, SLOT(renameSymbolUnderCursor())); cppToolsMenu->addAction(cmd); // Update context in global context cppToolsMenu->addSeparator(globalContext); m_reparseExternallyChangedFiles = new QAction(tr("Reparse Externally Changed Files"), this); cmd = ActionManager::registerAction(m_reparseExternallyChangedFiles, Constants::UPDATE_CODEMODEL, globalContext); CppTools::CppModelManager *cppModelManager = CppTools::CppModelManager::instance(); connect(m_reparseExternallyChangedFiles, SIGNAL(triggered()), cppModelManager, SLOT(updateModifiedSourceFiles())); cppToolsMenu->addAction(cmd); cppToolsMenu->addSeparator(globalContext); QAction *inspectCppCodeModel = new QAction(tr("Inspect C++ Code Model..."), this); cmd = ActionManager::registerAction(inspectCppCodeModel, Constants::INSPECT_CPP_CODEMODEL, globalContext); cmd->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+Shift+F12") : tr("Ctrl+Shift+F12"))); connect(inspectCppCodeModel, SIGNAL(triggered()), this, SLOT(inspectCppCodeModel())); cppToolsMenu->addAction(cmd); contextMenu->addSeparator(context); cmd = ActionManager::command(TextEditor::Constants::AUTO_INDENT_SELECTION); contextMenu->addAction(cmd); cmd = ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION); contextMenu->addAction(cmd); connect(ProgressManager::instance(), SIGNAL(taskStarted(Core::Id)), this, SLOT(onTaskStarted(Core::Id))); connect(ProgressManager::instance(), SIGNAL(allTasksFinished(Core::Id)), this, SLOT(onAllTasksFinished(Core::Id))); readSettings(); return true; }
bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage) { if (!ICore::mimeDatabase()->addMimeTypes(QLatin1String(":/glsleditor/GLSLEditor.mimetypes.xml"), errorMessage)) return false; // m_modelManager = new ModelManager(this); // addAutoReleasedObject(m_modelManager); addAutoReleasedObject(new GLSLHoverHandler(this)); m_editor = new GLSLEditorFactory(this); addObject(m_editor); addAutoReleasedObject(new GLSLCompletionAssistProvider); m_actionHandler = new TextEditorActionHandler(Constants::C_GLSLEDITOR_ID, TextEditorActionHandler::Format | TextEditorActionHandler::UnCommentSelection | TextEditorActionHandler::UnCollapseAll); m_actionHandler->initializeActions(); ActionContainer *contextMenu = ActionManager::createMenu(GLSLEditor::Constants::M_CONTEXT); ActionContainer *glslToolsMenu = ActionManager::createMenu(Id(Constants::M_TOOLS_GLSL)); glslToolsMenu->setOnAllDisabledBehavior(ActionContainer::Hide); QMenu *menu = glslToolsMenu->menu(); //: GLSL sub-menu in the Tools menu menu->setTitle(tr("GLSL")); ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(glslToolsMenu); Command *cmd = 0; // Insert marker for "Refactoring" menu: Context globalContext(Core::Constants::C_GLOBAL); Command *sep = contextMenu->addSeparator(globalContext); sep->action()->setObjectName(QLatin1String(Constants::M_REFACTORING_MENU_INSERTION_POINT)); contextMenu->addSeparator(globalContext); cmd = ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION); contextMenu->addAction(cmd); errorMessage->clear(); FileIconProvider *iconProvider = FileIconProvider::instance(); MimeDatabase *mimeDatabase = ICore::mimeDatabase(); iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")), mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE))); iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")), mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_VERT))); iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")), mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG))); iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")), mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_VERT_ES))); iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")), mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG_ES))); QObject *core = ICore::instance(); BaseFileWizardParameters fragWizardParameters(IWizard::FileWizard); fragWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL)); fragWizardParameters.setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL)); fragWizardParameters.setDescription (tr("Creates a fragment shader in the OpenGL/ES 2.0 Shading " "Language (GLSL/ES). Fragment shaders generate the final " "pixel colors for triangles, points and lines rendered " "with OpenGL.")); fragWizardParameters.setDisplayName(tr("Fragment Shader (OpenGL/ES 2.0)")); fragWizardParameters.setId(QLatin1String("F.GLSL")); addAutoReleasedObject(new GLSLFileWizard(fragWizardParameters, GLSLFileWizard::FragmentShaderES, core)); BaseFileWizardParameters vertWizardParameters(IWizard::FileWizard); vertWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL)); vertWizardParameters.setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL)); vertWizardParameters.setDescription (tr("Creates a vertex shader in the OpenGL/ES 2.0 Shading " "Language (GLSL/ES). Vertex shaders transform the " "positions, normals and texture co-ordinates of " "triangles, points and lines rendered with OpenGL.")); vertWizardParameters.setDisplayName(tr("Vertex Shader (OpenGL/ES 2.0)")); vertWizardParameters.setId(QLatin1String("G.GLSL")); addAutoReleasedObject(new GLSLFileWizard(vertWizardParameters, GLSLFileWizard::VertexShaderES, core)); fragWizardParameters.setDescription (tr("Creates a fragment shader in the Desktop OpenGL Shading " "Language (GLSL). Fragment shaders generate the final " "pixel colors for triangles, points and lines rendered " "with OpenGL.")); fragWizardParameters.setDisplayName(tr("Fragment Shader (Desktop OpenGL)")); fragWizardParameters.setId(QLatin1String("J.GLSL")); addAutoReleasedObject(new GLSLFileWizard(fragWizardParameters, GLSLFileWizard::FragmentShaderDesktop, core)); vertWizardParameters.setDescription (tr("Creates a vertex shader in the Desktop OpenGL Shading " "Language (GLSL). Vertex shaders transform the " "positions, normals and texture co-ordinates of " "triangles, points and lines rendered with OpenGL.")); vertWizardParameters.setDisplayName(tr("Vertex Shader (Desktop OpenGL)")); vertWizardParameters.setId(QLatin1String("K.GLSL")); addAutoReleasedObject(new GLSLFileWizard(vertWizardParameters, GLSLFileWizard::VertexShaderDesktop, core)); return true; }
void PinnedMemoryAllocator::deallocate(void* ptr) const { auto state = globalContext().lazyInitCUDA(); return state->cudaHostAllocator->free(nullptr, ptr); }
void* PinnedMemoryAllocator::allocate(size_t n) const { auto state = globalContext().lazyInitCUDA(); return state->cudaHostAllocator->malloc(nullptr, n); }
static status_t device_write(void* cookie, off_t position, const void* data, size_t* numBytes) { if (position != 0) return B_BAD_VALUE; // copy data to stack buffer char* buffer = (char*)malloc(*numBytes + 1); if (buffer == NULL) return B_NO_MEMORY; MemoryDeleter bufferDeleter(buffer); Thread* thread = thread_get_current_thread(); if ((thread->flags & THREAD_FLAGS_SYSCALL) != 0) { if (!IS_USER_ADDRESS(data) || user_memcpy(buffer, data, *numBytes) != B_OK) { return B_BAD_ADDRESS; } } else memcpy(buffer, data, *numBytes); buffer[*numBytes] = '\0'; // create an output TestOutput* output = new(std::nothrow) DebugTestOutput; if (output == NULL) return B_NO_MEMORY; ObjectDeleter<TestOutput> outputDeleter(output); // parse arguments char** argv; int argc; if (!parse_command_line(buffer, argv, argc)) return B_NO_MEMORY; ArrayDeleter<char*> argvDeleter(argv); if (argc == 0) return B_BAD_VALUE; // execute command if (strcmp(argv[0], "help") == 0) { // print usage -- print individual lines to avoid dprintf() buffer // overflows const char* usage = kUsage; while (*usage != '\0') { const char* lineEnd = strchr(usage, '\n'); if (lineEnd != NULL) lineEnd++; else lineEnd = usage + strlen(usage); output->Print("%.*s", (int)(lineEnd - usage), usage); usage = lineEnd; } } else if (strcmp(argv[0], "list") == 0) { sTestManager->ListTests(*output); } else if (strcmp(argv[0], "run") == 0) { // parse options TestOptions options; int argi = 1; while (argi < argc) { const char* arg = argv[argi]; if (*arg == '-') { for (arg++; *arg != '\0'; arg++) { switch (*arg) { case 'p': options.panicOnFailure = true; break; case 'q': options.quitAfterFailure = true; break; default: output->Print("Invalid option: \"-%c\"\n", *arg); return B_BAD_VALUE; } } argi++; } else break; } GlobalTestContext globalContext(*output, options); sTestManager->RunTests(globalContext, argv + argi, argc - argi); } else { output->Print("Invalid command \"%s\"!\n", argv[0]); return B_BAD_VALUE; } return B_OK; }
RCntxt::iterator RCntxt::begin() { return RCntxt::iterator(globalContext()); }