Skip to content

Commit

Permalink
+ Generate ParModelica code for function (non-simulation) case too.
Browse files Browse the repository at this point in the history
  plus some fixes.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12554 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
mahge committed Aug 16, 2012
1 parent d3c469b commit 4dc9ef7
Show file tree
Hide file tree
Showing 8 changed files with 2,352 additions and 1,446 deletions.
2,796 changes: 1,398 additions & 1,398 deletions Compiler/Template/AbsynDumpTpl.mo

Large diffs are not rendered by default.

51 changes: 43 additions & 8 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -81,7 +81,7 @@ template translateModel(SimCode simCode)

// If ParModelica generate the kernels file too.
if acceptParModelicaGrammar() then
let()= textFile(parModelicaKernelsFile(fileNamePrefix, modelInfo.functions, literals), '<%fileNamePrefix%>_kernels.cl')
let()= textFile(simulationParModelicaKernelsFile(fileNamePrefix, modelInfo.functions), '<%fileNamePrefix%>_kernels.cl')

//this top-level template always returns an empty result
//since generated texts are written to files directly
Expand All @@ -96,10 +96,13 @@ template translateFunctions(FunctionCode functionCode)
match functionCode
case FUNCTIONCODE(__) then
let filePrefix = name
let _= (if mainFunction then textFile(functionsMakefile(functionCode), '<%filePrefix%>.makefile'))
let()= textFile(functionsHeaderFile(filePrefix, mainFunction, functions, extraRecordDecls, externalFunctionIncludes, literals), '<%filePrefix%>.h')
let()= textFile(functionsFile(filePrefix, mainFunction, functions), '<%filePrefix%>.c')
let()= textFile(recordsFile(filePrefix, extraRecordDecls), '<%filePrefix%>_records.c')
let _= (if mainFunction then textFile(functionsMakefile(functionCode), '<%filePrefix%>.makefile'))
// If ParModelica generate the kernels file too.
if acceptParModelicaGrammar() then
let()= textFile(functionsParModelicaKernelsFile(filePrefix, mainFunction, functions), '<%filePrefix%>_kernels.cl')
"" // Return empty result since result written to files directly
end match
end translateFunctions;
Expand Down Expand Up @@ -2242,7 +2245,7 @@ template simulationFunctionsFile(String filePrefix, list<Function> functions, li
/* adpro: leave a newline at the end of file to get rid of warnings! */
end simulationFunctionsFile;

template parModelicaKernelsFile(String filePrefix, list<Function> functions, list<Exp> literals)
template simulationParModelicaKernelsFile(String filePrefix, list<Function> functions)
"Generates the content of the C file for functions in the simulation case."
::=

Expand All @@ -2256,13 +2259,36 @@ template parModelicaKernelsFile(String filePrefix, list<Function> functions, lis
<%functionHeadersParModelica(filePrefix, functions)%>

// Headers finish here.


<%functionBodiesParModelica(functions)%>


>>

end simulationParModelicaKernelsFile;

template functionsParModelicaKernelsFile(String filePrefix, Option<Function> mainFunction, list<Function> functions)
"Generates the content of the C file for functions in the simulation case."
::=

/* Reset the parfor loop id counter to 0*/
let()= System.parForTickReset(0)

<<
#include "OCLRuntimeUtil_new.cl"

// ParModelica Parallel Function headers.
<%functionHeadersParModelica(filePrefix, functions)%>

// Headers finish here.

<%match mainFunction case SOME(fn) then functionBodyParModelica(fn,true)%>
<%functionBodiesParModelica(functions)%>


>>

end parModelicaKernelsFile;
end functionsParModelicaKernelsFile;

template recordsFile(String filePrefix, list<RecordDeclaration> recordDecls)
"Generates the content of the C file for functions in the simulation case."
Expand All @@ -2284,7 +2310,6 @@ template simulationFunctionsHeaderFile(String filePrefix, list<Function> functio
#define <%stringReplace(filePrefix,".","_")%>__H
<%commonHeader()%>
#include "simulation_runtime.h"
<%if acceptParModelicaGrammar() then '#include <omc_ocl_interface.h>'%>
#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -2486,6 +2511,8 @@ template commonHeader()
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
<%if acceptParModelicaGrammar() then '#include <omc_ocl_interface.h>'%>

>>
end commonHeader;

Expand All @@ -2507,6 +2534,12 @@ template functionsFile(String filePrefix,
#define MODELICA_ASSERT(info,msg) { printInfo(stderr,info); fprintf(stderr,"Modelica Assert: %s!\n", msg); fflush(NULL); }
#define MODELICA_TERMINATE(msg) { fprintf(stderr,"Modelica Terminate: %s!\n", msg); fflush(NULL); }

<%if acceptParModelicaGrammar() then
<< /* the OpenCL program. Made global to avoid repeated builds */
cl_program ocl_kernels_program = ocl_build_p_from_src("<%filePrefix%>_kernels.cl", true);
>>
%>

<%match mainFunction case SOME(fn) then functionBody(fn,true)%>
<%functionBodies(functions)%>
<%\n%>
Expand Down Expand Up @@ -2551,18 +2584,20 @@ template functionsMakefile(FunctionCode fnCode)
match fnCode
case FUNCTIONCODE(makefileParams=MAKEFILE_PARAMS(__)) then
let libsStr = (makefileParams.libs ;separator=" ")
let ParModelicaLibs = if acceptParModelicaGrammar() then '-lOMOCLRuntime -lOpenCL' // else ""

<<
# Makefile generated by OpenModelica

# Dynamic loading uses -O0 by default
SIM_OR_DYNLOAD_OPT_LEVEL=-O0<% if boolOr(acceptMetaModelicaGrammar(), Flags.isSet(Flags.GEN_DEBUG_SYMBOLS)) then " -g"%>
CC=<%makefileParams.ccompiler%>
CC=<%if acceptParModelicaGrammar() then 'g++' else '<%makefileParams.ccompiler%>'%>
CXX=<%makefileParams.cxxcompiler%>
LINK=<%makefileParams.linker%>
EXEEXT=<%makefileParams.exeext%>
DLLEXT=<%makefileParams.dllext%>
CFLAGS= -I"<%makefileParams.omhome%>/include/omc" <%makefileParams.includes ; separator=" "%> <%makefileParams.cflags%>
LDFLAGS= -L"<%makefileParams.omhome%>/lib/omc" -lSimulationRuntimeC <%makefileParams.ldflags%> <%makefileParams.runtimelibs%>
LDFLAGS= -L"<%makefileParams.omhome%>/lib/omc" -lSimulationRuntimeC <%ParModelicaLibs%> <%makefileParams.ldflags%> <%makefileParams.runtimelibs%>
PERL=perl
MAINFILE=<%name%><% if boolOr(acceptMetaModelicaGrammar(), Flags.isSet(Flags.GEN_DEBUG_SYMBOLS)) then ".conv"%>.c

Expand Down
7 changes: 4 additions & 3 deletions SimulationRuntime/ParModelica/OpenCLRuntime/Makefile
Expand Up @@ -11,6 +11,7 @@ CXX=g++
EXEEXT=.exe
DLLEXT=.dll
CFLAGS= -O3 -Wall -I. -I"$(OPENMODELICAHOME)/include/omc"
OPENLC_LIB= OpenCL.lib


OBJS = \
Expand All @@ -26,15 +27,15 @@ transfer: libOMOCLRuntime.a
$(COPY) omc_ocl_common_header.h $(OPENMODELICA_INC)
$(COPY) omc_ocl_memory_ops.h $(OPENMODELICA_INC)
$(COPY) libOMOCLRuntime.a $(OPENMODELICA_LIB)
$(COPY) OpenCL.lib $(OPENMODELICA_LIB)
$(COPY) $(OPENLC_LIB) $(OPENMODELICA_LIB)
mkdir -p $(OPENMODELICA_INC)/CL/
$(COPY) ./CL/* $(OPENMODELICA_INC)/CL/
$(COPY) OCLRuntimeUtil_new.cl $(OPENMODELICAHOME)/include/omc/
# cp OCLRuntimeUtil.cl $(OPENMODELICAHOME)/bin/
# cp ocloffcomp$(EXEEXT) $(OPENMODELICAHOME)/bin/

ocloffc: ocl_offcomp.c ocl_util.hpp libOMOCLRuntime
$(CXX) -I. -o ocloffcomp$(EXEEXT) ocl_offcomp.c libOMOCLRuntime.a OpenCL.lib $(CFLAGS)
ocloffc: omc_ocl_util.h libOMOCLRuntime.a
$(CXX) -I. -o ocloffcomp$(EXEEXT) ocl_offcomp.c libOMOCLRuntime.a $(OPENLC_LIB) $(CFLAGS)

libOMOCLRuntime.a: $(OBJS)
@rm -f $@
Expand Down

0 comments on commit 4dc9ef7

Please sign in to comment.