Skip to content

Commit

Permalink
Version 1.0 release
Browse files Browse the repository at this point in the history
Co-authored-by: John F. Carr <[email protected]>
Co-authored-by: Tim Kaler <[email protected]>
Co-authored-by: Angelina Lee <[email protected]>
Co-authored-by: TB Schardl <[email protected]>
  • Loading branch information
4 people committed Mar 5, 2021
1 parent cb3d271 commit c50197a
Show file tree
Hide file tree
Showing 64 changed files with 2,263 additions and 1,532 deletions.
31 changes: 21 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CMake build for Cheetah.

cmake_minimum_required(VERSION 3.4.3)
cmake_minimum_required(VERSION 3.9)

if(POLICY CMP0068)
cmake_policy(SET CMP0068 NEW)
Expand All @@ -16,11 +16,11 @@ set(CMAKE_MODULE_PATH

# Check if cheetah is built as a standalone project.
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR CHEETAH_STANDALONE_BUILD)
project(cheetah CXX C)
project(Cheetah CXX C)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

set(PACKAGE_NAME cheetah)
set(PACKAGE_VERSION 9.0.1)
set(PACKAGE_NAME Cheetah)
set(PACKAGE_VERSION 10.0.1)
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "[email protected]")

Expand Down Expand Up @@ -56,13 +56,17 @@ set(CHEETAH_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")

option(CHEETAH_ENABLE_SHARED "Build cheetah as a shared library." ON)
option(CHEETAH_ENABLE_STATIC "Build cheetah as a static library." ON)
option(CHEETAH_ENABLE_BITCODE_ABI "Build cheetah ABI as LLVM bitcode." ON)

cmake_dependent_option(CHEETAH_INSTALL_STATIC_LIBRARY
"Install the static cheetah library." ON
"CHEETAH_ENABLE_STATIC;CHEETAH_INSTALL_LIBRARY" OFF)
cmake_dependent_option(CHEETAH_INSTALL_SHARED_LIBRARY
"Install the shared cheetah library." ON
"CHEETAH_ENABLE_SHARED;CHEETAH_INSTALL_LIBRARY" OFF)
cmake_dependent_option(CHEETAH_INSTALL_BITCODE_ABI
"Install the cheetah ABI LLVM bitcode." ON
"CHEETAH_ENABLE_BITCODE_ABI;CHEETAH_INSTALL_LIBRARY" OFF)

set(CHEETAH_ABI_VERSION "1" CACHE STRING "ABI version of cheetah. Defaults to 1.")

Expand All @@ -71,9 +75,10 @@ if (NOT CHEETAH_ENABLE_SHARED AND NOT CHEETAH_ENABLE_STATIC)
endif()

# Target options --------------------------------------------------------------
set(CHEETAH_SYSROOT "" CACHE STRING "Use alternate sysroot.")
set(CHEETAH_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.")
set(CHEETAH_MIN_OSX_VERSION 10.9)

# Default minimum OSX version to support, if
# CMAKE_OSX_DEPLOYMENT_TARGET is not specified
set(CHEETAH_MIN_OSX_VERSION 10.14)

#===============================================================================
# Configure System
Expand Down Expand Up @@ -126,13 +131,15 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CHEETAH_LIBRARY_DIR})
set(CHEETAH_C_FLAGS "")
set(CHEETAH_CXX_FLAGS "")
set(CHEETAH_COMPILE_FLAGS "")
if (APPLE)
list(APPEND CHEETAH_COMPILE_FLAGS -mmacosx-version-min=${CHEETAH_MIN_OSX_VERSION})
endif()
set(CHEETAH_COMPILE_DEFS "")
set(CHEETAH_LINK_FLAGS "")
set(CHEETAH_LIBRARIES "")

if (APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
list(APPEND CHEETAH_COMPILE_FLAGS -mmacosx-version-min=${CHEETAH_MIN_OSX_VERSION})
list(APPEND CHEETAH_LINK_FLAGS -mmacosx-version-min=${CHEETAH_MIN_OSX_VERSION})
endif()

# Include macros for adding and removing cheetah flags.
include(HandleCheetahFlags)

Expand Down Expand Up @@ -164,6 +171,10 @@ endif()
# Configure compiler.
include(config-ix)

if (APPLE AND CHEETAH_HAS_APP_EXTENSION)
list(APPEND CHEETAH_LINK_FLAGS "-fapplication-extension")
endif()

if (CHEETAH_USE_COMPILER_RT)
list(APPEND CHEETAH_LINK_FLAGS "--rtlib=compiler-rt")
endif()
Expand Down
13 changes: 13 additions & 0 deletions cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ include(CheckLibraryExists)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)

function(check_linker_flag flag out_var)
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}")
check_cxx_compiler_flag("" ${out_var})
cmake_pop_check_state()
endfunction()

check_library_exists(c fopen "" CHEETAH_HAS_C_LIB)
if (NOT CHEETAH_USE_COMPILER_RT)
check_library_exists(gcc_s __gcc_personality_v0 "" CHEETAH_HAS_GCC_S_LIB)
Expand All @@ -14,3 +21,9 @@ check_library_exists(rt clock_gettime "" CHEETAH_HAS_RT_LIB)

# Check compiler flags
check_c_compiler_flag(-fomit-frame-pointer CHEETAH_HAS_FOMIT_FRAME_POINTER_FLAG)
check_c_compiler_flag(-mavx -Werror CHEETAH_HAS_MAVX_FLAG)
check_c_compiler_flag(-march=sandybridge -Werror CHEETAH_HAS_MARCH_SANDYBRIDGE_FLAG)

if (APPLE)
check_linker_flag("-fapplication-extension" CHEETAH_HAS_APP_EXTENSION)
endif()
1 change: 1 addition & 0 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ COMPILER_BASE=
CC=$(COMPILER_BASE)clang
CXX=$(COMPILER_BASE)clang++
LINK_CC=$(CC)
LLVM_LINK=$(COMPILER_BASE)llvm-link
#
ABI_DEF=-DOPENCILK_ABI
# If use cheetah
Expand Down
18 changes: 9 additions & 9 deletions handcomp_test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TIMING_COUNT := 1

all: $(TESTS)

$(TESTS): %: %.o ktiming.o getoptions.o
$(TESTS): %: %.o ktiming.o getoptions.o ZERO.o
$(CC) $^ -o $@ $(RTS_LIBS) -lrt -lpthread -lm

%.o: %.c
Expand All @@ -28,18 +28,18 @@ $(TESTS): %: %.o ktiming.o getoptions.o
memcheck:
$(MAKE) clean; $(MAKE) > /dev/null
date
valgrind ./fib --cheetah-nproc 8 26
valgrind ./mm_dac --cheetah-nproc 8 -n 512
valgrind ./cilksort --cheetah-nproc 8 -n 3000000
valgrind ./nqueens --cheetah-nproc 8 10
CILK_NWORKERS=8 valgrind ./fib 26
CILK_NWORKERS=8 valgrind ./mm_dac -n 512
CILK_NWORKERS=8 valgrind ./cilksort -n 3000000
CILK_NWORKERS=8 valgrind ./nqueens 10
date

check:
$(MAKE) clean; $(MAKE) TIMING_COUNT=5 > /dev/null
./fib --cheetah-nproc $(MANYPROC) 40
./mm_dac --cheetah-nproc $(MANYPROC) -n 1024 -c
./cilksort --cheetah-nproc $(MANYPROC) -n 30000000 -c
./nqueens --cheetah-nproc $(MANYPROC) 14
CILK_NWORKERS=$(MANYPROC) ./fib 40
CILK_NWORKERS=$(MANYPROC) ./mm_dac -n 1024 -c
CILK_NWORKERS=$(MANYPROC) ./cilksort -n 30000000 -c
CILK_NWORKERS=$(MANYPROC) ./nqueens 14

clean:
rm -f *.o *~ $(TESTS) core.*
16 changes: 10 additions & 6 deletions handcomp_test/cilksort.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@
#include <string.h>

#include "../runtime/cilk2c.h"
#include "../runtime/cilk2c_inlined.c"
#include "ktiming.h"
#include "getoptions.h"

extern size_t ZERO;
void __attribute__((weak)) dummy(void *p) { return; }

#ifndef TIMING_COUNT
#define TIMING_COUNT 0
Expand Down Expand Up @@ -346,7 +348,7 @@ void cilkmerge(ELM *low1, ELM *high1,
return;
}

alloca(ZERO);
dummy(alloca(ZERO));
__cilkrts_stack_frame sf;
__cilkrts_enter_frame(&sf);

Expand Down Expand Up @@ -383,7 +385,8 @@ void cilkmerge(ELM *low1, ELM *high1,
}

__cilkrts_pop_frame(&sf);
__cilkrts_leave_frame(&sf);
if (0 != sf.flags)
__cilkrts_leave_frame(&sf);

return;
}
Expand Down Expand Up @@ -421,7 +424,7 @@ void cilksort(ELM *low, ELM *tmp, long size) {
return;
}

alloca(ZERO);
dummy(alloca(ZERO));
__cilkrts_stack_frame sf;
__cilkrts_enter_frame(&sf);

Expand Down Expand Up @@ -479,7 +482,8 @@ void cilksort(ELM *low, ELM *tmp, long size) {
cilkmerge(tmpA, tmpC - 1, tmpC, tmpA + size - 1, A);

__cilkrts_pop_frame(&sf);
__cilkrts_leave_frame(&sf);
if (0 != sf.flags)
__cilkrts_leave_frame(&sf);

return;
}
Expand Down Expand Up @@ -527,7 +531,7 @@ int usage(void) {
const char *specifiers[] = {"-n", "-c", "-h", 0};
int opt_types[] = {LONGARG, BOOLARG, BOOLARG, 0};

int cilk_main(int argc, char **argv) {
int main(int argc, char **argv) {

long size;
ELM *array, *tmp;
Expand All @@ -553,7 +557,7 @@ int cilk_main(int argc, char **argv) {
begin = ktiming_getmark();
cilksort(array, tmp, size);
end = ktiming_getmark();
elapsed[i] = ktiming_diff_usec(&begin, &end);
elapsed[i] = ktiming_diff_nsec(&begin, &end);
}
print_runtime(elapsed, TIMING_COUNT);

Expand Down
11 changes: 7 additions & 4 deletions handcomp_test/fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdlib.h>

#include "../runtime/cilk2c.h"
#include "../runtime/cilk2c_inlined.c"
#include "ktiming.h"


Expand Down Expand Up @@ -31,6 +32,7 @@ int fib(int n) {
*/

extern size_t ZERO;
void __attribute__((weak)) dummy(void *p) { return; }

static void __attribute__ ((noinline)) fib_spawn_helper(int *x, int n);

Expand All @@ -40,7 +42,7 @@ int fib(int n) {
if(n < 2)
return n;

alloca(ZERO);
dummy(alloca(ZERO));
__cilkrts_stack_frame sf;
__cilkrts_enter_frame(&sf);

Expand All @@ -62,7 +64,8 @@ int fib(int n) {
_tmp = x + y;

__cilkrts_pop_frame(&sf);
__cilkrts_leave_frame(&sf);
if (0 != sf.flags)
__cilkrts_leave_frame(&sf);

return _tmp;
}
Expand All @@ -77,7 +80,7 @@ static void __attribute__ ((noinline)) fib_spawn_helper(int *x, int n) {
__cilkrts_leave_frame(&sf);
}

int cilk_main(int argc, char * args[]) {
int main(int argc, char * args[]) {
int i;
int n, res;
clockmark_t begin, end;
Expand All @@ -94,7 +97,7 @@ int cilk_main(int argc, char * args[]) {
begin = ktiming_getmark();
res = fib(n);
end = ktiming_getmark();
running_time[i] = ktiming_diff_usec(&begin, &end);
running_time[i] = ktiming_diff_nsec(&begin, &end);
}
printf("Result: %d\n", res);
print_runtime(running_time, TIMING_COUNT);
Expand Down
56 changes: 28 additions & 28 deletions handcomp_test/ktiming.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* Copyright (c) 2012 MIT License by 6.172 Staff
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -31,18 +31,18 @@

#include "./ktiming.h"

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define USEC_TO_SEC(x) ((double)x*1.0e-9)

#define NSEC_TO_SEC(x) ((double)(x)*1.0e-9)

clockmark_t ktiming_getmark(void) {
struct timespec temp;
struct timespec temp = {0, 0};
uint64_t nanos;

int stat = clock_gettime(CLOCK_MONOTONIC , &temp);
int stat = clock_gettime(CLOCK_MONOTONIC, &temp);
if (stat != 0) {
perror("ktiming_getmark()");
exit(-1);
Expand All @@ -52,43 +52,44 @@ clockmark_t ktiming_getmark(void) {
return nanos;
}

uint64_t ktiming_diff_usec(const clockmark_t* const
start, const clockmark_t* const end) {
uint64_t ktiming_diff_nsec(const clockmark_t *const start,
const clockmark_t *const end) {
return *end - *start;
}

double ktiming_diff_sec(const clockmark_t* const start,
const clockmark_t* const end) {
return ((double)ktiming_diff_usec(start, end)) / 1000000000.0f;
double ktiming_diff_sec(const clockmark_t *const start,
const clockmark_t *const end) {
return NSEC_TO_SEC(ktiming_diff_nsec(start, end));
}

static void
print_runtime_helper(uint64_t *usec_elapsed, int size, int summary) {
static void print_runtime_helper(uint64_t *nsec_elapsed, int size,
int summary) {

int i;
int i;
uint64_t total = 0;
double ave, std_dev = 0, dev_sq_sum = 0;

for (i = 0; i < size; i++) {
total += usec_elapsed[i];
if(!summary) {
printf("Running time %d: %gs\n", (i + 1), USEC_TO_SEC(usec_elapsed[i]));
total += nsec_elapsed[i];
if (!summary) {
printf("Running time %d: %gs\n", (i + 1),
NSEC_TO_SEC(nsec_elapsed[i]));
}
}
ave = total / size;
if( size > 1 ) {

if (size > 1) {
for (i = 0; i < size; i++) {
dev_sq_sum += ( (ave - (double)usec_elapsed[i]) *
(ave - (double)usec_elapsed[i]) );
double diff = (double)nsec_elapsed[i] - ave;
dev_sq_sum += diff * diff;
}
std_dev = dev_sq_sum / (size-1);
std_dev = sqrt(dev_sq_sum / (size - 1));
}

printf("Running time average: %g s\n", USEC_TO_SEC(ave));
if( std_dev != 0 ) {
printf( "Std. dev: %g s (%2.3f%%)\n",
USEC_TO_SEC(std_dev), 100.0*USEC_TO_SEC(std_dev/ave) );
printf("Running time average: %g s\n", NSEC_TO_SEC(ave));
if (std_dev != 0) {
printf("Std. dev: %g s (%2.3f%%)\n", NSEC_TO_SEC(std_dev),
100.0 * std_dev / ave);
}
}

Expand All @@ -99,4 +100,3 @@ void print_runtime(uint64_t *tm_elapsed, int size) {
void print_runtime_summary(uint64_t *tm_elapsed, int size) {
print_runtime_helper(tm_elapsed, size, 1);
}

2 changes: 1 addition & 1 deletion handcomp_test/ktiming.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
typedef uint64_t clockmark_t;

uint64_t
ktiming_diff_usec(const clockmark_t* const start, const clockmark_t* const end);
ktiming_diff_nsec(const clockmark_t* const start, const clockmark_t* const end);
double
ktiming_diff_sec(const clockmark_t* const start, const clockmark_t* const end);
clockmark_t ktiming_getmark(void);
Expand Down
Loading

0 comments on commit c50197a

Please sign in to comment.