예제 #1
0
QString Generator::generateMethods()
{
  QString res;
  QTextStream s(&res);

  for (int m = 0; m < cdef->publicList.count(); m++)
  {
    FunctionDef f = cdef->publicList.at(m);
    int d = generateFunction(s, f);
    while (d > 0)
      d = generateFunction(s, f, d);
  }

  return res;
}
예제 #2
0
  void SXFunctionInternal::allocOpenCL() {
    // OpenCL return flag
    cl_int ret;

    // Generate the kernel source code
    stringstream ss;

    // Add kernel prefix
    ss << "__kernel ";

    // Generate the function
    CodeGenerator gen;
    generateFunction(ss, "evaluate", "__global const double*", "__global double*", "double", gen);

    // Form c-string
    std::string s = ss.str();
    if (verbose()) {
      userOut() << "Kernel source code for numerical evaluation:" << endl;
      userOut() << " ***** " << endl;
      userOut() << s;
      userOut() << " ***** " << endl;
    }
    const char* cstr = s.c_str();

    // Parse kernel source code
    program_ = clCreateProgramWithSource(sparsity_propagation_kernel_.context, 1,
                                         static_cast<const char **>(&cstr), 0, &ret);
    casadi_assert(ret == CL_SUCCESS);
    casadi_assert(program_ != 0);

    // Build Kernel Program
    compileProgram(program_);

    // Create OpenCL kernel for forward propatation
    kernel_ = clCreateKernel(program_, "evaluate", &ret);
    casadi_assert(ret == CL_SUCCESS);

    // Memory buffer for each of the input arrays
    input_memobj_.resize(nIn(), static_cast<cl_mem>(0));
    for (int i=0; i<input_memobj_.size(); ++i) {
      input_memobj_[i] = clCreateBuffer(sparsity_propagation_kernel_.context,
                                        CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
                                        inputNoCheck(i).size() * sizeof(cl_double),
                                        static_cast<void*>(inputNoCheck(i).ptr()), &ret);
      casadi_assert(ret == CL_SUCCESS);
    }

    // Memory buffer for each of the output arrays
    output_memobj_.resize(nOut(), static_cast<cl_mem>(0));
    for (int i=0; i<output_memobj_.size(); ++i) {
      output_memobj_[i] = clCreateBuffer(sparsity_propagation_kernel_.context,
                                         CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR,
                                         outputNoCheck(i).size() * sizeof(cl_double),
                                         static_cast<void*>(outputNoCheck(i).ptr()), &ret);
      casadi_assert(ret == CL_SUCCESS);
    }


  }
예제 #3
0
void generateFile( vector< BlockTab *> &allFunctions )
{
	for ( vector< BlockTab *>::iterator i = allFunctions.begin( );
					i != allFunctions.end( ); ++i ) {
	
		BlockTab *curBlockTab = *i;
		curBlockTab -> applyT2( );
		generateFunction( *curBlockTab );
		delete curBlockTab;
	}
}
예제 #4
0
void wasmint::TestCaseGenerator::generateModule() {
    source_ << "module ";
    if (decision(50))
        generateMemory();

    while (decision(90))
        generateFunction();

    if (decision(99))
        generateMainFunction();

    if (decision(3))
        mutateSource();
}
예제 #5
0
int main (int argc, char **argv) {
    
    int i, num = 0;
	int maxnodes = 20;
	int functionnum = 60;
	double x;
	directCode_t *code = (directCode_t *)malloc(sizeof(directCode_t));
	cvodeData_t *data = (cvodeData_t *)malloc(sizeof(cvodeData_t));
	void (**tests)() = (void (**)())malloc(sizeof(void (*)())*functionnum);
	nodes = (ASTNode_t *)malloc(sizeof(ASTNode_t)*maxnodes);
	data->value = (double *)malloc(sizeof(double)*10);
	data->value[5] = 4.25;
	data->currenttime = 13.4;
	
	tests[num++] = testAST_INTEGER;
	tests[num++] = testAST_REAL;
	tests[num++] = testAST_NAME;
	tests[num++] = testAST_FUNCTION_DELAY;
	tests[num++] = testAST_NAME_TIME;
	tests[num++] = testAST_CONSTANT_E;
	tests[num++] = testAST_CONSTANT_FALSE;
	tests[num++] = testAST_CONSTANT_PI;
	tests[num++] = testAST_CONSTANT_TRUE;
	tests[num++] = testAST_PLUS;
	tests[num++] = testAST_PLUS_large;
	tests[num++] = testAST_MINUS;
	tests[num++] = testAST_TIMES;
	tests[num++] = testAST_TIMES_large;
	tests[num++] = testAST_DIVIDE;
	tests[num++] = testAST_POWER;
	tests[num++] = testAST_FUNCTION;
	tests[num++] = testAST_FUNCTION_ABS;
	tests[num++] = testAST_FUNCTION_ARCCOS;
	tests[num++] = testAST_FUNCTION_ARCCOSH;
	tests[num++] = testAST_FUNCTION_ARCCOT;
	tests[num++] = testAST_FUNCTION_ARCCOTH;
	tests[num++] = testAST_FUNCTION_ARCCSC;
	tests[num++] = testAST_FUNCTION_ARCCSCH;
	tests[num++] = testAST_FUNCTION_ARCSEC;
	tests[num++] = testAST_FUNCTION_ARCSECH;
	tests[num++] = testAST_FUNCTION_ARCSIN;
	tests[num++] = testAST_FUNCTION_ARCSINH;
	tests[num++] = testAST_FUNCTION_ARCTAN;
	tests[num++] = testAST_FUNCTION_ARCTANH;
	tests[num++] = testAST_FUNCTION_CEILING;
	tests[num++] = testAST_FUNCTION_COS;
	tests[num++] = testAST_FUNCTION_COSH;
	tests[num++] = testAST_FUNCTION_COT;
	tests[num++] = testAST_FUNCTION_COTH;
	tests[num++] = testAST_FUNCTION_CSC;
	tests[num++] = testAST_FUNCTION_CSCH;
	tests[num++] = testAST_FUNCTION_EXP;
	tests[num++] = testAST_FUNCTION_FACTORIAL;
	tests[num++] = testAST_FUNCTION_FLOOR;
	tests[num++] = testAST_FUNCTION_LN;
	tests[num++] = testAST_FUNCTION_LOG;
	tests[num++] = testAST_FUNCTION_PIECEWISE;
	tests[num++] = testAST_FUNCTION_POWER;
	tests[num++] = testAST_FUNCTION_ROOT;
	tests[num++] = testAST_FUNCTION_SEC;
	tests[num++] = testAST_FUNCTION_SECH;
	tests[num++] = testAST_FUNCTION_SIN;
	tests[num++] = testAST_FUNCTION_SINH;
	tests[num++] = testAST_FUNCTION_TAN;
	tests[num++] = testAST_FUNCTION_TANH;
	tests[num++] = testAST_LOGICAL_AND;
	tests[num++] = testAST_LOGICAL_NOT;
	tests[num++] = testAST_LOGICAL_OR;
	tests[num++] = testAST_LOGICAL_XOR;
	tests[num++] = testAST_RELATIONAL_EQ;
	tests[num++] = testAST_RELATIONAL_GEQ;
	tests[num++] = testAST_RELATIONAL_GT;
	tests[num++] = testAST_RELATIONAL_LEQ;
	tests[num++] = testAST_RELATIONAL_LT;
	tests[num++] = complexTest1;
	
	/* tests */
	for(i = 0 ; i < num ; i++) {
		tests[i]();
		generateFunction(code, &nodes[0]);
		x = code->evaluate(data);
		destructFunction(code);
		printf("%s %8.3f\n", string, x);
		}

	return 0;
	}