Beispiel #1
0
int main(int argc, char** argv)
{
	//Parse command-line args
	ProgramOptions po(argc, argv);

	//Initialize the AST
	SgProject* project = new SgProject(argc, argv);
	ROSE_ASSERT(project);
	AstTests::runAllTests(project); //TODO switch on/off with command-line args

	//Set the folder containing the features
	string featureFolder = "";
	bool defaultFeatures = po.getFeaturesFolder(featureFolder);
	if(!defaultFeatures)
		CallScheduler::setFeaturesFolder(featureFolder);

	//Loop through all partitioned kernels and add scheduling calls
	Rose_STL_Container<SgNode*> pragmas = querySubTree(project, V_SgPragmaDeclaration);
	Rose_STL_Container<SgNode*>::const_iterator pragmaIt = pragmas.begin();
	SgPragmaDeclaration* pragma = NULL;
	SgFunctionDeclaration* funcDecl = NULL;
	SgStatement* stmt = NULL;
	for(pragmaIt = pragmas.begin(); pragmaIt != pragmas.end(); pragmaIt++)
	{
		pragma = isSgPragmaDeclaration(*pragmaIt);
		ROSE_ASSERT(pragma);

		PragmaParser pp(pragma);
		if(pp.isPopcornPragma() && pp.getPragmaType() == PARTITIONED)
		{
			stmt = getNextStatement(pragma);
			while(!isSgFunctionDeclaration(stmt))
				stmt = getNextStatement(pragma);
			funcDecl = isSgFunctionDeclaration(stmt);
			ROSE_ASSERT(funcDecl);
			Pragmas pragmas(funcDecl);

			//Add scheduling calls
			CallScheduler cs(funcDecl, pragmas);
			cs.addSchedulerCalls();

			//Insert the header
			//TODO this won't insert the header into files
			insertHeader(po.getSchedulerHeaderLocation(), PreprocessingInfo::after, false,
					getGlobalScope(funcDecl));
		}
	}

	return backend(project);
}
Beispiel #2
0
SQLTransactionState SQLTransactionBackend::runStatements()
{
    ASSERT(m_lockAcquired);
    SQLTransactionState nextState;

    // If there is a series of statements queued up that are all successful and have no associated
    // SQLStatementCallback objects, then we can burn through the queue
    do {
        if (m_shouldRetryCurrentStatement && !m_sqliteTransaction->wasRolledBackBySqlite()) {
            m_shouldRetryCurrentStatement = false;
            // FIXME - Another place that needs fixing up after <rdar://problem/5628468> is addressed.
            // See ::openTransactionAndPreflight() for discussion

            // Reset the maximum size here, as it was increased to allow us to retry this statement.
            // m_shouldRetryCurrentStatement is set to true only when a statement exceeds
            // the quota, which can happen only in a read-write transaction. Therefore, there
            // is no need to check here if the transaction is read-write.
            m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize());
        } else {
            // If the current statement has already been run, failed due to quota constraints, and we're not retrying it,
            // that means it ended in an error. Handle it now
            if (m_currentStatementBackend && m_currentStatementBackend->lastExecutionFailedDueToQuota()) {
                return nextStateForCurrentStatementError();
            }

            // Otherwise, advance to the next statement
            getNextStatement();
        }
        nextState = runCurrentStatementAndGetNextState();
    } while (nextState == SQLTransactionState::RunStatements);

    return nextState;
}
Beispiel #3
0
  // define pragmas to indicated expected results in the code
  // The grammar of pragmas is
  //
  // arithmetic_intensity_pragma = '#pragma' 'aitool' | fp_counter_clause
  // fp_counter_clause = 'fp_plus' '(' INTEGER ')'  | 'fp_minus' '(' INTEGER ')' | 'fp_multiply' '(' INTEGER ')' |
  //                    'fp_divide' '(' INTEGER ')'   | 'fp_total' '(' INTEGER ')'
  //  This pragma indicate the number of FP operations for the followed statement (a loop mostly), without considering repetition.
  //  e.g. #pragma aitool fp_plus(3) fp_minus(3) fp_multiple (6) fp_total (12)   
  FPCounters* parse_aitool_pragma (SgPragmaDeclaration* pragmaDecl)
  {
    FPCounters* result = NULL;
    assert (pragmaDecl != NULL);
    assert (pragmaDecl->get_pragma() != NULL);
    string pragmaString = pragmaDecl->get_pragma()->get_pragma();
    // make sure it is side effect free
    const char* old_char = c_char;
    SgNode* old_node = c_sgnode;

    c_sgnode = getNextStatement(pragmaDecl);
    assert (c_sgnode != NULL);

    c_char = pragmaString.c_str();

    if (afs_match_substr("aitool"))
    { 
      result = new FPCounters (pragmaDecl);
      fp_operation_kind_enum fp_op_kind = e_unknown; 
      int op_count = 0; 
      while (parse_fp_counter_clause (& fp_op_kind, & op_count))
      {
	if (debug)
	  cout<<"parse_aitool_pragma() set "<< toString(fp_op_kind) <<" with value "<<op_count<<endl;
	result->setCount (fp_op_kind, op_count); 
      }
    } 
    // may have incomplete info in the pragma
    if (result != NULL)
      result->updateTotal(); 
    // undo side effects
    c_char = old_char;
    c_sgnode = old_node;

    if (debug)
    { 
      if (result != NULL)
	result->printInfo();
    }

    return result;
  } // end parse_aitool_pragma
Beispiel #4
0
void SQLTransaction::runStatements()
{
    ASSERT(m_lockAcquired);

    // If there is a series of statements queued up that are all successful and have no associated
    // SQLStatementCallback objects, then we can burn through the queue
    do {
        if (m_shouldRetryCurrentStatement && !m_sqliteTransaction->wasRolledBackBySqlite()) {
            m_shouldRetryCurrentStatement = false;
            // FIXME - Another place that needs fixing up after <rdar://problem/5628468> is addressed.
            // See ::openTransactionAndPreflight() for discussion

            // Reset the maximum size here, as it was increased to allow us to retry this statement.
            // m_shouldRetryCurrentStatement is set to true only when a statement exceeds
            // the quota, which can happen only in a read-write transaction. Therefore, there
            // is no need to check here if the transaction is read-write.
            m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize());
        } else {
            // If the current statement has already been run, failed due to quota constraints, and we're not retrying it,
            // that means it ended in an error.  Handle it now
            if (m_currentStatement && m_currentStatement->lastExecutionFailedDueToQuota()) {
                handleCurrentStatementError();
                break;
            }

            // Otherwise, advance to the next statement
            getNextStatement();
        }
    } while (runCurrentStatement());

    // If runCurrentStatement() returned false, that means either there was no current statement to run,
    // or the current statement requires a callback to complete.  In the later case, it also scheduled
    // the callback or performed any other additional work so we can return
    if (!m_currentStatement)
        postflightAndCommit();
}
Beispiel #5
0
int main(int argc, char** argv)
{
	//Parse command-line options
	ProgramOptions po(argc, argv);

	//Initialize the AST
	SgProject* project = new SgProject(argc, argv);
	ROSE_ASSERT(project);
	AstTests::runAllTests(project); //TODO switch on/off with command-line args

	//Insert MM-wrapper header file
	string mmHeader = po.getMMWrapperHeaderLocation();
	insertHeader(mmHeader, PreprocessingInfo::after, false, getGlobalScope(findMain(project)));

	//Initialize set of system headers & compiler generated vars
	RegisterPointers::initialize();

	//Add calls to registers sizes of static variables
	RegisterVars rv(project, mmHeader);
	rv.registerStaticVars();

	//Used to accumulate all global variables
	set<SgInitializedName*> globalVars;

	//Add wrapper calls to each function/sub-function so that all pointers are registered
	Rose_STL_Container<SgNode*> pragmas = querySubTree(project, V_SgPragmaDeclaration);
	Rose_STL_Container<SgNode*>::const_iterator pragmaIt;
	Rose_STL_Container<SgNode*> funcCalls = querySubTree(project, V_SgFunctionCallExp);
	SgPragmaDeclaration* pragma;
	SgStatement* stmt;
	SgFunctionDeclaration* funcDecl;
	for(pragmaIt = pragmas.begin(); pragmaIt != pragmas.end(); pragmaIt++)
	{
		pragma = isSgPragmaDeclaration(*pragmaIt);
		ROSE_ASSERT(pragma);

		PragmaParser pp(pragma);
		if(pp.isPopcornPragma() && pp.getPragmaType() == PARTITIONED)
		{
			//Get function declaration
			stmt = getNextStatement(pragma);
			while(!isSgFunctionDeclaration(stmt))
				stmt = getNextStatement(stmt);
			funcDecl = isSgFunctionDeclaration(stmt);
			ROSE_ASSERT(funcDecl);
			Pragmas pragmas(funcDecl);

			//Save global variables
			saveGlobalVariables(pragmas.getGlobalInputs(), globalVars,
					pragmas.getFunction()->get_scope());
			saveGlobalVariables(pragmas.getGlobalOutputs(), globalVars,
					pragmas.getFunction()->get_scope());

			//Update call sites
			//TODO I don't think we need this anymore, since all sizes are
			//handled through the mm_wrapper interface
			//FunctionCallUpdater fcu(funcDecl, funcCalls);
			//fcu.updateDeclaration();
			//fcu.updateSites();
		}
	}

	//Register/unregister global variables
	RegisterVars::registerGlobalVars(globalVars);

	//Add call to initialize wrapper
	SgFunctionDeclaration* main = findMain(project);
	ROSE_ASSERT(main);
	FunctionCallUpdater::insertInitWrapperCall(main);

	return backend(project);
}
Beispiel #6
0
  //! Translate generated Pragma Attributes one by one
  void translatePragmas (std::vector <MPI_PragmaAttribute*>& Attribute_List)
  {
    std::vector<MPI_PragmaAttribute*>::iterator iter;
    for (iter = Attribute_List.begin(); iter!=Attribute_List.end(); iter ++)
    {
      MPI_PragmaAttribute* cur_attr = *iter; 
      cout<<"Translating ..." << cur_attr->toString() <<endl;
      SgScopeStatement* scope = cur_attr->pragma_node ->get_scope();
      ROSE_ASSERT (scope != NULL);
      // simply obtain the default value and remove the pragma
      if (cur_attr-> pragma_type == pragma_mpi_device_default)
      {
        mpi_device_default_choice = cur_attr->default_semantics;
        // no automatic handling of attached preprocessed info. for now
        removeStatement(cur_attr->pragma_node, false);
      }
      // find omp target device(mpi:all) begin
      else if (cur_attr-> pragma_type == pragma_mpi_device_all_begin)
      {
        iter ++; // additional increment once
        MPI_PragmaAttribute* end_attribute = *iter; 
        ROSE_ASSERT (end_attribute->pragma_type = pragma_mpi_device_all_end);
        removeStatement(cur_attr->pragma_node, false);
        removeStatement(end_attribute ->pragma_node, false);
      }  
      else if (cur_attr-> pragma_type == pragma_mpi_device_master_begin)
      { // TODO refactor into a function
        iter ++; // additional increment once
        MPI_PragmaAttribute* end_attribute = *iter; 
        ROSE_ASSERT (end_attribute->pragma_type = pragma_mpi_device_master_end);

        //insert a if (rank) .. after the end pragma
        SgIfStmt * ifstmt = buildIfStmt (buildEqualityOp(buildVarRefExp("_xomp_rank", scope), buildIntVal(0)), buildBasicBlock(), NULL);
        insertStatementAfter (end_attribute->pragma_node, ifstmt);
        SgBasicBlock * bb = isSgBasicBlock(ifstmt->get_true_body());

        SgStatement* next_stmt = getNextStatement(cur_attr->pragma_node); // the next stmt is BB, skip it by starting the search from it
        ROSE_ASSERT (next_stmt != NULL);
        // normalize all declarations
        while ( next_stmt != end_attribute ->pragma_node)
        {
          // save current stmt before getting next one 
          SgStatement* cur_stmt = next_stmt; 
          next_stmt = getNextStatement (next_stmt);
          ROSE_ASSERT (next_stmt != NULL);

          if (SgVariableDeclaration* decl = isSgVariableDeclaration (cur_stmt))
            splitVariableDeclaration (decl);
        }
        // move all non-declaration statements in between into the block
        next_stmt = getNextStatement(cur_attr->pragma_node); //reset from the beginning
        while ( next_stmt != end_attribute ->pragma_node) 
        {
          // save current stmt before getting next one 
          SgStatement* cur_stmt = next_stmt; 
          next_stmt = getNextStatement (next_stmt);
          ROSE_ASSERT (next_stmt != NULL);
           
          if (!isSgVariableDeclaration(cur_stmt))
          {
            // now remove the current stmt
            removeStatement (cur_stmt, false);
            appendStatement(cur_stmt, bb);
          }
        }
        
        // remove pragmas
        removeStatement(cur_attr->pragma_node, false);
        removeStatement(end_attribute ->pragma_node, false);
      }  

    }  // end for
  } // end translatePragmas ()