This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPENCIL.cmake
55 lines (51 loc) · 3.42 KB
/
PENCIL.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
set(PENCIL_COMPILER "ppcg" CACHE STRING "PENCIL compiler")
set(PENCIL_INCLUDE_DIRS "/usr/local/include" CACHE PATH "PENCIL library headers directory")
set(PENCIL_LIBRARIES "libocl_pencil_opt.so" CACHE FILE "PENCIL runtime library")
#device-specific settings
set(PENCIL_DEFAULT_FLAGS_BLOCKSIZE "8,8" CACHE STRING "Default block sizes of kernels")
set(PENCIL_DEFAULT_FLAGS_LOCAL_MEMORY_SIZE "0" CACHE STRING "Amount of __local memory to use. Set to 0 to disable __local memory usage")
#other important PPCG switches
set(PENCIL_DEFAULT_FLAGS_MAXFUSE true CACHE BOOL "--isl-schedule-fuse=min|max")
set(PENCIL_DEFAULT_FLAGS_NO_SEPARATE_COMP true CACHE BOOL "--no-isl-schedule-separate-components")
set(PENCIL_DEFAULT_FLAGS_DISABLE_PRIVATE false CACHE BOOL "Disable usage of private memory")
if(${PENCIL_DEFAULT_FLAGS_MAXFUSE})
set(PENCIL_DEFAULT_FLAGS "--isl-schedule-fuse=max")
else()
set(PENCIL_DEFAULT_FLAGS "--isl-schedule-fuse=min")
endif()
if(${PENCIL_DEFAULT_FLAGS_NO_SEPARATE_COMP})
set(PENCIL_DEFAULT_FLAGS "${PENCIL_DEFAULT_FLAGS};--no-isl-schedule-separate-components")
endif()
if(${PENCIL_DEFAULT_FLAGS_DISABLE_PRIVATE})
set(PENCIL_DEFAULT_FLAGS "${PENCIL_DEFAULT_FLAGS};--no-private-memory")
endif()
if(${PENCIL_DEFAULT_FLAGS_LOCAL_MEMORY_SIZE} GREATER 0)
set(PENCIL_DEFAULT_FLAGS "${PENCIL_DEFAULT_FLAGS};--max-shared-memory=${PENCIL_DEFAULT_FLAGS_LOCAL_MEMORY_SIZE}")
else()
set(PENCIL_DEFAULT_FLAGS "${PENCIL_DEFAULT_FLAGS};--no-shared-memory")
endif()
set(PENCIL_DEFAULT_FLAGS ${PENCIL_DEFAULT_FLAGS} --sizes=\"{kernel[i]->tile[${PENCIL_DEFAULT_FLAGS_BLOCKSIZE}]}\" --sizes=\"{kernel[i]->grid[${PENCIL_DEFAULT_FLAGS_BLOCKSIZE}]}\" --sizes=\"{kernel[i]->block[${PENCIL_DEFAULT_FLAGS_BLOCKSIZE}]}\")
set(PENCIL_REQUIRED_FLAGS "-D__PENCIL__;--target=opencl;--opencl-include-file=${PENCIL_INCLUDE_DIRS}/pencil_opencl.h" CACHE STRING "Required PENCIL compilation flags")
mark_as_advanced(PENCIL_DEFAULT_FLAGS, PENCIL_REQUIRED_FLAGS)
function(pencil_wrap)
cmake_parse_arguments(COMPILE_PENCIL "" "DEST" "FLAGS;FILES" ${ARGN})
set(COMPILE_PENCIL_DEST_INCLUDE_DIRS "${COMPILE_PENCIL_DEST}_GEN_INCLUDE_DIRS")
set(COMPILE_PENCIL_DEST_SOURCES "${COMPILE_PENCIL_DEST}_GEN_SOURCES")
if("${COMPILE_PENCIL_FLAGS}" STREQUAL "")
message(STATUS "FLAGS is not set for ${COMPILE_PENCIL_DEST}, using default PENCIL flags: ${PENCIL_DEFAULT_FLAGS}")
set(COMPILE_PENCIL_FLAGS ${PENCIL_DEFAULT_FLAGS})
endif()
foreach(pencil_file ${COMPILE_PENCIL_FILES})
get_filename_component(PENCIL_FILE_NAME ${pencil_file} NAME_WE)
get_filename_component(PENCIL_FILE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${pencil_file} PATH)
list(APPEND ${COMPILE_PENCIL_DEST_INCLUDE_DIRS} ${PENCIL_FILE_DIRECTORY})
add_custom_command(OUTPUT ${PENCIL_FILE_NAME}.ppcg.c ${PENCIL_FILE_NAME}.ppcg_kernel.cl
COMMAND ${PENCIL_COMPILER}
ARGS ${PENCIL_REQUIRED_FLAGS} ${COMPILE_PENCIL_FLAGS} -I${PENCIL_INCLUDE_DIRS} -o ${PENCIL_FILE_NAME}.ppcg.c ${CMAKE_CURRENT_SOURCE_DIR}/${pencil_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${pencil_file}
)
list(APPEND ${COMPILE_PENCIL_DEST_SOURCES} ${PENCIL_FILE_NAME}.ppcg.c)
endforeach()
set(${COMPILE_PENCIL_DEST_SOURCES} ${${COMPILE_PENCIL_DEST_SOURCES}} PARENT_SCOPE)
set(${COMPILE_PENCIL_DEST_INCLUDE_DIRS} ${${COMPILE_PENCIL_DEST_INCLUDE_DIRS}} PARENT_SCOPE)
endfunction()