Skip to content

Commit

Permalink
Merge pull request #178 from klimkin/feature/build-with-cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
emeryberger authored Mar 19, 2021
2 parents 381cbe5 + fafd230 commit 2e6c4a1
Show file tree
Hide file tree
Showing 41 changed files with 336 additions and 391 deletions.
14 changes: 9 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ branches:
# Install dependencies
before_install:
- sudo apt-get update
- sudo apt-get install -y --install-recommends docutils-common libelfin-dev nodejs npm
- sudo apt-get install -y --install-recommends build-essential cmake ninja-build docutils-common nodejs npm
- sudo pip install conan

# Make and install
install:
- make
- sudo make install
- mkdir build && cd build
- conan install .. -s compiler.libcxx=libstdc++11 -s compiler.cppstd=11 --build=outdated
- cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_BENCHMARKS=ON -G Ninja
- ninja
- sudo ninja install

# Run the make check target (add tests later)
# Run tests
script:
- make check USE_SYSTEM_COZ=1
- CTEST_OUTPUT_ON_FAILURE=1 ninja test

# Test the Rust support as well
matrix:
Expand Down
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.4)
project(coz C CXX)

enable_testing()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CONAN_CMAKE_SILENT_OUTPUT ON)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake)

find_package(Threads REQUIRED)
find_package(libelfin REQUIRED)

add_compile_options(-gdwarf-3)

add_subdirectory(libcoz)

option(BUILD_BENCHMARKS "Build benchmarks" OFF)
if(BUILD_BENCHMARKS)
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
message(FATAL_ERROR "Build benchmarks with debug information - use Debug or RelWithDebInfo")
endif()
find_package(SQLite3 REQUIRED)
find_package(BZip2 REQUIRED)
add_subdirectory(benchmarks)
endif()

option(INSTALL_COZ "Enable installation of coz. (Projects embedding coz may want to turn this OFF.)" ON)
if(INSTALL_COZ)
include(GNUInstallDirs)
install(PROGRAMS coz DESTINATION bin)
install(FILES LICENSE.md DESTINATION licenses)
install(FILES cmake/coz-profilerConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
endif()
24 changes: 0 additions & 24 deletions Makefile

This file was deleted.

10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ To build Coz from source, you will need:
- A copy of the source code for this project
- A compiler with C++0x support (clang++ or g++)
- A Python interpreter (Python 3.x is required)
- The libelfin development libraries (Use release 0.2 or the latest from <https://github.com/aclements/libelfin>. _Version 0.3 does not work_.)
- The libelfin development libraries (Use latest from <https://github.com/aclements/libelfin>. _Version 0.3 does not work_.)
- The `rst2man` command (for building documentation)
- NodeJS and npm (for building the profiler viewer)

Once you have all dependencies in place, run `make` to build Coz. On Debian-based distributions, the following commands should take care of the entire process:
Once you have all dependencies in place, build Coz with CMake. On Debian-based distributions, the following commands should take care of the entire process:

```
$ sudo apt-get install clang docutils-common libelfin-dev nodejs npm python3
$ sudo apt-get install build-essential cmake docutils-common libelfin-dev nodejs npm python3
$ pip install conan --user
$ git clone https://github.com/plasma-umass/coz.git
$ cd coz
$ mkdir build && cd build
$ conan install ..
$ cmake ..
$ make
```

Expand Down
25 changes: 0 additions & 25 deletions benchmark.mk

This file was deleted.

18 changes: 18 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function(add_coz_run_target name)
set(one_value_args "")
set(multi_value_args COMMAND)
set(options "")
cmake_parse_arguments(COZ_RUN "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})

add_custom_target(${name}
COMMENT "Running coz for ${name}"
COMMAND ${PROJECT_SOURCE_DIR}/coz run --- ${COZ_RUN_COMMAND}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
DEPENDS coz)
endfunction()

file(GLOB cmake_files */CMakeLists.txt)
foreach(filepath ${cmake_files})
get_filename_component(dir ${filepath} DIRECTORY)
add_subdirectory(${dir})
endforeach(filepath)
16 changes: 0 additions & 16 deletions benchmarks/Makefile

This file was deleted.

11 changes: 11 additions & 0 deletions benchmarks/check-output.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -e
rm -f profile.coz

$@

grep -q "time=" profile.coz || { echo failure: valid profile.coz not generated; exit 1; }
grep -q "throughput-point" profile.coz || { echo failure: throughput-point not found in profile; exit 1; }
grep -q -P "samples\tlocation=" profile.coz || { echo failure: samples not found in profile; exit 1; }
echo success: benchmark generated valid profile.coz
23 changes: 23 additions & 0 deletions benchmarks/histogram/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
add_executable(histogram histogram-pthread.c)
target_link_libraries(histogram PRIVATE coz-instrumentation pthread)

add_custom_command(
COMMENT "Downloading histogram inputs"
OUTPUT
histogram_datafiles/small.bmp
histogram_datafiles/large.bmp
COMMAND wget -cq http://csl.stanford.edu/~christos/data/histogram.tar.gz
COMMAND tar xzf histogram.tar.gz)

add_custom_target(histogram_datafiles
DEPENDS
histogram_datafiles/small.bmp
histogram_datafiles/large.bmp)

add_coz_run_target(run_histogram_large
COMMAND $<TARGET_FILE:histogram> ${CMAKE_CURRENT_BINARY_DIR}/histogram_datafiles/large.bmp)
add_dependencies(run_histogram_large histogram_datafiles)

add_coz_run_target(run_histogram_small
COMMAND $<TARGET_FILE:histogram> ${CMAKE_CURRENT_BINARY_DIR}/histogram_datafiles/small.bmp)
add_dependencies(run_histogram_small histogram_datafiles)
20 changes: 0 additions & 20 deletions benchmarks/histogram/Makefile

This file was deleted.

10 changes: 10 additions & 0 deletions benchmarks/kmeans/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_executable(kmeans kmeans-pthread.c)
target_link_libraries(kmeans PRIVATE coz-instrumentation pthread)

add_coz_run_target(run_kmeans_small COMMAND $<TARGET_FILE:kmeans> -d 3 -c 100 -p 10000 -s 100)
add_coz_run_target(run_kmeans_large COMMAND $<TARGET_FILE:kmeans> -d 3 -c 100 -p 100000 -s 1000)

add_test(
NAME test_run_kmeans
COMMAND ${PROJECT_SOURCE_DIR}/benchmarks/check-output.sh ${PROJECT_SOURCE_DIR}/coz run --- $<TARGET_FILE:kmeans>
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
9 changes: 0 additions & 9 deletions benchmarks/kmeans/Makefile

This file was deleted.

23 changes: 23 additions & 0 deletions benchmarks/linear_regression/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
add_executable(linear_regression linear_regression-pthread.c)
target_link_libraries(linear_regression PRIVATE coz-instrumentation pthread)

add_custom_command(
COMMENT "Downloading linear_regression inputs"
OUTPUT
linear_regression_datafiles/key_file_500MB.txt
linear_regression_datafiles/key_file_50MB.txt
COMMAND wget -cq http://csl.stanford.edu/~christos/data/linear_regression.tar.gz
COMMAND tar xzf linear_regression.tar.gz)

add_custom_target(linear_regression_datafiles
DEPENDS
linear_regression_datafiles/key_file_500MB.txt
linear_regression_datafiles/key_file_50MB.txt)

add_coz_run_target(run_linear_regression_large
COMMAND $<TARGET_FILE:linear_regression> ${CMAKE_CURRENT_BINARY_DIR}/linear_regression_datafiles/key_file_500MB.txt)
add_dependencies(run_linear_regression_large linear_regression_datafiles)

add_coz_run_target(run_linear_regression_small
COMMAND $<TARGET_FILE:linear_regression> ${CMAKE_CURRENT_BINARY_DIR}/linear_regression_datafiles/key_file_50MB.txt)
add_dependencies(run_linear_regression_small linear_regression_datafiles)
20 changes: 0 additions & 20 deletions benchmarks/linear_regression/Makefile

This file was deleted.

31 changes: 31 additions & 0 deletions benchmarks/matrix_multiply/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
add_executable(matrix_multiply matrix_multiply-pthread.c)
target_link_libraries(matrix_multiply PRIVATE coz-instrumentation pthread)
target_compile_options(matrix_multiply PRIVATE -Wno-format)

add_custom_command(
COMMENT "Generating bench input"
OUTPUT ${PROJECT_BINARY_DIR}/matrix_file_A_1000.txt ${PROJECT_BINARY_DIR}/matrix_file_B_1000.txt
BYPRODUCTS ${PROJECT_BINARY_DIR}/matrix_file_out_pthreads_1000.txt
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/matrix_multiply 1000 -create_files > /dev/null
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
DEPENDS matrix_multiply)
add_custom_target(matrix_multiply_large_datafiles
DEPENDS ${PROJECT_BINARY_DIR}/matrix_file_A_1000.txt ${PROJECT_BINARY_DIR}/matrix_file_B_1000.txt)

add_custom_command(
COMMENT "Generating test input"
OUTPUT ${PROJECT_BINARY_DIR}/matrix_file_A_400.txt ${PROJECT_BINARY_DIR}/matrix_file_B_400.txt
BYPRODUCTS ${PROJECT_BINARY_DIR}/matrix_file_out_pthreads_400.txt
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/matrix_multiply 400 -create_files > /dev/null
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
DEPENDS matrix_multiply)
add_custom_target(matrix_multiply_small_datafiles
DEPENDS ${PROJECT_BINARY_DIR}/matrix_file_A_400.txt ${PROJECT_BINARY_DIR}/matrix_file_B_400.txt)

add_coz_run_target(run_matrix_multiply_large
COMMAND $<TARGET_FILE:matrix_multiply> 1000 > /dev/null)
add_dependencies(run_matrix_multiply_large matrix_multiply_large_datafiles)

add_coz_run_target(run_matrix_multiply_small
COMMAND $<TARGET_FILE:matrix_multiply> 400 > /dev/null)
add_dependencies(run_matrix_multiply_small matrix_multiply_small_datafiles)
25 changes: 0 additions & 25 deletions benchmarks/matrix_multiply/Makefile

This file was deleted.

10 changes: 5 additions & 5 deletions benchmarks/matrix_multiply/matrix_multiply-pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ int main(int argc, char *argv[]) {
char * fdata_A, *fdata_B;
int matrix_len;
struct stat finfo_A, finfo_B;
char * fname_A, *fname_B,*fname_out;
char fname_A[512], fname_B[512], fname_out[512];
int *matrix_A_ptr, *matrix_B_ptr;

struct timeval starttime,endtime;
Expand All @@ -181,14 +181,14 @@ int main(int argc, char *argv[]) {
// Make sure a filename is specified
if (argv[1] == NULL)
{
printf("USAGE: %s [side of matrix] [size of Row block]\n", argv[0]);
printf("USAGE: %s size_of_matrix [-create_files]\n", argv[0]);
exit(1);
}

fname_A = "matrix_file_A.txt";
fname_B = "matrix_file_B.txt";
fname_out = "matrix_file_out_pthreads.txt";
CHECK_ERROR ( (matrix_len = atoi(argv[1])) < 0);
sprintf(fname_A, "matrix_file_A_%d.txt", matrix_len);
sprintf(fname_B, "matrix_file_B_%d.txt", matrix_len);
sprintf(fname_out, "matrix_file_out_pthreads_%d.txt", matrix_len);
file_size = ((matrix_len*matrix_len))*sizeof(int);

fprintf(stderr, "***** file size is %d\n", file_size);
Expand Down
14 changes: 14 additions & 0 deletions benchmarks/pbzip2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_executable(pbzip2 BZ2StreamScanner.cpp ErrorContext.cpp pbzip2.cpp)
target_link_libraries(pbzip2 PRIVATE BZip2::BZip2 coz-instrumentation pthread)
target_compile_options(pbzip2 PRIVATE -Wno-format)

set(datafiles ${CMAKE_CURRENT_BINARY_DIR}/../linear_regression/linear_regression_datafiles)

add_coz_run_target(run_pbzip2_large
COMMAND $<TARGET_FILE:pbzip2> -c < ${datafiles}/key_file_500MB.txt > ${CMAKE_CURRENT_BINARY_DIR}/key_file_500MB_compressed.bz2)
add_dependencies(run_pbzip2_large linear_regression_datafiles)

add_coz_run_target(run_pbzip2_small
COMMAND $<TARGET_FILE:pbzip2> -c < ${datafiles}/key_file_50MB.txt > ${CMAKE_CURRENT_BINARY_DIR}/key_file_50MB_compressed.bz2)
add_dependencies(run_pbzip2_small linear_regression_datafiles)

Loading

0 comments on commit 2e6c4a1

Please sign in to comment.