diff --git a/.gitignore b/.gitignore index 53fd9a9..037b5c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -build +build* *.ll *.bc diff --git a/CMakeLists.txt b/CMakeLists.txt index d2f5afd..1f97e81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,7 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR) project(STINCILLA CXX) enable_testing() -find_package(AnyDSL-runtime REQUIRED) -include(${ANYDSL_RUNTIME_CMAKE_DIR}/Runtime.cmake) -include_directories(${ANYDSL_RUNTIME_DIR}/src) +find_package(Impala REQUIRED) set(BACKEND ${BACKEND} CACHE STRING "select the backend from the following: CPU, AVX, NVVM, CUDA, OPENCL") if(NOT BACKEND) @@ -14,7 +12,7 @@ endif() string(TOLOWER "${BACKEND}" BACKEND) message(STATUS "Selected backend: ${BACKEND}") -set(BACKEND_FILE intrinsics_${BACKEND}.impala) +set(BACKEND_FILE ${CMAKE_CURRENT_SOURCE_DIR}/intrinsics_${BACKEND}.impala) if(BACKEND STREQUAL "cpu" OR BACKEND STREQUAL "avx") set(DEVICE "cpu") @@ -28,6 +26,21 @@ set(IMPALA_FLAGS --log-level info) set(STINCILLA_COMMON_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/common/pnm_image) include_directories(${STINCILLA_COMMON_INCLUDE_DIRS}) +function (add_test_sample _name) + CMAKE_PARSE_ARGUMENTS ( "PARGS" "" "" "CXX;IMPALA" ${ARGN} ) + set(_infiles ${PARGS_IMPALA}) + set(_cxxfiles ${PARGS_CXX}) + if (NOT (_infiles OR _cxxfiles)) + set(_infiles ${PARGS_UNPARSED_ARGUMENTS}) + endif() + set(_backend_file ${BACKEND_FILE}) + source_group("Impala Files" REGULAR_EXPRESSION "[.]impala$") + wrap_impala_sources(_outfiles OUTPUT_NAME ${_name} CLANG_FLAGS ${CLANG_FLAGS} IMPALA_FLAGS ${IMPALA_FLAGS} FILES ${_infiles} ${_backend_file}) + add_executable(${_name} ${_outfiles} ${_infiles} ${_backend_file} ${_cxxfiles}) + target_link_libraries(${_name} ${Impala_RUNTIME_LIBRARIES}) + add_test("${_name}" ${_name}) +endfunction() + add_subdirectory(aobench) add_subdirectory(bilateral_grid) add_subdirectory(harris_corner) @@ -37,35 +50,9 @@ add_subdirectory(sorting_networks) add_subdirectory(vcycle) # simple CPU-based examples -anydsl_runtime_wrap(MATMUL_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ${BACKEND_FILE} utils.impala matmul.impala) -add_executable(matmul ${MATMUL_PROGRAM}) -target_link_libraries(matmul ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) -add_test("matmul" matmul) +add_test_sample(matmul utils.impala matmul.impala) # examples based on the "mapping" -anydsl_runtime_wrap(GAUSSIAN_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ${BACKEND_FILE} utils.impala stencil_lib.impala mapping_${DEVICE}.impala gaussian.impala) -add_executable(gaussian ${GAUSSIAN_PROGRAM}) -target_link_libraries(gaussian ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) -add_test("gaussian" gaussian) - -anydsl_runtime_wrap(BILATERAL_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ${BACKEND_FILE} utils.impala stencil_lib.impala mapping_${DEVICE}.impala bilateral.impala) -add_executable(bilateral ${BILATERAL_PROGRAM}) -target_link_libraries(bilateral ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) -add_test("bilateral" bilateral) - -anydsl_runtime_wrap(JACOBI_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ${BACKEND_FILE} utils.impala stencil_lib.impala mapping_${DEVICE}.impala jacobi.impala) -add_executable(jacobi ${JACOBI_PROGRAM}) -target_link_libraries(jacobi ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) -add_test("jacobi" jacobi) +add_test_sample(gaussian utils.impala stencil_lib.impala mapping_${DEVICE}.impala gaussian.impala) +add_test_sample(bilateral utils.impala stencil_lib.impala mapping_${DEVICE}.impala bilateral.impala) +add_test_sample(jacobi utils.impala stencil_lib.impala mapping_${DEVICE}.impala jacobi.impala) diff --git a/aobench/CMakeLists.txt b/aobench/CMakeLists.txt index 79212be..eaa0475 100644 --- a/aobench/CMakeLists.txt +++ b/aobench/CMakeLists.txt @@ -1,8 +1,4 @@ -anydsl_runtime_wrap(AOBENCH_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ../${BACKEND_FILE} ../utils.impala mapping_${DEVICE}.impala aobench.impala) -add_executable(aobench main.cpp ${AOBENCH_PROGRAM}) -target_link_libraries(aobench ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) +add_test_sample(aobench + CXX main.cpp + IMPALA ../utils.impala mapping_${DEVICE}.impala aobench.impala) set_target_properties(aobench PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) -add_test("aobench" aobench) diff --git a/aobench/main.cpp b/aobench/main.cpp index f587411..50a317a 100644 --- a/aobench/main.cpp +++ b/aobench/main.cpp @@ -11,6 +11,20 @@ void saveppm(uint8_t* img, int width, int height) { write_pnm_image(img, width, height, "aobench.ppm", pnm_t::P6); } +// polyfill of non-standard drand48() +#ifdef _MSC_VER + +#include +static std::mt19937_64 std_gen64; +static std::uniform_real_distribution std_dist64(0., 1.); +extern "C" void srand48(int64_t seed) { std_gen64.seed(seed); } +extern "C" double drand48() { return std_dist64(std_gen64); } + +static std::uniform_int_distribution std_disti64(-(1 << 31), 1 << 31); +extern "C" int64_t mrand48() { return std_disti64(std_gen64); } + +#endif // _MSC_VER + /************************************************************************* * Main function * *************************************************************************/ diff --git a/bilateral_grid/CMakeLists.txt b/bilateral_grid/CMakeLists.txt index 3f27ba7..d6fbfca 100644 --- a/bilateral_grid/CMakeLists.txt +++ b/bilateral_grid/CMakeLists.txt @@ -1,9 +1,5 @@ -anydsl_runtime_wrap(BILATERAL_GRID_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ../${BACKEND_FILE} ../utils.impala mapping_${DEVICE}.impala bilateral_grid.impala) -add_executable(bilateral_grid main.cpp ${BILATERAL_GRID_PROGRAM}) -target_link_libraries(bilateral_grid ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) +add_test_sample(bilateral_grid + CXX main.cpp + IMPALA ../utils.impala mapping_${DEVICE}.impala bilateral_grid.impala) set_target_properties(bilateral_grid PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) -add_test("bilateral_grid" bilateral_grid) configure_file(../common/lena.pgm ${CMAKE_CURRENT_BINARY_DIR}/lena.pgm COPYONLY) diff --git a/harris_corner/CMakeLists.txt b/harris_corner/CMakeLists.txt index dbf3185..ee8a633 100644 --- a/harris_corner/CMakeLists.txt +++ b/harris_corner/CMakeLists.txt @@ -1,9 +1,5 @@ -anydsl_runtime_wrap(HARRIS_CORNER_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ../${BACKEND_FILE} ../utils.impala ../stencil_lib.impala ../mapping_${DEVICE}.impala harris_corner.impala) -add_executable(harris_corner main.cpp ${HARRIS_CORNER_PROGRAM}) -target_link_libraries(harris_corner ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) +add_test_sample(harris_corner + CXX main.cpp + IMPALA ../utils.impala ../stencil_lib.impala ../mapping_${DEVICE}.impala harris_corner.impala) set_target_properties(harris_corner PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) -add_test("harris_corner" harris_corner) configure_file(../common/lena.pgm ${CMAKE_CURRENT_BINARY_DIR}/lena.pgm COPYONLY) diff --git a/image_sharpening/CMakeLists.txt b/image_sharpening/CMakeLists.txt index 50d8813..94826f5 100644 --- a/image_sharpening/CMakeLists.txt +++ b/image_sharpening/CMakeLists.txt @@ -1,9 +1,5 @@ -anydsl_runtime_wrap(SHARPENING_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ../${BACKEND_FILE} ../utils.impala ../stencil_lib.impala ../mapping_${DEVICE}.impala mapping_${DEVICE}.impala sharpening.impala) -add_executable(sharpening main.cpp ${SHARPENING_PROGRAM}) -target_link_libraries(sharpening ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) +add_test_sample(sharpening + CXX main.cpp + IMPALA ../utils.impala ../stencil_lib.impala ../mapping_${DEVICE}.impala mapping_${DEVICE}.impala sharpening.impala) set_target_properties(sharpening PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) -add_test("sharpening" sharpening) configure_file(goldhill.pgm ${CMAKE_CURRENT_BINARY_DIR}/goldhill.pgm COPYONLY) diff --git a/sorting_networks/CMakeLists.txt b/sorting_networks/CMakeLists.txt index df3c381..5800a98 100644 --- a/sorting_networks/CMakeLists.txt +++ b/sorting_networks/CMakeLists.txt @@ -1,7 +1,2 @@ -anydsl_runtime_wrap(MEDIAN_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ../${BACKEND_FILE} ../utils.impala ../stencil_lib.impala ../mapping_${DEVICE}.impala mapping_${DEVICE}.impala oddeven.impala median.impala) -add_executable(median ${MEDIAN_PROGRAM}) -target_link_libraries(median ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) -add_test("median" median) +add_test_sample(median + ../utils.impala ../stencil_lib.impala ../mapping_${DEVICE}.impala mapping_${DEVICE}.impala oddeven.impala median.impala) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 74f4b3d..fa09b04 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,51 +1,21 @@ -anydsl_runtime_wrap(STENCIL_INT_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} +wrap_impala_sources(STENCIL_INT_PROGRAM FILES stencil_dsl.impala) add_executable(stencil_dsl ${STENCIL_INT_PROGRAM}) -target_link_libraries(stencil_dsl ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) +target_link_libraries(stencil_dsl ${Impala_RUNTIME_LIBRARIES}) add_test("stencil_dsl" stencil_dsl) if(NOT (BACKEND STREQUAL "cpu" OR BACKEND STREQUAL "avx")) - anydsl_runtime_wrap(MULTI_GPU_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ../${BACKEND_FILE} ../utils.impala multi_gpu.impala) - add_executable(multi_gpu ${MULTI_GPU_PROGRAM}) - target_link_libraries(multi_gpu ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) - add_test("multi_gpu" multi_gpu) - - anydsl_runtime_wrap(ALLOC_GPU_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ../${BACKEND_FILE} alloc_gpu.impala) - add_executable(alloc_gpu ${ALLOC_GPU_PROGRAM}) - target_link_libraries(alloc_gpu ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) - add_test("alloc_gpu" alloc_gpu) - - anydsl_runtime_wrap(ALLOC_GPU_UNIFIED_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ../${BACKEND_FILE} alloc_gpu_unified.impala) - add_executable(alloc_gpu_unified ${ALLOC_GPU_UNIFIED_PROGRAM}) - target_link_libraries(alloc_gpu_unified ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) - add_test("alloc_gpu_unified" alloc_gpu_unified) - - anydsl_runtime_wrap(RESERVE_SHARED_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ../${BACKEND_FILE} reserve_shared.impala) - add_executable(reserve_shared ${RESERVE_SHARED_PROGRAM}) - target_link_libraries(reserve_shared ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) - add_test("reserve_shared" reserve_shared) + add_test_sample(multi_gpu ../utils.impala multi_gpu.impala) + add_test_sample(alloc_gpu alloc_gpu.impala) + add_test_sample(alloc_gpu_unified alloc_gpu_unified.impala) + add_test_sample(reserve_shared reserve_shared.impala) if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") - anydsl_runtime_wrap(HALF_FLOAT_GPU_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ../${BACKEND_FILE} half_float_gpu.impala) - add_executable(half_float_gpu ${HALF_FLOAT_GPU_PROGRAM}) - target_link_libraries(half_float_gpu ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) - add_test("half_float_gpu" half_float_gpu) + # wrap_impala_sources(HALF_FLOAT_GPU_PROGRAM + # FILES ../${BACKEND_FILE} half_float_gpu.impala) + # add_executable(half_float_gpu ${HALF_FLOAT_GPU_PROGRAM}) + # target_link_libraries(half_float_gpu ${IMPALA_RUNTIME_LIBRARIES}) + # add_test("half_float_gpu" half_float_gpu) + add_test_sample(half_float_gpu half_float_gpu.impala) endif() endif() diff --git a/vcycle/CMakeLists.txt b/vcycle/CMakeLists.txt index 88edd2a..4d29386 100644 --- a/vcycle/CMakeLists.txt +++ b/vcycle/CMakeLists.txt @@ -1,9 +1,5 @@ -anydsl_runtime_wrap(VCYCLE_PROGRAM - CLANG_FLAGS ${CLANG_FLAGS} - IMPALA_FLAGS ${IMPALA_FLAGS} - FILES ../${BACKEND_FILE} ../utils.impala ../stencil_lib.impala ../mapping_${DEVICE}.impala mapping_${DEVICE}.impala vcycle.impala) -add_executable(vcycle main.cpp ${VCYCLE_PROGRAM}) -target_link_libraries(vcycle ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES}) +add_test_sample(vcycle + CXX main.cpp + IMPALA ../utils.impala ../stencil_lib.impala ../mapping_${DEVICE}.impala mapping_${DEVICE}.impala vcycle.impala) set_target_properties(vcycle PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) -add_test("vcycle" vcycle) configure_file(../common/lena.pgm ${CMAKE_CURRENT_BINARY_DIR}/lena.pgm COPYONLY)