From d75fad88de6022677536bacbceb72452bbeea2de Mon Sep 17 00:00:00 2001 From: ZerataX Date: Thu, 9 Apr 2020 17:57:08 +0200 Subject: [PATCH 1/3] clean up makefiles and readme --- .github/workflows/docs.yml | 2 +- README.MD | 93 ++++++++++++++++++++++++++++++-------- examples/makefile | 25 ---------- makefile | 56 +++-------------------- test/makefile | 25 ---------- 5 files changed, 83 insertions(+), 118 deletions(-) delete mode 100644 examples/makefile delete mode 100644 test/makefile diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 60f3aa9..490cfdd 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -14,7 +14,7 @@ jobs: - name: Install Dependencies run: sudo apt-get install doxygen - name: Build - run: doxygen Doxyfile + run: make docs - name: Deploy uses: JamesIves/github-pages-deploy-action@releases/v3 with: diff --git a/README.MD b/README.MD index a30fd84..357d491 100644 --- a/README.MD +++ b/README.MD @@ -10,19 +10,24 @@ wrapper to easily compile and execute cuda kernels - online compilation with NVRTC - template kernels - logging system -- simple to understand exceptions -- time kernel execution as well as uploading and downloading arguments to and from the device +- descriptive exceptions +- benchmarking + - time kernel execution as well as uploading and downloading arguments to and from the device for more see the [changelog](./CHANGELOG.md) ## Requirements - - [Cuda Toolkit >= V7.0](https://developer.nvidia.com/cuda-toolkit) - - c++17 (just to build) + - [Cuda Toolkit >= V7.0 (recommended 9.3)](https://developer.nvidia.com/cuda-toolkit) + - C++17 (just to build) + - JDK >= 8 (to build the JNI) -## Usage +## C++ + +### Usage ```c++ +// file.cpp #include "yacx/main.hpp" #include #include @@ -85,7 +90,7 @@ int main() { } ``` -### Compile +#### Compile download the latest version of the library from the [releases](https://github.com/ZerataX/yacx/releases/latest) section or build it yourself: @@ -98,7 +103,7 @@ make -C build yacx-jni and then compile with: ```console -g++ -Wall -Wextra --pedantic -lyacx -lnvrtc -lcuda -L $(CUDA_PATH)/lib64 -Wl,-rpath,$(CUDA_PATH)/lib64 file.cpp +g++ -lyacx -lnvrtc -lcuda -L $(CUDA_PATH)/lib64 -Wl,-rpath,$(CUDA_PATH)/lib64 file.cpp ``` some syntatic sugar is given using templates, which requires you to include the headers when building: @@ -106,13 +111,7 @@ some syntatic sugar is given using templates, which requires you to include the g++ -Wall -Wextra --pedantic -lyacx -lnvrtc -lcuda -L $(CUDA_PATH)/lib64 -Wl,-rpath,$(CUDA_PATH)/lib64 -I include/yacx file.cpp ``` -## Examples - -yacx comes with many examples using a multitude of different kernels with hostcode in c++,java and scala - -### C++ - -#### Run Examples +### Run Examples ```console # list examples @@ -123,22 +122,80 @@ examples/example_saxpy.cpp examples/example_program.cpp examples/example_gauss.cpp # compile example -$ make example_program +$ cmake -H. -Bbuild +$ make -C build example_program # run example -$ make run +$ ./build/examples/bin/example_program 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8 ``` -## Tests +### Tests Require the [Catch2](https://github.com/catchorg/Catch2) test-framework ```console -$ make check +$ cmake -H. -Bbuild +$ make -C build tests +$ pushd build/test/bin/ +$ ./tests +$ popd ``` For more info read the [contribution guideline](https://github.com/ZerataX/yacx/blob/master/CONTRIBUTING.md#test) +## Java + +### Run Examples + +```console +# for autocompletion +$ source yacx-completion.bash +# compile example +$ ./yacx build-java +# list examples +$ ./yacx execute-java +!! parameter needed, select one of the following +ExampleSimpleGEMMBenchmark +ExampleFastGEMM +ExampleSimpleGEMM +... +$ ./yacx.sh execute-java ExampleFastGEMM +``` + +### Tests + +```console +# build JNI and Test Classes +$ cmake -H. -Bbuild +$ make -C build JNITestClasses +# link kernels to execution folder +$ mkdir build/java/bin/examples +$ ln -s $(realpath examples/kernels/) build/java/bin/examples/kernels +# execute tests +$ pushd build/java/bin +$ java -Djava.library.path=../../ -jar src/junit-platform-console-standalone-1.5.2.jar --class-path . --scan-class-path +$ popd +``` + +## Scala + +### Run Examples + +```console +# for autocompletion +$ source yacx-completion.bash +# compile example +$ ./yacx build-scala +# list examples +$ ./yacx execute-scala +!! parameter needed, select one of the following +ExampleFilterBenchmark +ExampleFilter +ExampleFastGEMM +... +$ ./yacx.sh execute-scala ExampleFastGEMM +``` + ## Contributing Make sure you agree to the [code of conduct](./CODE_OF_CONDUCT.md) and read the [contribution guideline](https://github.com/ZerataX/yacx/blob/master/CONTRIBUTING.md) diff --git a/examples/makefile b/examples/makefile deleted file mode 100644 index 52b6d63..0000000 --- a/examples/makefile +++ /dev/null @@ -1,25 +0,0 @@ -CC := g++ # This is the main compiler -# CC := clang --analyze # and comment out the linker last line for sanity - -SRCDIR := . -INCDIR := ../include -BUILDDIR := ../build -TARGET := ../bin/runner - -SRCEXT := cpp -HEADDEREXT := hpp -SOURCES := $(shell find $(SRCDIR) -maxdepth 1 -type f -not -path '*tests*' -name '*.$(SRCEXT)') -HEADERS := $(shell find $(LIBDIR) -type f -name *.$(HEADDEREXT)) -OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) -CFLAGS := -std=c++17 -Wall -g -DNVRTC_GET_TYPE_NAME=1 -LIB := -lnvrtc -lcuda -L $(CUDA_PATH)/lib64 -Wl,-rpath,$(CUDA_PATH)/lib64 -INC := -I $(INCDIR) -I $(CUDA_PATH)/include - -# Build -all: $(OBJECTS) - -$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) - @echo "SOURCES: $(SOURCES)" - @echo " $(CC) $(CFLAGS) $(INC) -c -o $@ $<"; $(CC) $(CFLAGS) $(INC) -c -o $@ $< - -.PHONY: all \ No newline at end of file diff --git a/makefile b/makefile index 9175332..8e7018a 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,4 @@ -CC := g++ # This is the main compiler -# CC := clang --analyze # and comment out the linker last line for sanity +ANALYZER := clang --analyze LINTER := cpplint FORMATER := clang-format MKDIR_P = mkdir -p @@ -10,9 +9,7 @@ VENDOR := exclude TESTDIR := test BUILDDIR := build EXAMPLEDIR := examples -TARGET := bin/runner -TESTTARGET := bin/tester -DIRS := bin build +DIRS := ${BUILDDIR} SRCEXT := cpp HEADDEREXT := hpp @@ -20,65 +17,26 @@ SOURCES := $(shell find $(SRCDIR) -maxdepth 1 -type f -name '*.$(SRCEXT)') TESTS := $(shell find $(TESTDIR) -type f -name '*.$(SRCEXT)') EXAMPLES := $(shell find $(EXAMPLEDIR) -maxdepth 1 -type f -name '*.$(SRCEXT)') HEADERS := $(shell find $(LIBDIR) -type f -name '*.$(HEADDEREXT)') -OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) -TEST_OBJ = $(OBJECTS) $(patsubst $(TESTDIR)/%,$(BUILDDIR)/%,$(TESTS:.$(SRCEXT)=.o)) -CFLAGS := -std=c++17 -Wall -g -DNVRTC_GET_TYPE_NAME=1 -LIB := -lnvrtc -lcuda -L $(CUDA_PATH)/lib64 -Wl,-rpath,$(CUDA_PATH)/lib64 -INC := -I $(INCDIR) -I $(CUDA_PATH)/include - -# Build -example_program: example - @echo " $(CC) build/example_program.o $(OBJECTS) -o $(TARGET) $(LIB)"; $(CC) build/example_program.o $(OBJECTS) -o $(TARGET) $(LIB) -example_template: example - echo " $(CC) build/example_template.o $(OBJECTS) -o $(TARGET) $(LIB)"; $(CC) build/example_template.o $(OBJECTS) -o $(TARGET) $(LIB) -example_saxpy: example - @echo " $(CC) build/example_saxpy.o $(OBJECTS) -o $(TARGET) $(LIB)"; $(CC) build/example_saxpy.o $(OBJECTS) -o $(TARGET) $(LIB) -example_matrix_multiply: example - @echo " $(CC) build/example_matrix_multiply.o $(OBJECTS) -o $(TARGET) $(LIB)"; $(CC) build/example_matrix_multiply.o $(OBJECTS) -o $(TARGET) $(LIB) -example_gauss: example - @echo " $(CC) build/example_gauss.o $(OBJECTS) -o $(TARGET) $(LIB)"; $(CC) build/example_gauss.o $(OBJECTS) -o $(TARGET) $(LIB) -example_logger: example - @echo " $(CC) build/example_logger.o $(OBJECTS) -o $(TARGET) $(LIB)"; $(CC) build/example_logger.o $(OBJECTS) -o $(TARGET) $(LIB) -example: directories $(OBJECTS) - +$(MAKE) -C examples directories: ${DIRS} ${DIRS}: ${MKDIR_P} ${DIRS} -$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) - @echo " $(CC) $(CFLAGS) $(INC) -c -o $@ $<"; $(CC) $(CFLAGS) $(INC) -c -o $@ $< - clean: @echo " Cleaning..."; - @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET) - + @echo " $(RM) -r $(DIRS) docs/{java,html,latex}"; $(RM) -r $(DIRS) docs/{java,html,latex} -# Execute -run: - @$(TARGET) - -# Format format: $(FORMATER) -i -style=file $(SOURCES) $(HEADERS) $(TESTS) $(EXAMPLES) -# Linter lint: $(LINTER) --root=${CURDIR} --recursive . #clang-tidy src/ -system-headers=false -# Tests -init_submodules: - -git submodule update --init --recursive - -${TESTTARGET}: init_submodules directories $(OBJECTS) - +$(MAKE) -C test - @echo " Linking... $(TEST_OBJ)"; - @echo " $(CC) $(TEST_OBJ) -o $(TESTTARGET) $(LIB)"; $(CC) $(TEST_OBJ) -o $(TESTTARGET) $(LIB) - -check: $(TESTTARGET) - @$(TESTTARGET) -d yes +docs: + doxygen Doxyfile + javadoc -d docs/java -sourcepath src/main/java yacx -.PHONY: clean, lint, directories, format, init_submodules, check, run +.PHONY: clean, lint, directories, format, docs diff --git a/test/makefile b/test/makefile deleted file mode 100644 index b22b3df..0000000 --- a/test/makefile +++ /dev/null @@ -1,25 +0,0 @@ -CC := g++ # This is the main compiler -# CC := clang --analyze # and comment out the linker last line for sanity - -SRCDIR := . -INCDIR := ../include -VENDOR := ../extern -BUILDDIR := ../build -TARGET := ../bin/tester - -SRCEXT := cpp -HEADDEREXT := hpp -SOURCES := $(shell find $(SRCDIR) -type f -name '*.$(SRCEXT)') -HEADERS := $(shell find $(LIBDIR) -type f -name '*.$(HEADDEREXT)') -OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) -CFLAGS := -std=c++17 -Wall -g -DNVRTC_GET_TYPE_NAME=1 -LIB := -lnvrtc -lcuda -L $(CUDA_PATH)/lib64 -Wl,-rpath,$(CUDA_PATH)/lib64 -INC := -I $(INCDIR) -I $(CUDA_PATH)/include -I $(VENDOR)/catch2/single_include - -# Build -all: $(OBJECTS) - -$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) - @echo " $(CC) $(CFLAGS) $(INC) -c -o $@ $<"; $(CC) $(CFLAGS) $(INC) -c -o $@ $< - -.PHONY: all \ No newline at end of file From f9f5f359faa98336c0de392a94f15224594ef07f Mon Sep 17 00:00:00 2001 From: Jona Abdinghoff Date: Thu, 9 Apr 2020 18:04:02 +0200 Subject: [PATCH 2/3] doxygen ignore java files --- Doxyfile | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/Doxyfile b/Doxyfile index 6bd5a24..4a13188 100644 --- a/Doxyfile +++ b/Doxyfile @@ -122,49 +122,19 @@ FILE_PATTERNS = *.c \ *.cxx \ *.cpp \ *.c++ \ - *.java \ - *.ii \ - *.ixx \ - *.ipp \ - *.i++ \ - *.inl \ - *.idl \ - *.ddl \ - *.odl \ *.h \ *.hh \ *.hxx \ *.hpp \ *.h++ \ - *.cs \ - *.d \ - *.php \ - *.php4 \ - *.php5 \ - *.phtml \ - *.inc \ *.m \ *.markdown \ *.md \ *.mm \ - *.dox \ - *.py \ - *.pyw \ - *.f90 \ - *.f95 \ - *.f03 \ - *.f08 \ - *.f \ - *.for \ - *.tcl \ - *.vhd \ - *.vhdl \ - *.ucf \ - *.qsf \ - *.ice + *.dox RECURSIVE = YES EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = +EXCLUDE_PATTERNS = */jni/* EXCLUDE_SYMBOLS = EXAMPLE_PATH = "examples" EXAMPLE_PATTERNS = * From e95117d4ca1d265af9dca553f9aaf38f29f61f85 Mon Sep 17 00:00:00 2001 From: ZerataX Date: Tue, 28 Apr 2020 01:08:35 +0000 Subject: [PATCH 3/3] add index page --- .github/workflows/docs.yml | 2 +- Doxyfile | 2 +- shell.nix | 47 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 shell.nix diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 490cfdd..d141e5e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -21,4 +21,4 @@ jobs: ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} BASE_BRANCH: master # The branch the action should deploy from. BRANCH: gh-pages # The branch the action should deploy to. - FOLDER: docs/html # The folder the action should deploy. + FOLDER: docs/ # The folder the action should deploy. diff --git a/Doxyfile b/Doxyfile index 4a13188..38b312e 100644 --- a/Doxyfile +++ b/Doxyfile @@ -8,7 +8,7 @@ PROJECT_NAME = yacx - Yet Another CudaExecutor PROJECT_NUMBER = 0.6.1 PROJECT_BRIEF = "wrapper to easily compile and execute cuda kernels" PROJECT_LOGO = -OUTPUT_DIRECTORY = "docs" +OUTPUT_DIRECTORY = "docs/cpp" CREATE_SUBDIRS = NO ALLOW_UNICODE_NAMES = NO OUTPUT_LANGUAGE = English diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..922df80 --- /dev/null +++ b/shell.nix @@ -0,0 +1,47 @@ +{ pkgs ? import {} }: + +let fhs = pkgs.buildFHSUserEnv { + name = "cuda-env"; + targetPkgs = pkgs: with pkgs; + [ git + gitRepo + gnupg + autoconf + curl + cmake + doxygen + procps + gnumake + gcc7 + utillinux + m4 + gperf + unzip + cudatoolkit_10 + linuxPackages.nvidia_x11 + libGLU + libGL + xorg.libXi xorg.libXmu freeglut + xorg.libXext xorg.libX11 xorg.libXv xorg.libXrandr zlib + ncurses5 + stdenv.cc + binutils + jdk12 + ]; + multiPkgs = pkgs: with pkgs; [ zlib ]; + runScript = "bash"; + profile = '' + export CUDA_PATH=${pkgs.cudatoolkit_10} + export JAVA_HOME=${pkgs.jdk12.home} + export PATH=$CUDA_PATH/bin:$PATH + # export LD_LIBRARY_PATH=${pkgs.linuxPackages.nvidia_x11}/lib + export EXTRA_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib" + export EXTRA_CCFLAGS="-I/usr/include" + ''; + }; +in pkgs.stdenv.mkDerivation { + name = "cuda-env-shell"; + nativeBuildInputs = [ fhs ]; + shellHook = "exec cuda-env"; +} +