Skip to content

Commit

Permalink
handle compile flags in new cocl_add_executable et al
Browse files Browse the repository at this point in the history
  • Loading branch information
hughperkins committed Jun 4, 2017
1 parent 6bb44a1 commit 2bfe4e0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ Please cite: [CUDA-on-CL: a compiler and runtime for running NVIDIA® CUDA™ C+

## News

- June 4:
- added cmake macros `cocl_add_executable` and `cocl_add_library`
- these replace the previous `add_cocl_executable`, and have the advantage that they are standard targets, that you can use `target_link_libraries` and so on
- see [test/cmake/README.md](test/cmake/README.md) for an example
- May 31:
- added a developer debugging option `COCL_DUMP_CONFIG`, to allow easy inspection of buffers returned by kernel calls, see [advanced usage](doc/advanced_usage.md)
- May 28:
Expand Down
9 changes: 6 additions & 3 deletions bin/cocl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ if [ ! -z "$SETX" ]; then {
set -x
} fi

# set -x
echo cocl args: $@

set -e

if [ x$CLANG_HOME = x ]; then {
Expand Down Expand Up @@ -131,7 +132,7 @@ EOF
PASSTHRU=
export IROOPENCLARGS=
export DEVICELLOPT=
while [ x$1 != x ]; do {
while [ "x$1" != x ]; do {
THISARG=$(echo $1 | cut -d = -f 1)
DONE=0
TWOLETTERS=$(echo $1 | cut -c 1-2)
Expand All @@ -148,7 +149,9 @@ while [ x$1 != x ]; do {
DONE=1
;;
-D)
PASSTHRU="$PASSTHRU $1"
# hacktastic :-D. Would be better to fix the cmake rules, sooner or later...
DSTRIPPED=$(echo $1 | sed -e 's/-D-D/-D/')
PASSTHRU="$PASSTHRU $DSTRIPPED"
DONE=1
;;
-O)
Expand Down
15 changes: 1 addition & 14 deletions cmake/cocl_impl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,26 @@ macro(cocl_build_objects target_name target_type)
set(filenames ${filenames} ${arg})
endif()
endforeach()
# message("cocl_build_objects ${target_name} ${target_type} exclude from all: ${excludefromall} shared: ${shared} files: ${filenames}")

set(DEF_CMDLINE)
get_directory_property(DirDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS)
set(DEF_CMDLINE)
foreach(DEF ${DirDefs})
SET(DEF_CMDLINE ${DEF_CMDLINE} -D${DEF})
endforeach()
# message("DEF_CMDLINE ${DEF_CMDLINE}")

set(OBJECTS)
foreach(filename ${filenames})
get_filename_component(EXT ${filename} EXT)
string(REPLACE / _ FILENAME_NO_SLASH ${filename})
if(${EXT} STREQUAL .cu)
# message("its a cu")
# for the bit with angle brackets, see https://cmake.org/cmake/help/v3.0/manual/cmake-generator-expressions.7.html#manual:cmake-generator-expressions(7)
# it's because we dot actually know the include directories yet, at the time of executing the contents of this macro
# note that, despite what that page may claim, generator expressions cannot contain spaces, eg see:
# http://cmake.3232098.n2.nabble.com/Custom-Commands-Generator-Expressions-tp7586630p7586631.html
# (finding this bit about whitespace cost me a world of pain...)
# CLANG_HOME=${LLVM40_HOME}
add_custom_command(
OUTPUT ${target_name}.d/${filename}.o
# COMMAND mkdir -p
COMMAND
${COCL_PATH}
${DEF_CMDLINE}
"$<$<BOOL:$<TARGET_PROPERTY:${target_name},COMPILE_FLAGS>>:$<JOIN:$<TARGET_PROPERTY:${target_name},COMPILE_FLAGS>,;>>"
"$<$<BOOL:$<TARGET_PROPERTY:${target_name},INCLUDE_DIRECTORIES>>:-I$<JOIN:$<TARGET_PROPERTY:${target_name},INCLUDE_DIRECTORIES>,;-I>>"
${CMAKE_CURRENT_SOURCE_DIR}/${filename}
-o ${target_name}.d/${filename}.o
-c
${_TESTS_COCL_OPTIONS}
DEPENDS ${filename}
COMMAND_EXPAND_LISTS
)
Expand Down
1 change: 1 addition & 0 deletions src/function_names_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void FunctionNamesMap::populateKnownValues() {
knownFunctionsMap["_Z3powff"] = "pow";
knownFunctionsMap["_Z4sqrtf"] = "sqrt";
knownFunctionsMap["_Z3logf"] = "log";
knownFunctionsMap["_Z5isnanf"] = "isnan";

// CAS
knownFunctionsMap["_Z9atomicCASIjET_PS0_S0_S0_"] = "atomic_cmpxchg"; // cas int
Expand Down
14 changes: 12 additions & 2 deletions test/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)

set(COCL_PATH /usr/local/bin/cocl)
include(cmake/cocl.cmake)
set(COCL_HOME "/usr/local" CACHE STRING "Coriander directory, eg /usr/local")

# assumes you've installed coriander, into default location, ie /usr/local
set(COCL_PATH ${COCL_HOME}/bin/cocl)
include(${COCL_HOME}/share/cocl/cocl.cmake)

cocl_add_executable(cuda_sample cuda_sample.cu)
target_link_libraries(cuda_sample cocl clblast clew)
Expand All @@ -28,3 +31,10 @@ target_include_directories(uses_mylibrary PRIVATE include)
cocl_add_executable(uses_mylibrary_static many_cpp.cpp)
target_link_libraries(uses_mylibrary_static cocl clblast clew mylibrary_static)
target_include_directories(uses_mylibrary_static PRIVATE include)

cocl_add_executable(requires_define requires_define.cu)
# set_target_properties(requires_define PROPERTIES COMPILE_DEFINITIONS -DSHOULD_BE_DEFINED)
# set_target_properties(requires_define PROPERTIES COMPILE_DEFINITIONS -DSHOULD_BE_DEFINED2)
# add_definitions(-DSHOULD_BE_DEFINED3 -DSHOULD_BE_DEFINED4)
# ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_NO_ASSERTION_CHECKING=1")
set_target_properties(requires_define PROPERTIES COMPILE_FLAGS "-DSHOULD_BE_DEFINED -DSHOULD_BE_DEFINED2 -DSHOULD_BE_DEFINED3 -DSHOULD_BE_DEFINED4")
11 changes: 11 additions & 0 deletions test/cmake/requires_define.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef SHOULD_BE_DEFINED
#error SHOULD_BE_DEFINED should be defined. It is not.
#endif

#ifndef SHOULD_BE_DEFINED3
#error SHOULD_BE_DEFINED3 should be defined. It is not.
#endif

int main(int argc, char *argv[]) {
return 0;
}

0 comments on commit 2bfe4e0

Please sign in to comment.