summaryrefslogtreecommitdiff
path: root/lib/make/make.config.rules.in
diff options
context:
space:
mode:
authoreschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac>2012-05-02 00:26:14 +0000
committereschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac>2012-05-02 00:26:14 +0000
commitb7e100f8ac916f47f4a6b01002bd5157a2eccdf0 (patch)
tree013aee66410b173897b28b4a8783473f10a6493a /lib/make/make.config.rules.in
parent9ebfa0fd87f4582f90f58f979e5a5b8deb659501 (diff)
Support OpenCL source code (.cl files)
OpenCL source code needs to be compiled at run time, and thus needs to be passed as string to the OpenCL run-time library. This makes writing OpenCL source code inconvenient. This patch adds *.cl as supported file type to Cactus. *.cl files are transformed into globally visible strings, with a name consisting of the thorn name and file name. These strings can then be easily used at run time to build and run OpenCL code. Since *.cl files are converted to strings (and are not OpenCL-compiled at build time), there are no CL* options specifying compiler type, compiler flags etc. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4808 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib/make/make.config.rules.in')
-rw-r--r--lib/make/make.config.rules.in40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/make/make.config.rules.in b/lib/make/make.config.rules.in
index cec72a91..caef245d 100644
--- a/lib/make/make.config.rules.in
+++ b/lib/make/make.config.rules.in
@@ -83,6 +83,12 @@ define CXX_DEPENDENCIES
$(DEPENDENCY_FIXER)
endef
+define CL_DEPENDENCIES
+# An OpenCL source file has no external dependencies
+ $(CL_DEPEND) $< $(CL_DEPEND_OUT)
+ $(DEPENDENCY_FIXER)
+endef
+
define CU_DEPENDENCIES
$(CU_DEPEND) $< $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DCCODE $(CU_DEPEND_OUT)
$(DEPENDENCY_FIXER)
@@ -149,6 +155,26 @@ define POSTPROCESS_CXX
$(CXX_POSTPROCESSING)
endef
+# Define how to do an OpenCL compilation
+define PREPROCESS_CL
+# Wrap the OpenCL source code into a string, using the thorn name and
+# file name to create a variable name, and create a C file
+{ \
+ echo 'char const *const OpenCL_source_$(THORN)_$* ='; \
+ sed -e 's/\\/\\\\/g;s/"/\\"/g;s/\(.*\)/"\1\\n"/g'; \
+ echo ';'; \
+} < $^ > $(notdir $<).c
+endef
+
+define COMPILE_CL
+# Basically a C compile, but with a different source file name
+current_wd=`$(GET_WD)` ; cd $(SCRATCH_BUILD) ; $(CC) $(CPPFLAGS) $(CFLAGS) $(CCOMPILEONLY)$(OPTIONSEP)$$current_wd$(DIRSEP)$@ $$current_wd$(DIRSEP)$(notdir $<).c $(INCLUDE_LINE) $(EXTRA_DEFINES:%=-D%) -DCCODE
+endef
+
+define POSTPROCESS_CL
+$(CL_POSTPROCESSING)
+endef
+
# Define how to do a CUDA compilation
define PREPROCESS_CU
{ if test $(C_LINE_DIRECTIVES) = 'yes'; then echo '#line 1 "'$<'"'; fi; cat $<; } | $(PERL) -s $(C_FILE_PROCESSOR) -line_directives=$(C_LINE_DIRECTIVES) -source_file_name=$< $(CONFIG) > $(notdir $<)
@@ -283,6 +309,20 @@ endef
%.cxx.d: $(SRCDIR)/%.cxx
$(CXX_DEPENDENCIES)
+# Build rules for OpenCL
+
+%.cl.o: $(SRCDIR)/%.cl
+ $(NOTIFY_PREPROCESSING)
+ $(PREPROCESS_CL)
+ $(NOTIFY_COMPILING)
+ $(COMPILE_CL)
+ $(NOTIFY_POSTPROCESSING)
+ $(POSTPROCESS_CL)
+ $(NOTIFY_DIVIDER)
+
+%.cl.d: $(SRCDIR)/%.cl
+ $(CL_DEPENDENCIES)
+
# Build rules for CUDA
%.cu.o: $(SRCDIR)/%.cu