├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── avoid_file.txt ├── cmake └── GVirtuS.cmake ├── contributors.txt ├── etc └── properties.json ├── gvirtus-test.sh ├── include └── gvirtus │ ├── backend │ ├── Backend.h │ ├── Handler.h │ ├── Process.h │ └── Property.h │ ├── common │ ├── Decoder.h │ ├── Encoder.h │ ├── JSON.h │ ├── LD_Lib.h │ ├── MessageDispatcher.h │ ├── Mutex.h │ ├── Observable.h │ ├── Observer.h │ ├── SignalException.h │ ├── SignalState.h │ ├── Util.h │ └── gvirtus-type.h │ ├── communicators │ ├── AfUnixCommunicator.h │ ├── Buffer.h │ ├── Communicator.h │ ├── CommunicatorFactory.h │ ├── Endpoint.h │ ├── EndpointFactory.h │ ├── Endpoint_Rdma.h │ ├── Endpoint_Tcp.h │ ├── Result.h │ ├── ShmCommunicator.h │ ├── VMShmCommunicator.h │ ├── VMSocketCommunicator.h │ ├── VirtioCommunicator.h │ ├── VmciCommunicator.h │ └── ZmqCommunicator.h │ └── frontend │ └── Frontend.h ├── plugins ├── cublas │ ├── CMakeLists.txt │ ├── backend │ │ ├── CublasHandler.cpp │ │ ├── CublasHandler.h │ │ ├── CublasHandler_Helper.cpp │ │ ├── CublasHandler_Level1.cpp │ │ ├── CublasHandler_Level2.cpp │ │ └── CublasHandler_Level3.cpp │ └── frontend │ │ ├── CublasFrontend.cpp │ │ ├── CublasFrontend.h │ │ ├── Cublas_helper.cpp │ │ ├── Cublas_level1.cpp │ │ ├── Cublas_level2.cpp │ │ └── Cublas_level3.cpp ├── cudadr │ ├── CMakeLists.txt │ ├── __cudaFatFormat.h │ ├── backend │ │ ├── CudaDrHandler.cpp │ │ ├── CudaDrHandler.h │ │ ├── CudaDrHandler_context.cpp │ │ ├── CudaDrHandler_device.cpp │ │ ├── CudaDrHandler_event.cpp │ │ ├── CudaDrHandler_execution.cpp │ │ ├── CudaDrHandler_initialization.cpp │ │ ├── CudaDrHandler_memory.cpp │ │ ├── CudaDrHandler_module.cpp │ │ ├── CudaDrHandler_stream.cpp │ │ ├── CudaDrHandler_texture.cpp │ │ └── CudaDrHandler_version.cpp │ ├── frontend │ │ ├── CudaDr.cpp │ │ ├── CudaDr.h │ │ ├── CudaDrFrontend.cpp │ │ ├── CudaDrFrontend.h │ │ ├── CudaDr_context.cpp │ │ ├── CudaDr_device.cpp │ │ ├── CudaDr_event.cpp │ │ ├── CudaDr_execution.cpp │ │ ├── CudaDr_initialization.cpp │ │ ├── CudaDr_memory.cpp │ │ ├── CudaDr_module.cpp │ │ ├── CudaDr_stream.cpp │ │ ├── CudaDr_texture.cpp │ │ └── CudaDr_version.cpp │ └── util │ │ ├── CudaUtil.cpp │ │ └── CudaUtil.h ├── cudart │ ├── 3rdparty │ │ └── include │ │ │ ├── CudaRt_internal.h │ │ │ └── __cudaFatFormat.h │ ├── CMakeLists.txt │ ├── backend │ │ ├── CudaRtHandler.cpp │ │ ├── CudaRtHandler.h │ │ ├── CudaRtHandler_device.cpp │ │ ├── CudaRtHandler_error.cpp │ │ ├── CudaRtHandler_event.cpp │ │ ├── CudaRtHandler_execution.cpp │ │ ├── CudaRtHandler_internal.cpp │ │ ├── CudaRtHandler_memory.cpp │ │ ├── CudaRtHandler_occupancy.cpp │ │ ├── CudaRtHandler_opengl.cpp │ │ ├── CudaRtHandler_stream.cpp │ │ ├── CudaRtHandler_surface.cpp │ │ ├── CudaRtHandler_texture.cpp │ │ ├── CudaRtHandler_thread.cpp │ │ ├── CudaRtHandler_version.cpp │ │ ├── cuda_runtime_compat.h │ │ └── main.cpp │ ├── demo │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── add_grid.cu │ │ ├── dummy0.cu │ │ ├── launchKernel.cu │ │ └── matrixMul.cu │ ├── frontend │ │ ├── CudaRt.cpp │ │ ├── CudaRt.h │ │ ├── CudaRtFrontend.cpp │ │ ├── CudaRtFrontend.h │ │ ├── CudaRt_device.cpp │ │ ├── CudaRt_error.cpp │ │ ├── CudaRt_event.cpp │ │ ├── CudaRt_execution.cpp │ │ ├── CudaRt_internal.cpp │ │ ├── CudaRt_memory.cpp │ │ ├── CudaRt_occupancy.cpp │ │ ├── CudaRt_opengl.cpp │ │ ├── CudaRt_stream.cpp │ │ ├── CudaRt_surface.cpp │ │ ├── CudaRt_texture.cpp │ │ ├── CudaRt_thread.cpp │ │ └── CudaRt_version.cpp │ └── util │ │ ├── CudaUtil.cpp │ │ └── CudaUtil.h ├── cudnn │ ├── CMakeLists.txt │ ├── backend │ │ ├── CudnnHandler.cpp │ │ └── CudnnHandler.h │ └── frontend │ │ ├── Cudnn.cpp │ │ ├── CudnnFrontend.cpp │ │ ├── CudnnFrontend.h │ │ └── Cudnn_helper.cpp ├── cufft │ ├── CMakeLists.txt │ ├── backend │ │ ├── CufftHandler.cpp │ │ └── CufftHandler.h │ └── frontend │ │ ├── Cufft.cpp │ │ ├── Cufft.h │ │ ├── CufftFrontend.cpp │ │ └── CufftFrontend.h ├── curand │ ├── CMakeLists.txt │ ├── backend │ │ ├── CurandHandler.cpp │ │ ├── CurandHandler.h │ │ └── CurandHandler_host.cpp │ └── frontend │ │ ├── Curand.cpp │ │ ├── CurandFrontend.cpp │ │ └── CurandFrontend.h ├── cusolver │ ├── CMakeLists.txt │ ├── backend │ │ ├── CusolverHandler.cpp │ │ └── CusolverHandler.h │ └── frontend │ │ ├── Cusolver.cpp │ │ ├── CusolverFrontend.cpp │ │ ├── CusolverFrontend.h │ │ └── Cusolver_helper.cpp └── cusparse │ ├── CMakeLists.txt │ ├── backend │ ├── CusparseHandler.cpp │ └── CusparseHandler.h │ └── frontend │ ├── Cusparse.cpp │ ├── CusparseFrontend.cpp │ ├── CusparseFrontend.h │ └── Cusparse_helper.cpp ├── src ├── backend │ ├── Backend.cpp │ ├── Process.cpp │ ├── Property.cpp │ └── main.cpp ├── common │ ├── Decoder.cpp │ ├── Encoder.cpp │ ├── JSON.cpp │ ├── LD_Lib.cpp │ ├── MessageDispatcher.cpp │ ├── Mutex.cpp │ ├── Observable.cpp │ ├── Observer.cpp │ ├── SignalException.cpp │ ├── SignalState.cpp │ └── Util.cpp ├── communicators │ ├── AfUnixCommunicator.cpp │ ├── Buffer.cpp │ ├── CommunicatorFactory.cpp │ ├── EndpointFactory.cpp │ ├── Endpoint_Rdma.cpp │ ├── Endpoint_Tcp.cpp │ ├── Result.cpp │ ├── ShmCommunicator.cpp │ ├── VMShmCommunicator.cpp │ ├── VMSocketCommunicator.cpp │ ├── VirtioCommunicator.cpp │ ├── VmciCommunicator.cpp │ ├── ZmqCommunicator.cpp │ ├── rdma │ │ ├── RdmaCommunicator.cpp │ │ ├── RdmaCommunicator.h │ │ ├── ktmrdma.cpp │ │ └── ktmrdma.h │ └── tcp │ │ ├── TcpCommunicator.cpp │ │ └── TcpCommunicator.h └── frontend │ └── Frontend.cpp └── tools ├── CMakeLists.txt └── protocol-generator ├── CMakeLists.txt └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | *.la 4 | *.so 5 | *.lo 6 | *.Plo 7 | *.Tpo 8 | *.Po 9 | *.cache 10 | .deps/ 11 | .libs 12 | config.h.in* 13 | 14 | # Clion 15 | cmake-build-debug/ 16 | .idea/ 17 | 18 | # VSCode 19 | .vscode/ 20 | .clang-format 21 | 22 | # CMake 23 | cmake_install.cmake 24 | CMakeCache.txt 25 | install_manifest.txt 26 | CMakeFiles/ 27 | Makefile 28 | *.cbp 29 | .graphviz/ 30 | .puml/ 31 | *.pdf 32 | *.png 33 | *.puml 34 | 35 | # Diagrams not exported 36 | *.dia* 37 | *.xcf 38 | 39 | # Build 40 | build/ 41 | 42 | # Binary or source test 43 | test 44 | bin/ 45 | client.cpp 46 | server.cpp 47 | 48 | # External library 49 | external/ 50 | libuv-prefix/ 51 | uvw-prefix/ 52 | nlohmann-prefix/ 53 | 54 | # Temporainly 55 | doc/ 56 | diagrams/ 57 | unit_test/include 58 | unit_test/lib64 59 | gtest 60 | 61 | gvirtus/backend/gvirtus-backend 62 | 63 | gvirtus/uWebSockets-prefix/ 64 | -------------------------------------------------------------------------------- /avoid_file.txt: -------------------------------------------------------------------------------- 1 | # Unknown reason 2 | 0_Simple/simpleIPC 3 | 3_Imaging/convolutionFFT2D 4 | 4_Finance/MonteCarloMultiGPU 5 | 7_CUDALibraries/simpleCUFFT_2d_MGPU 6 | 7_CUDALibraries/simpleCUFFT_MGPU 7 | 8 | # Using libnvrtc (not supported) 9 | 0_Simple/clock_nvrtc 10 | 0_Simple/inlinePTX_nvrtc 11 | 0_Simple/matrixMul_nvrtc 12 | 0_Simple/simpleAssert_nvrtc 13 | 0_Simple/simpleAtomicIntrinsics_nvrtc 14 | 0_Simple/simpleTemplates_nvrtc 15 | 0_Simple/simpleVoteIntrinsics_nvrtc 16 | 0_Simple/vectorAdd_nvrtc 17 | 4_Finance/binomialOptions_nvrtc 18 | 4_Finance/BlackScholes_nvrtc 19 | 4_Finance/quasirandomGenerator_nvrtc 20 | 21 | # Display interaction (can't be supported) 22 | 2_Graphics/bindlessTexture 23 | 2_Graphics/Mandelbrot 24 | 2_Graphics/marchingCubes 25 | 2_Graphics/simpleGL 26 | 2_Graphics/simpleTexture3D 27 | 2_Graphics/volumeFiltering 28 | 2_Graphics/volumeRender 29 | 3_Imaging/bicubicTexture 30 | 3_Imaging/bilateralFilter 31 | 3_Imaging/boxFilter 32 | 3_Imaging/cudaDecodeGL 33 | 3_Imaging/imageDenoising 34 | 3_Imaging/postProcessGL 35 | 3_Imaging/recursiveGaussian 36 | 3_Imaging/simpleCUDA2GL 37 | 3_Imaging/SobelFilter 38 | 5_Simulations/fluidsGL 39 | 5_Simulations/nbody 40 | 5_Simulations/oceanFFT 41 | 5_Simulations/particles 42 | 5_Simulations/smokeParticles 43 | 6_Advanced/FunctionPointers 44 | -------------------------------------------------------------------------------- /cmake/GVirtuS.cmake: -------------------------------------------------------------------------------- 1 | include_directories(include) 2 | 3 | if(NOT ${PROJECT_NAME} STREQUAL "gvirtus-common") 4 | include_directories(${GVIRTUS_HOME}/include) 5 | link_directories(${GVIRTUS_HOME}/lib) 6 | endif() 7 | 8 | set(CMAKE_CXX_STANDARD 17) 9 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 10 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGVIRTUS_HOME=\\\"${GVIRTUS_HOME}\\\"") 11 | set(CMAKE_SKIP_RPATH ON) 12 | 13 | # Include the support to external projects 14 | include(ExternalProject) 15 | 16 | # Set the external install location 17 | set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/external) 18 | 19 | ExternalProject_Add(log4cplus 20 | URL https://kumisystems.dl.sourceforge.net/project/log4cplus/log4cplus-stable/2.0.5/log4cplus-2.0.5.tar.gz 21 | TIMEOUT 360 22 | BUILD_IN_SOURCE 1 23 | CONFIGURE_COMMAND ./configure --prefix=${EXTERNAL_INSTALL_LOCATION} CFLAGS=-fPIC CPPFLAGS=-I${EXTERNAL_INSTALL_LOCATION}/include/ LDFLAGS=-L${EXTERNAL_INSTALL_LOCATION}/lib/ 24 | BUILD_COMMAND make 25 | INSTALL_COMMAND make install 26 | ) 27 | set(LIBLOG4CPLUS ${EXTERNAL_INSTALL_LOCATION}/lib/liblog4cplus.so) 28 | if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") 29 | set(LIBLOG4CPLUS ${EXTERNAL_INSTALL_LOCATION}/lib/liblog4cplus.dylib) 30 | endif() 31 | include_directories(${EXTERNAL_INSTALL_LOCATION}/include) 32 | 33 | find_package(Threads REQUIRED) 34 | 35 | if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/gvirtus) 36 | message(STATUS "Installing ${CMAKE_CURRENT_SOURCE_DIR}/include/gvirtus to ${GVIRTUS_HOME}/include") 37 | install(DIRECTORY include/gvirtus DESTINATION ${GVIRTUS_HOME}/include) 38 | endif() 39 | 40 | macro(gvirtus_install_target target_name) 41 | install(TARGETS ${target_name} 42 | LIBRARY DESTINATION ${GVIRTUS_HOME}/lib 43 | ARCHIVE DESTINATION ${GVIRTUS_HOME}/lib 44 | RUNTIME DESTINATION ${GVIRTUS_HOME}/bin 45 | INCLUDES DESTINATION ${GVIRTUS_HOME}/include) 46 | endmacro() 47 | 48 | function(gvirtus_add_backend) 49 | if(ARGC LESS 3) 50 | message(FATAL_ERROR "Usage: gvirtus_add_backend(wrapped_library version source1 ...)") 51 | endif() 52 | list(GET ARGV 0 wrapped_library) 53 | list(REMOVE_AT ARGV 0) 54 | list(GET ARGV 0 version) 55 | list(REMOVE_AT ARGV 0) 56 | if(NOT "${PROJECT_NAME}" STREQUAL "gvirtus-plugin-${wrapped_library}") 57 | message(FATAL_ERROR "This project should be named gvirtus-plugin-${wrapped_library}") 58 | endif() 59 | add_library(${PROJECT_NAME} SHARED 60 | ${ARGV}) 61 | target_link_libraries(${PROJECT_NAME} ${LIBLOG4CPLUS} gvirtus-common gvirtus-communicators) 62 | install(TARGETS ${PROJECT_NAME} 63 | LIBRARY DESTINATION ${GVIRTUS_HOME}/lib) 64 | endfunction() 65 | 66 | function(gvirtus_add_frontend) 67 | if(ARGC LESS 3) 68 | message(FATAL_ERROR "Usage: gvirtus_add_frontend(wrapped_library version source1 ...)") 69 | endif() 70 | list(GET ARGV 0 wrapped_library) 71 | list(REMOVE_AT ARGV 0) 72 | list(GET ARGV 0 version) 73 | list(REMOVE_AT ARGV 0) 74 | add_library(${wrapped_library} SHARED 75 | ${ARGV}) 76 | target_link_libraries(${wrapped_library} ${LIBLOG4CPLUS} gvirtus-common gvirtus-communicators gvirtus-frontend) 77 | set_target_properties(${wrapped_library} PROPERTIES VERSION ${version}) 78 | string(REGEX REPLACE "\\..*" "" soversion ${version}) 79 | set_target_properties(${wrapped_library} PROPERTIES SOVERSION ${soversion}) 80 | string(TOUPPER "LIB${wrapped_library}_${version}" script) 81 | set(script "${script} {\n local:\n*;\n};") 82 | file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/lib${wrapped_library}.map "${script}") 83 | install(TARGETS ${wrapped_library} 84 | LIBRARY DESTINATION ${GVIRTUS_HOME}/lib/frontend) 85 | endfunction() 86 | -------------------------------------------------------------------------------- /contributors.txt: -------------------------------------------------------------------------------- 1 | Giuseppe Coviello 2 | Roberto Di Lauro 3 | Carmine Ferraro 4 | Flora Giannone 5 | Sokol Kosta 6 | Antonio Mentone 7 | Raffaele Montella 8 | Carlo Palmieri 9 | Valentina Pelliccia 10 | Vincenzo Santopietro 11 | Antonio Pilato 12 | Juan Pablo Ruiz 13 | Mariano Aponte 14 | -------------------------------------------------------------------------------- /etc/properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "communicator": [ 3 | { 4 | "endpoint": { 5 | "suite": "tcp/ip", 6 | "protocol": "tcp", 7 | "server_address": "127.0.0.1", 8 | "port": "9999" 9 | }, 10 | "plugins": [ 11 | "cudart", 12 | "cublas", 13 | "curand", 14 | "cudnn" 15 | ] 16 | } 17 | ], 18 | "secure_application": false 19 | } 20 | -------------------------------------------------------------------------------- /gvirtus-test.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | if [ "$#" -lt 2 ]; then 4 | echo "Usage $0 NVIDIA_SAMPLES_PATH output_file [avoid_file]" 5 | exit -1 6 | fi 7 | 8 | base_dir=$1 9 | output_file=$2 10 | avoid_file="" 11 | if [ "$#" -eq 3 ]; then 12 | avoid_file=$3 13 | if [ ! -f $avoid_file ]; then 14 | echo "Avoid file doesn't exist" 15 | exit -1 16 | fi 17 | _avoid_file="/tmp/avoid-$RANDOM-.txt" 18 | cat $avoid_file | sed '/^#/ d' >$_avoid_file 19 | fi 20 | 21 | _output_file="/tmp/output-$RANDOM-.txt" 22 | echo >$_output_file "TYPE;SAMPLE;RESULT;TIME;ERROR" 23 | 24 | cd $base_dir 25 | sample_type_paths=`ls -d ${base_dir}/?_*` 26 | for sample_type_path in $sample_type_paths 27 | do 28 | sample_paths=`ls -d ${sample_type_path}/*` 29 | sample_type=`basename $sample_type_path` 30 | echo "In $sample_type_path ..." 31 | for sample_path in $sample_paths 32 | do 33 | sample_exec=`basename $sample_path` 34 | cd $sample_path 35 | if [ -f "$sample_exec" ]; then 36 | avoid="" 37 | if [ -n "$avoid_file" ]; then 38 | avoid=`grep -w $sample_type/$sample_exec $_avoid_file` 39 | fi 40 | if [ -z "$avoid" ]; then 41 | _stderr_file="/tmp/stderr-$RANDOM-.txt" 42 | echo "Testing: $sample_type/$sample_exec" 43 | err="" 44 | result="FAIL" 45 | dT=-1 46 | t0=`echo $(($(date +%s%N)/1000000))` 47 | ./$sample_exec >/dev/null 2>$_stderr_file 48 | if [ $? -ne 0 ]; then 49 | err_lines=`cat $_stderr_file | wc | awk '{ print $1 }'` 50 | skip_err_lines=`grep "no version information available" $_stderr_file | wc | awk '{ print $1 }'` 51 | if [ "$err_lines" -gt "$skip_err_lines" ]; then 52 | err=`tr '\n' ';' <$_stderr_file` 53 | echo "FAIL:" 54 | cat $_stderr_file 55 | fi 56 | else 57 | result="OK" 58 | t1=`echo $(($(date +%s%N)/1000000))` 59 | dT=$((t1-t0)) 60 | fi 61 | rm $_stderr_file 2>/dev/null 62 | echo "----------------------------" 63 | echo >>$_output_file "$sample_type;$sample_exec;$result;$dT;$err" 64 | fi 65 | fi 66 | done 67 | done 68 | cp $_output_file $output_file 69 | rm $_output_file 2>/dev/null 70 | rm $_avoid_file 2>/dev/null 71 | -------------------------------------------------------------------------------- /include/gvirtus/backend/Backend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "Process.h" 10 | #include "Property.h" 11 | #include "log4cplus/configurator.h" 12 | #include "log4cplus/logger.h" 13 | #include "log4cplus/loggingmacros.h" 14 | 15 | #define DEBUG 16 | 17 | namespace gvirtus::backend { 18 | 19 | static int activeChilds = 0; 20 | 21 | static void sigint_handler(int sig) {} 22 | 23 | /** 24 | * Backend is the main object of gvirtus-backend. It is responsible of accepting 25 | * the connection from the Frontend(s) and spawing a new Process for handling 26 | * each Frontend. 27 | */ 28 | class Backend : public common::Observer { 29 | public: 30 | Backend(const fs::path &path); 31 | 32 | /** 33 | * Starts the Backend. The call to Start() will make the Backend to serve 34 | * forever. 35 | */ 36 | void Start(); 37 | 38 | void EventOccurred(std::string &event, void *object); 39 | 40 | virtual ~Backend() = default; 41 | 42 | private: 43 | std::vector> _children; 44 | Property _properties; 45 | log4cplus::Logger logger; 46 | }; 47 | } // namespace gvirtus::backend -------------------------------------------------------------------------------- /include/gvirtus/backend/Handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file Handler.h 28 | * @author Giuseppe Coviello 29 | * @date Wed Jan 12 10:01:58 2011 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include "log4cplus/configurator.h" 41 | #include "log4cplus/logger.h" 42 | #include "log4cplus/loggingmacros.h" 43 | 44 | namespace gvirtus::backend { 45 | class Handler { 46 | protected: 47 | using create_t = std::shared_ptr(); 48 | 49 | public: 50 | virtual bool CanExecute(std::string routine) = 0; 51 | virtual std::shared_ptr Execute( 52 | std::string routine, 53 | std::shared_ptr input_buffer) = 0; 54 | 55 | private: 56 | log4cplus::Logger logger; 57 | }; 58 | } // namespace gvirtus::backend 59 | -------------------------------------------------------------------------------- /include/gvirtus/backend/Process.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "Handler.h" 11 | #include "log4cplus/configurator.h" 12 | #include "log4cplus/logger.h" 13 | #include "log4cplus/loggingmacros.h" 14 | 15 | namespace gvirtus::backend { 16 | /** 17 | * Process is the object used by the Backend to handle the request from a single 18 | * Frontend. 19 | */ 20 | class Process : public common::Observable { 21 | public: 22 | Process( 23 | std::shared_ptr>> 25 | communicator, 26 | std::vector &plugins); 27 | ~Process() override; 28 | void Start(); 29 | 30 | private: 31 | std::shared_ptr>> _communicator; 32 | std::vector>> _handlers; 33 | 34 | std::vector mPlugins; 35 | log4cplus::Logger logger; 36 | }; 37 | } // namespace gvirtus::backend 38 | -------------------------------------------------------------------------------- /include/gvirtus/backend/Property.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace gvirtus::backend { 10 | /** 11 | * Property class. 12 | * This class is a model to represent the properties of the backend. 13 | */ 14 | class Property { 15 | public: 16 | /** 17 | * Default constructor 18 | */ 19 | Property() = default; 20 | 21 | /** 22 | * This method is a setter for the class member _endpoints 23 | * @param endpoints: pointer to a vector of Endpoint 24 | * @return reference to itself (Fluent Interface API) 25 | */ 26 | Property &endpoints(const int endpoints); 27 | 28 | /** 29 | * This method is a getter for the class member _endpoints 30 | * @return the reference to vector where Endpoint are saved 31 | */ 32 | inline const int &endpoints() const { return _endpoints; } 33 | 34 | /** 35 | * This method is a setter for the class member _plugins 36 | * @param plugins: pointer to a vector of std::string 37 | * @return reference to itself (Fluent Interface API) 38 | */ 39 | Property &plugins(const std::vector &plugins); 40 | 41 | /** 42 | * This method is a getter for the class member _plugins 43 | * @return the reference to vector where plugins string are saved 44 | */ 45 | inline std::vector> &plugins() { return _plugins; } 46 | 47 | Property &secure(bool secure); 48 | 49 | inline bool &secure() { return _secure; } 50 | 51 | private: 52 | std::vector> _plugins; 53 | int _endpoints; 54 | bool _secure; 55 | }; 56 | 57 | /** 58 | * This function will be used by nlohmann::json object when we call 59 | * j.get<Property<(). Without this function the program doesn't know how 60 | * to build a property object from json object. 61 | * @param j: reference to json object which contains the data 62 | * @param p: reference to property object to be created 63 | */ 64 | inline void from_json(const nlohmann::json &j, Property &p) { 65 | int ends = 0; 66 | for (auto &el : j["communicator"]) { 67 | ends++; 68 | p.plugins(el["plugins"].get>()); 69 | } 70 | 71 | p.endpoints(ends); 72 | p.secure(j["secure_application"].get()); 73 | } 74 | } // namespace gvirtus::backend 75 | -------------------------------------------------------------------------------- /include/gvirtus/common/Decoder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Decoder.h 3 | * @author Raffaele Montella 4 | * @date Wed Nov 30 17:16:48 2016 5 | * 6 | * @brief 7 | * 8 | * 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace gvirtus::common { 21 | typedef enum { step_a, step_b, step_c, step_d } DecodeStep; 22 | 23 | class Decoder { 24 | public: 25 | Decoder(); 26 | 27 | Decoder(const Decoder &orig); 28 | 29 | virtual ~Decoder(); 30 | 31 | int Decode(char value_in); 32 | 33 | int Decode(const char *, int, char *); 34 | 35 | void Decode(std::istream &, std::ostream &); 36 | 37 | private: 38 | log4cplus::Logger logger; 39 | int _buffersize; 40 | DecodeStep step; 41 | char plainchar; 42 | 43 | int Value(char value_in); 44 | 45 | int Block(const char *code_in, const int length_in, char *plaintext_out); 46 | }; 47 | } // namespace gvirtus::common 48 | -------------------------------------------------------------------------------- /include/gvirtus/common/Encoder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Decoder.h 3 | * @author Raffaele Montella 4 | * @date Wed Nov 30 17:16:48 2016 5 | * 6 | * @brief 7 | * 8 | * 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | namespace gvirtus::common { 17 | typedef enum { step_A, step_B, step_C } EncodeStep; 18 | 19 | class Encoder { 20 | public: 21 | Encoder(); 22 | 23 | Encoder(const Encoder &orig); 24 | 25 | virtual ~Encoder(); 26 | 27 | int Encode(char value_in); 28 | 29 | int Encode(const char *, int, char *); 30 | 31 | void Encode(std::istream &, std::ostream &); 32 | 33 | private: 34 | int CHARS_PER_LINE; 35 | 36 | int _buffersize; 37 | EncodeStep step; 38 | char result; 39 | int stepcount; 40 | 41 | int Value(char value_in); 42 | 43 | int Block(const char *code_in, const int length_in, char *plaintext_out); 44 | 45 | int BlockEnd(char *code_out); 46 | 47 | int EncodeEnd(char *code_out); 48 | }; 49 | } // namespace gvirtus::common 50 | -------------------------------------------------------------------------------- /include/gvirtus/common/JSON.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace fs = std::experimental::filesystem; 10 | 11 | namespace gvirtus::common { 12 | /** 13 | * JSON class. 14 | * This class is a wrapper of nlohmann::json class. 15 | * When you are starting this class you must indicate a type of class, here 16 | * called T. This serves to parser method to determine how to construct an 17 | * object from a json file or as a json file to build from a given class. 18 | * @tparam T: T must be a class. This class must have the functions to_json and 19 | * from_json defined. See Property.h for more info 20 | */ 21 | template 22 | class JSON { 23 | public: 24 | /** 25 | * Default constructor 26 | */ 27 | JSON() = default; 28 | 29 | /** 30 | * Parameterized constructor 31 | * @param file_path: the path where json file is located 32 | */ 33 | // TOdO: default path? 34 | JSON(fs::path file_path) { path(file_path); } 35 | /** 36 | * This method loads the contents of the json file into the json object using 37 | * a std::fstream file handler 38 | * @param file_path: the path where json file is located 39 | * @return reference to itself (Fluent Interface API) 40 | *///TOdO: default path? 41 | JSON &path(fs::path &file_path) { 42 | _handler. 43 | exceptions(std::ios::failbit 44 | | std::ios::badbit); 45 | 46 | if ( 47 | fs::exists(file_path) 48 | && 49 | fs::is_regular_file(file_path) 50 | && 51 | file_path. 52 | filename() 53 | . 54 | extension() 55 | == ".json") { 56 | _handler. 57 | open(file_path 58 | . 59 | string() 60 | ); 61 | 62 | if (_handler. 63 | is_open() 64 | ) { 65 | _file_path = file_path; 66 | _handler >> 67 | _json; 68 | } else 69 | // TODO: exception or optional? 70 | throw std::ifstream::failure("Can't open file"); 71 | } else 72 | // TODO: exception or optional? 73 | throw std::ifstream::failure("No such file, or file is irregular"); 74 | 75 | return *this; 76 | } 77 | 78 | /** 79 | * @return the path where json file is located 80 | */ 81 | inline const fs::path 82 | path() const { 83 | return _file_path; 84 | } 85 | /** 86 | * @return copy of the object built from json file 87 | */ 88 | T parser() { 89 | if (!_json.is_null()) { 90 | auto object = _json.get(); 91 | return object; 92 | } 93 | 94 | return T(); 95 | } 96 | 97 | /** 98 | * Class destroyer 99 | */ 100 | ~JSON() { 101 | _json.clear(); 102 | _handler.close(); 103 | _file_path.clear(); 104 | } 105 | 106 | private: 107 | nlohmann::json _json; 108 | std::ifstream _handler; 109 | fs::path _file_path; 110 | }; // namespace gvirtus::util 111 | } 112 | -------------------------------------------------------------------------------- /include/gvirtus/common/LD_Lib.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | //#define ldDEBUG 9 | 10 | namespace gvirtus::common { 11 | 12 | template class LD_Lib { 13 | private: 14 | using create_t = std::shared_ptr(Args...); 15 | 16 | /* DLOPEN */ 17 | void dlopen(const std::string &path, int flag = RTLD_LAZY) { 18 | #ifdef ldDEBUG 19 | std::cout << "LD_Lib::dlopen(path, flag) called" << std::endl; 20 | #endif 21 | 22 | m_module = ::dlopen(path.c_str(), flag); 23 | 24 | if (m_module == nullptr) { 25 | throw "Error loading: " + std::string(dlerror()); 26 | } 27 | 28 | #ifdef ldDEBUG 29 | std::cout << "LD_Lib::dlopen(path, flag) returned" << std::endl; 30 | #endif 31 | } 32 | 33 | /* SET_CREATE_SYMBOL */ 34 | void set_create_symbol(const std::string &function) { 35 | #ifdef ldDEBUG 36 | std::cout << "LD_Lib::set_create_symbol(&function) called" << std::endl; 37 | std::cout << "function: " << function.c_str() << std::endl; 38 | if (m_module == nullptr) { 39 | std::cout << "m_module is null!!! " << std::endl; 40 | } 41 | #endif 42 | 43 | // Since the value of the symbol could actually be NULL (so that a NULL return from dlsym() 44 | // need not indicate an error) the correct way to test for an error is to 45 | // call dlerror() to clear any old error conditions, then call dlsym(), and then 46 | // call dlerror() again, saving its return value, and check whether this saved value is not NULL. 47 | dlerror(); 48 | sym = (create_t *) dlsym(m_module, function.c_str()); 49 | auto dl_error = dlerror(); 50 | 51 | if (dl_error != nullptr) { 52 | #ifdef ldDEBUG 53 | std::cout << "LD_Lib::set_create_symbol(&function) exception!" << std::endl; 54 | #endif 55 | std::string error(dl_error); 56 | ::dlclose(m_module); 57 | throw "Cannot load symbol create: " + error; 58 | } 59 | 60 | #ifdef ldDEBUG 61 | std::cout << "LD_Lib::set_create_symbol(&function) returned" << std::endl; 62 | #endif 63 | } 64 | 65 | public: 66 | /* LD_LIB CONSTRUCTOR */ 67 | LD_Lib(const std::string path, std::string fcreate_name = "create_t") { 68 | #ifdef ldDEBUG 69 | std::cout << "LD_Lib::LD_Lib(path, fcreate_name) called (it's the constructor)" << std::endl; 70 | std::cout << "path: " << path << std::endl; 71 | std::cout << "fcreate_name: " << fcreate_name << std::endl; 72 | #endif 73 | 74 | _obj_ptr = nullptr; 75 | dlopen(path); 76 | set_create_symbol(fcreate_name); 77 | 78 | #ifdef ldDEBUG 79 | std::cout << "LD_Lib::LD_Lib(path, fcreate_name) returned" << std::endl; 80 | #endif 81 | } 82 | 83 | /* LD_LIB DESTRUCTOR */ 84 | ~LD_Lib() { 85 | if (m_module != nullptr) { 86 | sym = nullptr; 87 | _obj_ptr.reset(); 88 | ::dlclose(m_module); 89 | } 90 | } 91 | 92 | /* BUILD_OBJ */ 93 | void build_obj(Args... args) { 94 | #ifdef ldDEBUG 95 | std::cout << "LD_Lib::build_obj(Args... args) called" << std::endl; 96 | #endif 97 | _obj_ptr = this->sym(args...); 98 | #ifdef ldDEBUG 99 | std::cout << "LD_Lib::build_obj(Args... args) returned" << std::endl; 100 | #endif 101 | } 102 | 103 | /* OBJ_PTR */ 104 | std::shared_ptr obj_ptr() { 105 | return _obj_ptr; 106 | } 107 | 108 | protected: 109 | create_t *sym; 110 | void *m_module; 111 | std::shared_ptr _obj_ptr; 112 | }; 113 | 114 | } // namespace gvirtus::common 115 | -------------------------------------------------------------------------------- /include/gvirtus/common/MessageDispatcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: MessageDispatcher.h 3 | * Author: cpalmieri 4 | * 5 | * Created on March 4, 2016, 2:22 PM 6 | */ 7 | 8 | #pragma once 9 | 10 | namespace gvirtus::common { 11 | class MessageDispatcher { 12 | public: 13 | MessageDispatcher(); 14 | MessageDispatcher(const MessageDispatcher &orig); 15 | virtual ~MessageDispatcher(); 16 | 17 | private: 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /include/gvirtus/common/Mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file Mutex.h 28 | * @author Giuseppe Coviello 29 | * @date Thu Oct 1 11:54:04 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace gvirtus::common { 41 | /** 42 | * Mutex can be used to implement the mutual exclusion on blocks of code. 43 | */ 44 | class Mutex { 45 | public: 46 | Mutex(); 47 | virtual ~Mutex(); 48 | bool Lock(); 49 | void Unlock(); 50 | 51 | private: 52 | pthread_mutex_t mMutex; 53 | }; 54 | 55 | #define synchronized(mutex) \ 56 | for (bool __mutex_lock = (mutex).Lock(); __mutex_lock; \ 57 | __mutex_lock = false, (mutex).Unlock()) 58 | } 59 | -------------------------------------------------------------------------------- /include/gvirtus/common/Observable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file Observable.h 28 | * @author Giuseppe Coviello 29 | * @date Sat Oct 3 9:26:26 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | #include "Observer.h" 43 | 44 | namespace gvirtus::common { 45 | /** 46 | * Observable emits signal that can be catched by registred Observer(s). 47 | */ 48 | class Observable { 49 | public: 50 | Observable(); 51 | virtual ~Observable(); 52 | void AddObserver(std::string &event, const Observer *observer); 53 | void AddObserver(const char *event, const Observer *observer); 54 | 55 | protected: 56 | void Notify(std::string &event); 57 | void Notify(const char *event); 58 | 59 | private: 60 | std::map *> *mObservers; 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /include/gvirtus/common/Observer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file Observer.h 28 | * @author Giuseppe Coviello 29 | * @date Fri Oct 2 15:54:38 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace gvirtus::common { 41 | /** 42 | * Observer object can receive the events emitted by Observable. 43 | */ 44 | class Observer { 45 | public: 46 | virtual ~Observer(); 47 | virtual void EventOccurred(std::string &event, void *object) = 0; 48 | 49 | private: 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /include/gvirtus/common/SignalException.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace gvirtus::common { 7 | class SignalException : public std::runtime_error { 8 | public: 9 | SignalException(const std::string& message) : std::runtime_error(message) {} 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /include/gvirtus/common/SignalState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace gvirtus::common { 7 | class SignalState { 8 | public: 9 | SignalState() = default; 10 | ~SignalState() = default; 11 | void setup_signal_state(int); 12 | 13 | static inline bool get_signal_state(int signo) { 14 | return _signals_state[signo]; 15 | } 16 | private: 17 | static void true_flag(int signo) { _signals_state[signo] = true; } 18 | static std::map _signals_state; 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /include/gvirtus/common/Util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file Util.h 28 | * @author Giuseppe Coviello 29 | * @date Sun Oct 11 17:16:48 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include "gvirtus-type.h" 41 | 42 | namespace gvirtus::common { 43 | /** 44 | *Util contains facility functions used by gVirtuS. These functions 45 | * includes the ones for marshalling and unmarshalling pointers and "CUDA fat 46 | * binaries". 47 | */ 48 | class Util { 49 | public: 50 | Util(); 51 | Util(const Util &orig); 52 | virtual ~Util(); 53 | static const size_t MarshaledDevicePointerSize = sizeof(void *) * 2 + 3; 54 | static const size_t MarshaledHostPointerSize = sizeof(void *) * 2 + 3; 55 | static char *MarshalHostPointer(const void *ptr); 56 | static void MarshalHostPointer(const void *ptr, char *marshal); 57 | static char *MarshalDevicePointer(const void *devPtr); 58 | static void MarshalDevicePointer(const void *devPtr, char *marshal); 59 | static inline void *UnmarshalPointer(const char *marshal) { 60 | return (void *) strtoul(marshal, NULL, 16); 61 | } 62 | template 63 | static inline pointer_t MarshalPointer(const T ptr) { 64 | /*Verify the correctness */ 65 | return static_cast(ptr); 66 | } 67 | 68 | private: 69 | }; 70 | } 71 | -------------------------------------------------------------------------------- /include/gvirtus/common/gvirtus-type.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace gvirtus::common { 6 | #if defined(__ia64) || defined(__itanium__) || defined(_M_IA64) || \ 7 | defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) 8 | typedef uint64_t pointer_t; 9 | #else 10 | typedef uint32_t pointer_t; 11 | #endif 12 | 13 | typedef struct __mappedPointer { 14 | void *pointer; 15 | size_t size; 16 | } mappedPointer; 17 | 18 | typedef enum __funcs { 19 | RegisterFatBinary, 20 | UnregisterFatBinary, 21 | RegisterFunction, 22 | RegisterVar, 23 | RegisterShared, 24 | RegisterSharedVar, 25 | RegisterTexture, 26 | RegisterSurface 27 | } funcs; 28 | } 29 | -------------------------------------------------------------------------------- /include/gvirtus/communicators/AfUnixCommunicator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file AfUnixCommunicator.h 28 | * @author Giuseppe Coviello 29 | * @date Wed Sep 30 12:01:12 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #ifndef _AFUNIXCOMMUNICATOR_H 37 | #define _AFUNIXCOMMUNICATOR_H 38 | 39 | #ifndef __WIN32 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | #include 46 | 47 | #include "Communicator.h" 48 | 49 | namespace gvirtus { 50 | 51 | /** 52 | * AfUnixCommunicator implements a Communicator for the AF_UNIX socket in the unix domain. 53 | */ 54 | class AfUnixCommunicator : public Communicator { 55 | public: 56 | AfUnixCommunicator(const std::string &communicator); 57 | /** 58 | * Creates a new AfUnixCommunicator for binding or connecting it to the 59 | * AF_UNIX socket specified from path. 60 | * 61 | * @param path the path the AF_UNIX socket. 62 | * @param mode 63 | * @param use_shm 64 | */ 65 | AfUnixCommunicator(std::string &path, mode_t mode); 66 | 67 | /** 68 | * Creates a new AfUnixCommunicator for binding or connecting it to the 69 | * AF_UNIX socket specified from path. 70 | * 71 | * @param path the path the AF_UNIX socket. 72 | * @param mode 73 | * @param use_shm 74 | */ 75 | AfUnixCommunicator(const char *path, mode_t mode); 76 | 77 | /** 78 | * Creates a new AfUnixCommunicator for binding or connecting it to the 79 | * AF_UNIX socket specified from path. 80 | * 81 | * @param path the path the AF_UNIX socket. 82 | */ 83 | AfUnixCommunicator(int fd); 84 | 85 | virtual ~AfUnixCommunicator(); 86 | void Serve(); 87 | const Communicator *const Accept() const; 88 | void Connect(); 89 | size_t Read(char *buffer, size_t size); 90 | size_t Write(const char *buffer, size_t size); 91 | void Sync(); 92 | void Close(); 93 | 94 | private: 95 | /** 96 | * Initializes the input and output streams. 97 | */ 98 | void InitializeStream(); 99 | std::istream *mpInput; /**< the input stream for sending */ 100 | std::ostream *mpOutput; /**< the output stream for receiving data */ 101 | std::string mPath; /**< the path of the AF_UNIX socket */ 102 | int mSocketFd; /**< the file descriptor of the connected socket */ 103 | __gnu_cxx::stdio_filebuf *mpInputBuf; 104 | __gnu_cxx::stdio_filebuf *mpOutputBuf; 105 | mode_t mMode; 106 | }; 107 | 108 | } // namespace gvirtus 109 | 110 | #endif 111 | 112 | #endif /* _AFUNIXCOMMUNICATOR_H */ 113 | -------------------------------------------------------------------------------- /include/gvirtus/communicators/Communicator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Endpoint.h" 6 | 7 | namespace gvirtus::communicators { 8 | /** 9 | * Communicator is an abstract class that implements a simple stream oriented 10 | * mechanism for communicating with two end points. 11 | * Communicator use a client/server approach, for having a Communicator server 12 | * the application must call Serve() and the Accept() for accepting the 13 | * connection by clients and communicating to them. 14 | * The client has to use just the Connect() method. 15 | * For sending and receiving data through the communicator is possible the use 16 | * the input and output stream. Warning: _never_ try to communicate through the 17 | * streams of a server Communicator, for communicating with the client the 18 | * Communicator returned from the Accept() must be used. 19 | */ 20 | class Communicator { 21 | public: 22 | /** 23 | * Creates a new communicator. The real type of the communicator and his 24 | * parameters are obtained from the ConfigFile::Element @arg config. 25 | * 26 | * @param config the ConfigFile::Element that stores the configuration. 27 | * 28 | * @return a new Communicator. 29 | */ 30 | 31 | virtual ~Communicator() = default; 32 | 33 | /** 34 | * Sets the communicator as a server. 35 | */ 36 | virtual void Serve() = 0; 37 | 38 | /** 39 | * Accepts a new connection. The call to the first Accept() must follow a 40 | * call to Serve(). 41 | * 42 | * @return a Communicator to the connected peer. 43 | */ 44 | virtual const Communicator *const Accept() const = 0; 45 | 46 | /** 47 | * Sets the communicator as a client and connects it to the end point 48 | * specified in the ConfigFile::Element used to build this Communicator. 49 | */ 50 | virtual void Connect() = 0; 51 | 52 | virtual size_t Read(char *buffer, size_t size) = 0; 53 | virtual size_t Write(const char *buffer, size_t size) = 0; 54 | virtual void Sync() = 0; 55 | 56 | /** 57 | * Closes the connection with the end point. 58 | */ 59 | virtual void Close() = 0; 60 | 61 | virtual std::string to_string() { return "communicator"; } 62 | 63 | virtual void run(){}; 64 | 65 | private: 66 | }; 67 | 68 | using create_t = std::shared_ptr(std::shared_ptr); 69 | 70 | } // namespace gvirtus::communicators 71 | -------------------------------------------------------------------------------- /include/gvirtus/communicators/Endpoint.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace gvirtus::communicators { 6 | /** 7 | * Endpoint class. 8 | * This class is a model to represent the endpoint property. 9 | */ 10 | class Endpoint { 11 | public: 12 | /** 13 | * Parameterized constructor 14 | * @param protocol: string containing protocol value 15 | * @param address: string containing address value 16 | * @param port: string containing port value 17 | */ 18 | Endpoint() = default; 19 | 20 | /** 21 | * This method is a setter for the class member _suite 22 | * @param protocol: string containing suite value 23 | * @return reference to itself (Fluent Interface API) 24 | */ 25 | virtual Endpoint &suite(const std::string &suite) = 0; 26 | 27 | /** 28 | * This method is a getter for the class member _suite 29 | * @return reference to class member _suite 30 | */ 31 | virtual inline const std::string &suite() const { return _suite; } 32 | 33 | /** 34 | * This method is a setter for the class member _protocol 35 | * @param protocol: string containing protocol value 36 | * @return reference to itself (Fluent Interface API) 37 | */ 38 | virtual Endpoint &protocol(const std::string &protocol) = 0; 39 | 40 | /** 41 | * This method is a getter for the class member _protocol 42 | * @return reference to class member _protocol 43 | */ 44 | virtual inline const std::string &protocol() const { return _protocol; } 45 | 46 | /** 47 | * This method return an object description 48 | * @return string that represents the concatenation between class member 49 | */ 50 | virtual inline const std::string to_string() const { 51 | return _suite + _protocol; 52 | }; 53 | 54 | /** 55 | * This method is an overload of == operator. 56 | * @param endpoint: object to compare 57 | * @return True if two object are similar, false otherwise 58 | */ 59 | inline bool operator==(const Endpoint &endpoint) const { 60 | return this->to_string() == endpoint.to_string(); 61 | } 62 | 63 | protected: 64 | std::string _suite; 65 | std::string _protocol; 66 | }; 67 | } // namespace gvirtus::communicators 68 | -------------------------------------------------------------------------------- /include/gvirtus/communicators/EndpointFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include "Endpoint.h" 7 | #include "Endpoint_Rdma.h" 8 | #include "Endpoint_Tcp.h" 9 | 10 | //#define DEBUG 11 | 12 | namespace gvirtus::communicators { 13 | class EndpointFactory { 14 | public: 15 | static std::shared_ptr get_endpoint(const fs::path &json_path) { 16 | #ifdef DEBUG 17 | std::cout << "EndpointFactory::get_endpoint() called" << std::endl; 18 | #endif 19 | 20 | std::shared_ptr ptr; 21 | std::ifstream ifs(json_path); 22 | nlohmann::json j; 23 | ifs >> j; 24 | 25 | // FIXME: This if-else smells... 26 | // tcp/ip 27 | if ("tcp/ip" == j["communicator"][ind_endpoint]["endpoint"].at("suite")) { 28 | #ifdef DEBUG 29 | std::cout << "EndpointFactory::get_endpoint() found tcp/ip endpoint" << std::endl; 30 | #endif 31 | auto end = common::JSON(json_path).parser(); 32 | ptr = std::make_shared(end); 33 | } 34 | // infiniband 35 | else if ("infiniband-rdma" == j["communicator"][ind_endpoint]["endpoint"].at("suite")) { 36 | #ifdef DEBUG 37 | std::cout << "EndpointFactory::get_endpoint() found infiniband endpoint" << std::endl; 38 | #endif 39 | auto end = common::JSON(json_path).parser(); 40 | ptr = std::make_shared(end); 41 | } 42 | else { 43 | throw "EndpointFactory::get_endpoint(): Your suite is not compatible!"; 44 | } 45 | 46 | ind_endpoint++; 47 | 48 | j.clear(); 49 | ifs.close(); 50 | 51 | #ifdef DEBUG 52 | std::cout << "EndpointFactoru::get_endpoint(): end is: " << ptr->to_string() << std::endl; 53 | std::cout << "EndpointFactory::get_endpoint() ended" << std::endl; 54 | #endif 55 | 56 | return ptr; 57 | } 58 | 59 | static int index() { return ind_endpoint; } 60 | 61 | private: 62 | static int ind_endpoint; 63 | }; 64 | } // namespace gvirtus::communicators 65 | -------------------------------------------------------------------------------- /include/gvirtus/communicators/Endpoint_Rdma.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Mariano Aponte on 18/12/23. 3 | // 4 | 5 | #ifndef GVIRTUS_ENDPOINT_RDMA_H 6 | #define GVIRTUS_ENDPOINT_RDMA_H 7 | 8 | #pragma once 9 | 10 | #include 11 | #include "Endpoint.h" 12 | 13 | namespace gvirtus::communicators { 14 | 15 | 16 | class Endpoint_Rdma : public Endpoint { 17 | private: 18 | std::string _address; 19 | std::uint16_t _port; 20 | 21 | public: 22 | Endpoint_Rdma() = default; 23 | 24 | explicit Endpoint_Rdma(const std::string &endp_suite, 25 | const std::string &endp_protocol, 26 | const std::string &endp_address, 27 | const std::string &endp_port); 28 | 29 | explicit Endpoint_Rdma(const std::string &endp_suite) 30 | : Endpoint_Rdma(endp_suite, "ib", "127.0.0.1", "9999") {} 31 | 32 | Endpoint &suite(const std::string &suite) override; 33 | Endpoint &protocol(const std::string &protocol) override; 34 | 35 | Endpoint_Rdma &address(const std::string &address); 36 | inline const std::string &address() const { return _address; } 37 | 38 | Endpoint_Rdma &port(const std::string &port); 39 | inline const std::uint16_t &port() const { return _port; } 40 | 41 | virtual inline const std::string to_string() const { 42 | return _suite + _protocol + _address + std::to_string(_port); 43 | } 44 | 45 | std::string to_string() { 46 | return "EndpointRdma"; 47 | } 48 | 49 | }; 50 | void from_json(const nlohmann::json &j, Endpoint_Rdma &end); 51 | } 52 | #endif //GVIRTUS_ENDPOINT_RDMA_H 53 | -------------------------------------------------------------------------------- /include/gvirtus/communicators/Endpoint_Tcp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Endpoint.h" 5 | 6 | namespace gvirtus::communicators { 7 | class Endpoint_Tcp : public Endpoint { 8 | public: 9 | Endpoint_Tcp() = default; 10 | 11 | explicit Endpoint_Tcp(const std::string &endp_suite, 12 | const std::string &endp_protocol, 13 | const std::string &endp_address, 14 | const std::string &endp_port); 15 | 16 | explicit Endpoint_Tcp(const std::string &endp_suite) 17 | : Endpoint_Tcp(endp_suite, "tcp", "127.0.0.1", "9999") {} 18 | 19 | Endpoint &suite(const std::string &suite) override; 20 | 21 | Endpoint &protocol(const std::string &protocol) override; 22 | 23 | /** 24 | * This method is a setter for the class member _address 25 | * @param address: string containing address value 26 | * @return reference to itself (Fluent Interface API) 27 | */ 28 | Endpoint_Tcp &address(const std::string &address); 29 | 30 | /** 31 | * This method is a setter for the class member _port 32 | * @param port: string containing port value 33 | * @return reference to itself (Fluent Interface API) 34 | */ 35 | Endpoint_Tcp &port(const std::string &port); 36 | 37 | /** 38 | * This method is a getter for the class member _address 39 | * @return reference to class member _address 40 | */ 41 | inline const std::string &address() const { return _address; } 42 | 43 | /** 44 | * This method is a getter for the class member _port 45 | * @return reference to class member _port 46 | */ 47 | inline const std::uint16_t &port() const { return _port; } 48 | 49 | /** 50 | * This method return an object description 51 | * @return string that represents the concatenation between class member 52 | */ 53 | virtual inline const std::string to_string() const { 54 | return _suite + _protocol + _address + std::to_string(_port); 55 | } 56 | 57 | 58 | private: 59 | std::string _address; 60 | std::uint16_t _port; 61 | }; 62 | 63 | /** 64 | * This function will be used by nlohmann::json object when we call 65 | * j.get<Property<(). Without this function the program doesn't know how 66 | * to build a property object from json object. 67 | * @param j: reference to json object which contains the data 68 | * @param p: reference to endpoint object to be created 69 | */ 70 | void from_json(const nlohmann::json &j, Endpoint_Tcp &end); 71 | } // namespace gvirtus::communicators 72 | -------------------------------------------------------------------------------- /include/gvirtus/communicators/Result.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file Result.h 28 | * @author Giuseppe Coviello 29 | * @date Sun Oct 18 13:23:56 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include "Buffer.h" 41 | 42 | namespace gvirtus::communicators { 43 | /** 44 | * Result is used to store the results of a CUDA Runtime routine. 45 | */ 46 | class Result { 47 | public: 48 | Result(int exit_code); 49 | Result(int exit_code, const std::shared_ptr output_buffer); 50 | 51 | virtual ~Result() = default; 52 | int GetExitCode(); 53 | 54 | void Dump(Communicator *c); 55 | 56 | void TimeTaken(double time_taken); 57 | double TimeTaken() const; 58 | 59 | private: 60 | int mExitCode; 61 | std::shared_ptr mpOutputBuffer; 62 | double mTimeTaken = 0; 63 | }; 64 | } // namespace gvirtus::communicators 65 | -------------------------------------------------------------------------------- /include/gvirtus/communicators/ShmCommunicator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file ShmCommunicator.h 28 | * @author Giuseppe Coviello 29 | * @date Tue Nov 16 9:52:26 2010 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #ifndef SHMCOMMUNICATOR_H 37 | #define SHMCOMMUNICATOR_H 38 | 39 | #include 40 | #include 41 | 42 | #include "Communicator.h" 43 | 44 | namespace gvirtus { 45 | 46 | class ShmCommunicator : public Communicator { 47 | public: 48 | ShmCommunicator(const std::string &communicator); 49 | ShmCommunicator(); 50 | virtual ~ShmCommunicator(); 51 | void Serve(); 52 | const Communicator *const Accept() const; 53 | void Connect(); 54 | size_t Read(char *buffer, size_t size); 55 | size_t Write(const char *buffer, size_t size); 56 | void Sync(); 57 | void Close(); 58 | 59 | private: 60 | ShmCommunicator(const char *name); 61 | size_t ReadPacket(char *buffer); 62 | int mSocketFd; 63 | int mFd; 64 | char *mpShm; 65 | size_t mIOSize; 66 | int *mpClosed; 67 | sem_t *mpInEmpty; 68 | sem_t *mpInFull; 69 | size_t *mpInSize; 70 | char *mpIn; 71 | sem_t *mpOutEmpty; 72 | sem_t *mpOutFull; 73 | size_t *mpOutSize; 74 | char *mpOut; 75 | char *mpLocalIn; 76 | size_t mLocalInSize; 77 | size_t mLocalInOffset; 78 | char *mpLocalOut; 79 | size_t mLocalOutSize; 80 | size_t mLocalOutOffset; 81 | }; 82 | } // namespace gvirtus 83 | #endif /* SHMCOMMUNICATOR_H */ 84 | -------------------------------------------------------------------------------- /include/gvirtus/communicators/VMShmCommunicator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file VMShmCommunicator.h 28 | * @author Giuseppe Coviello 29 | * @date Tue Nov 16 12:34:26 2010 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #ifndef VMSHMCOMMUNICATOR_H 37 | #define VMSHMCOMMUNICATOR_H 38 | 39 | #include 40 | 41 | #include 42 | 43 | #include "Communicator.h" 44 | 45 | namespace gvirtus { 46 | 47 | typedef struct { 48 | pthread_spinlock_t *mLock; 49 | int *mCounter; 50 | } vmshm_sem_t; 51 | 52 | class VMShmCommunicator : public Communicator { 53 | public: 54 | VMShmCommunicator(const std::string &communicator); 55 | VMShmCommunicator(const char *hostname, short port); 56 | virtual ~VMShmCommunicator(); 57 | void Serve(); 58 | const Communicator *const Accept() const; 59 | void Connect(); 60 | size_t Read(char *buffer, size_t size); 61 | size_t Write(const char *buffer, size_t size); 62 | void Sync(); 63 | void Close(); 64 | 65 | private: 66 | VMShmCommunicator(const char *name); 67 | size_t ReadPacket(char *buffer); 68 | std::string mHostname; 69 | short mPort; 70 | int mSocketFd; 71 | int mFd; 72 | char *mpVMShm; 73 | size_t mIOSize; 74 | int *mpClosed; 75 | vmshm_sem_t mpInEmpty; 76 | vmshm_sem_t mpInFull; 77 | size_t *mpInSize; 78 | char *mpIn; 79 | vmshm_sem_t mpOutEmpty; 80 | vmshm_sem_t mpOutFull; 81 | size_t *mpOutSize; 82 | char *mpOut; 83 | char *mpLocalIn; 84 | size_t mLocalInSize; 85 | size_t mLocalInOffset; 86 | char *mpLocalOut; 87 | size_t mLocalOutSize; 88 | size_t mLocalOutOffset; 89 | }; 90 | } // namespace gvirtus 91 | #endif /* VMSHMCOMMUNICATOR_H */ 92 | -------------------------------------------------------------------------------- /include/gvirtus/communicators/VMSocketCommunicator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: VMSocketCommunicator.h 3 | * Author: cjg 4 | * 5 | * Created on February 14, 2011, 3:57 PM 6 | */ 7 | 8 | #ifndef VMSOCKETCOMMUNICATOR_H 9 | #define VMSOCKETCOMMUNICATOR_H 10 | 11 | #include "Communicator.h" 12 | #include 13 | 14 | namespace gvirtus { 15 | class VMSocketCommunicator : public Communicator { 16 | public: 17 | VMSocketCommunicator(const std::string &communicator); 18 | void Serve(); 19 | const Communicator *const Accept() const; 20 | void Connect(); 21 | size_t Read(char *buffer, size_t size); 22 | size_t Write(const char *buffer, size_t size); 23 | void Sync(); 24 | void Close(); 25 | 26 | private: 27 | int mFd; 28 | std::string mPath; 29 | std::string mDevice; 30 | }; 31 | } // namespace gvirtus 32 | #endif /* VMSOCKETCOMMUNICATOR_H */ 33 | -------------------------------------------------------------------------------- /include/gvirtus/communicators/VirtioCommunicator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file VirtioCommunicator.h 28 | * @author Abhijeet Dev 29 | * @date Tue Mar 6 15:30:21 2012 30 | * 31 | * @brief 32 | * 33 | */ 34 | 35 | #ifndef VIRTIOCOMMUNICATOR_H 36 | #define VIRTIOCOMMUNICATOR_H 37 | 38 | #include "Communicator.h" 39 | #include 40 | 41 | namespace gvirtus { 42 | 43 | class VirtioCommunicator : public Communicator { 44 | public: 45 | VirtioCommunicator(const std::string &communicator); 46 | void Serve(); 47 | const Communicator *const Accept() const; 48 | void Connect(); 49 | size_t Read(char *buffer, size_t size); 50 | size_t Write(const char *buffer, size_t size); 51 | void Sync(); 52 | void Close(); 53 | 54 | private: 55 | int mFd; 56 | std::string mDevice; 57 | }; 58 | } // namespace gvirtus 59 | #endif /* VIRTIOCOMMUNICATOR_H */ 60 | -------------------------------------------------------------------------------- /include/gvirtus/communicators/VmciCommunicator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file VmciCommunicator.h 28 | * @author Giuseppe Coviello 29 | * @date Wed Nov 4 14:50:05 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #ifndef _VMCICOMMUNICATOR_H 37 | #define _VMCICOMMUNICATOR_H 38 | 39 | #include "../config.h" 40 | 41 | #ifdef HAVE_VMCI_VMCI_SOCKETS_H 42 | 43 | #include 44 | 45 | #include 46 | 47 | #include "Communicator.h" 48 | 49 | #define AF_VMCI VMCISock_GetAFValue() 50 | 51 | namespace gvirtus { 52 | 53 | class VmciCommunicator : public Communicator { 54 | public: 55 | VmciCommunicator(short port, short cid = -1); 56 | VmciCommunicator(unsigned fd); 57 | virtual ~VmciCommunicator(); 58 | void Serve(); 59 | const Communicator *const Accept() const; 60 | void Connect(); 61 | std::istream &GetInputStream() const; 62 | std::ostream &GetOutputStream() const; 63 | void Close(); 64 | 65 | /* Semaphores and Shared Memory */ 66 | bool 67 | HasSemaphoresAndShm() { 68 | return false; 69 | } 70 | void 71 | HostWait() {} 72 | void 73 | HostPost() {} 74 | void 75 | HostSet(int value) {} 76 | void 77 | GuestWait() {} 78 | void 79 | GuestPost() {} 80 | void 81 | GuestSet(int value) {} 82 | void * 83 | GetShm() { 84 | return NULL; 85 | } 86 | const char * 87 | GetHostSemName() { 88 | return NULL; 89 | } 90 | const char * 91 | GetGuestSemName() { 92 | return NULL; 93 | } 94 | const char * 95 | GetShmName() { 96 | return NULL; 97 | } 98 | 99 | private: 100 | void InitializeStream(); 101 | std::istream *mpInput; 102 | std::ostream *mpOutput; 103 | short mCid; 104 | short mPort; 105 | int mSocketFd; 106 | __gnu_cxx::stdio_filebuf *mpInputBuf; 107 | __gnu_cxx::stdio_filebuf *mpOutputBuf; 108 | }; 109 | } // namespace gvirtus 110 | #endif /* HAVE_VMCI_VMCI_SOCKETS_H */ 111 | 112 | #endif /* _VMCICOMMUNICATOR_H */ 113 | -------------------------------------------------------------------------------- /include/gvirtus/communicators/ZmqCommunicator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file ZmqCommunicator.h 28 | * @author Giuseppe Coviello 29 | * @date Thu Oct 8 12:08:33 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #ifndef _ZMQCOMMUNICATOR_H 37 | #define _ZMQCOMMUNICATOR_H 38 | 39 | #include 40 | 41 | #ifdef _WIN32 42 | #include 43 | #else 44 | #include 45 | #endif 46 | 47 | #include "Communicator.h" 48 | 49 | namespace gvirtus { 50 | 51 | /** 52 | * ZmqCommunicator implements a Communicator for the ZMQ. 53 | */ 54 | class ZmqCommunicator : public Communicator { 55 | public: 56 | ZmqCommunicator(const std::string &communicator); 57 | ZmqCommunicator(const char *hostname, short port); 58 | ZmqCommunicator(int fd, const char *hostname); 59 | virtual ~ZmqCommunicator(); 60 | void Serve(); 61 | const Communicator *const Accept() const; 62 | void Connect(); 63 | size_t Read(char *buffer, size_t size); 64 | size_t Write(const char *buffer, size_t size); 65 | void Sync(); 66 | void Close(); 67 | 68 | private: 69 | void InitializeStream(); 70 | std::istream *mpInput; 71 | std::ostream *mpOutput; 72 | std::string mHostname; 73 | char *mInAddr; 74 | int mInAddrSize; 75 | short mPort; 76 | int mSocketFd; 77 | #ifdef _WIN32 78 | std::filebuf *mpInputBuf; 79 | std::filebuf *mpOutputBuf; 80 | #else 81 | __gnu_cxx::stdio_filebuf *mpInputBuf; 82 | __gnu_cxx::stdio_filebuf *mpOutputBuf; 83 | #endif 84 | zmq::context_t *zmq_context; 85 | zmq::socket_t *zmq_socket; 86 | }; 87 | } // namespace gvirtus 88 | #endif /* _ZMQCOMMUNICATOR_H */ 89 | -------------------------------------------------------------------------------- /plugins/cublas/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.17) 2 | project(gvirtus-plugin-cublas) 3 | find_package(CUDA REQUIRED) 4 | 5 | include_directories(${CUDA_INCLUDE_DIRS}) 6 | 7 | gvirtus_add_backend(cublas ${CUDA_VERSION} 8 | backend/CublasHandler.cpp) 9 | target_link_libraries(${PROJECT_NAME} ${CUDA_cublas_LIBRARY} ${CUDA_CUDART_LIBRARY}) 10 | 11 | gvirtus_add_frontend(cublas ${CUDA_VERSION} 12 | frontend/Cublas_helper.cpp 13 | frontend/Cublas_level1.cpp 14 | frontend/Cublas_level2.cpp 15 | frontend/Cublas_level3.cpp 16 | frontend/CublasFrontend.cpp) 17 | -------------------------------------------------------------------------------- /plugins/cublas/frontend/CublasFrontend.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include "CublasFrontend.h" 27 | 28 | using namespace std; 29 | 30 | CublasFrontend msInstance __attribute_used__; 31 | void * CublasFrontend::handler = NULL; 32 | 33 | using gvirtus::frontend::Frontend; 34 | 35 | CublasFrontend::CublasFrontend() { 36 | Frontend::GetFrontend(); 37 | } 38 | -------------------------------------------------------------------------------- /plugins/cudadr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.17) 2 | project(gvirtus-plugin-cudadr) 3 | -------------------------------------------------------------------------------- /plugins/cudadr/backend/CudaDrHandler_event.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Flora Giannone , 23 | * Department of Applied Science 24 | */ 25 | 26 | 27 | #include 28 | #include "CudaDrHandler.h" 29 | #include 30 | #include 31 | #include 32 | 33 | /*Creates an event.*/ 34 | CUDA_DRIVER_HANDLER(EventCreate) { 35 | CUevent phEvent = NULL; 36 | unsigned int Flags = input_buffer->Get(); 37 | CUresult exit_code = cuEventCreate(&phEvent, Flags); 38 | std::shared_ptr out = std::make_shared(); 39 | out->AddMarshal(phEvent); 40 | return std::make_shared((cudaError_t) exit_code, out); 41 | } 42 | 43 | /*Destroys an event.*/ 44 | CUDA_DRIVER_HANDLER(EventDestroy) { 45 | CUevent phEvent = input_buffer->Get (); 46 | CUresult exit_code = cuEventDestroy(phEvent); 47 | return std::make_shared((cudaError_t) exit_code); 48 | } 49 | 50 | /*Computes the elapsed time between two events.*/ 51 | CUDA_DRIVER_HANDLER(EventElapsedTime) { 52 | float *pMilliseconds = input_buffer->Assign(); 53 | CUevent hStart = input_buffer->Get (); 54 | CUevent hEnd = input_buffer->Get (); 55 | CUresult exit_code = cuEventElapsedTime(pMilliseconds, hStart, hEnd); 56 | std::shared_ptr out = std::make_shared(); 57 | out->Add(pMilliseconds); 58 | return std::make_shared((cudaError_t) exit_code, out); 59 | } 60 | 61 | /*Queries an event's status.*/ 62 | CUDA_DRIVER_HANDLER(EventQuery) { 63 | CUevent hEvent = input_buffer->Get (); 64 | CUresult exit_code = cuEventQuery(hEvent); 65 | return std::make_shared((cudaError_t) exit_code); 66 | } 67 | 68 | /*Records an event. */ 69 | CUDA_DRIVER_HANDLER(EventRecord) { 70 | CUevent hEvent = input_buffer->Get (); 71 | CUstream hStream = input_buffer->Get (); 72 | CUresult exit_code = cuEventRecord(hEvent, hStream); 73 | return std::make_shared((cudaError_t) exit_code); 74 | } 75 | 76 | /*Waits for an event to complete.*/ 77 | CUDA_DRIVER_HANDLER(EventSynchronize) { 78 | CUevent hEvent = input_buffer->Get (); 79 | CUresult exit_code = cuEventSynchronize(hEvent); 80 | return std::make_shared((cudaError_t) exit_code); 81 | } 82 | -------------------------------------------------------------------------------- /plugins/cudadr/backend/CudaDrHandler_initialization.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Flora Giannone , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include 27 | #include "CudaDrHandler.h" 28 | #include 29 | 30 | CUDA_DRIVER_HANDLER(Init) { 31 | unsigned int flags = input_buffer->Get(); 32 | CUresult exit_code = cuInit(flags); 33 | return std::make_shared((cudaError_t) exit_code); 34 | } 35 | -------------------------------------------------------------------------------- /plugins/cudadr/backend/CudaDrHandler_stream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Flora Giannone , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include 27 | #include "CudaDrHandler.h" 28 | #include 29 | #include 30 | #include 31 | 32 | /*Create a stream.*/ 33 | CUDA_DRIVER_HANDLER(StreamCreate) { 34 | CUstream phStream = NULL; 35 | unsigned int Flags = input_buffer->Get(); 36 | CUresult exit_code = cuStreamCreate(&phStream, Flags); 37 | std::shared_ptr out = std::make_shared(); 38 | out->AddMarshal(phStream); 39 | return std::make_shared((cudaError_t) exit_code, out); 40 | } 41 | 42 | /*Destroys a stream.*/ 43 | CUDA_DRIVER_HANDLER(StreamDestroy) { 44 | CUstream phStream = input_buffer->Get (); 45 | CUresult exit_code = cuStreamDestroy(phStream); 46 | return std::make_shared((cudaError_t) exit_code); 47 | } 48 | 49 | /*Determine status of a compute stream.*/ 50 | CUDA_DRIVER_HANDLER(StreamQuery) { 51 | CUstream phStream = input_buffer->Get (); 52 | CUresult exit_code = cuStreamQuery(phStream); 53 | return std::make_shared((cudaError_t) exit_code); 54 | } 55 | 56 | /*Wait until a stream's tasks are completed.*/ 57 | CUDA_DRIVER_HANDLER(StreamSynchronize) { 58 | CUstream phStream = input_buffer->Get (); 59 | CUresult exit_code = cuStreamSynchronize(phStream); 60 | return std::make_shared((cudaError_t) exit_code); 61 | } 62 | -------------------------------------------------------------------------------- /plugins/cudadr/backend/CudaDrHandler_version.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Flora Giannone , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include 27 | #include "CudaDrHandler.h" 28 | #include 29 | 30 | /*Return the Cuda Driver Version */ 31 | CUDA_DRIVER_HANDLER(DriverGetVersion) { 32 | int *driverVersion = input_buffer->Assign(); 33 | CUresult exit_code = cuDriverGetVersion(driverVersion); 34 | std::shared_ptr out = std::make_shared(); 35 | out->Add(driverVersion); 36 | return std::make_shared((cudaError_t) exit_code, out); 37 | } 38 | -------------------------------------------------------------------------------- /plugins/cudadr/frontend/CudaDr.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Flora Giannone , 23 | * Department of Applied Science 24 | */ 25 | -------------------------------------------------------------------------------- /plugins/cudadr/frontend/CudaDr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Flora Giannone , 23 | * Department of Applied Science 24 | */ 25 | 26 | #ifndef CUDADR_H_ 27 | #define CUDADR_H_ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "CudaUtil.h" 34 | #include 35 | #include "CudaDrFrontend.h" 36 | 37 | #define __dv(v) 38 | 39 | 40 | #endif /* CUDADR_H_ */ 41 | -------------------------------------------------------------------------------- /plugins/cudadr/frontend/CudaDrFrontend.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | *Written by: Flora Giannone , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include "CudaDrFrontend.h" 27 | 28 | using namespace std; 29 | 30 | CudaDrFrontend msInstance __attribute_used__; 31 | 32 | CudaDrFrontend::CudaDrFrontend() { 33 | Frontend::GetFrontend(); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /plugins/cudadr/frontend/CudaDr_event.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Flora Giannone , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include 27 | #include "CudaDrFrontend.h" 28 | #include "CudaUtil.h" 29 | #include "CudaDr.h" 30 | #include 31 | 32 | using namespace std; 33 | 34 | /*Creates an event.*/ 35 | extern CUresult cuEventCreate(CUevent *phEvent, unsigned int Flags) { 36 | CudaDrFrontend::Prepare(); 37 | CudaDrFrontend::AddVariableForArguments(Flags); 38 | CudaDrFrontend::Execute("cuEventCreate"); 39 | if (CudaDrFrontend::Success()) 40 | *phEvent = (CUevent) (CudaDrFrontend::GetOutputDevicePointer()); 41 | return (CUresult) (CudaDrFrontend::GetExitCode()); 42 | } 43 | 44 | /*Destroys an event.*/ 45 | extern CUresult cuEventDestroy(CUevent hEvent) { 46 | CudaDrFrontend::Prepare(); 47 | CudaDrFrontend::AddDevicePointerForArguments((void*) hEvent); 48 | CudaDrFrontend::Execute("cuEventDestroy"); 49 | return (CUresult) CudaDrFrontend::GetExitCode(); 50 | } 51 | 52 | /*Computes the elapsed time between two events.*/ 53 | extern CUresult cuEventElapsedTime(float *pMilliseconds, CUevent hStart, CUevent hEnd) { 54 | CudaDrFrontend::Prepare(); 55 | CudaDrFrontend::AddHostPointerForArguments(pMilliseconds); 56 | CudaDrFrontend::AddDevicePointerForArguments((void*) hStart); 57 | CudaDrFrontend::AddDevicePointerForArguments((void*) hEnd); 58 | CudaDrFrontend::Execute("cuEventElapsedTime"); 59 | if (CudaDrFrontend::Success()) 60 | *pMilliseconds = *(CudaDrFrontend::GetOutputHostPointer()); 61 | return (CUresult) (CudaDrFrontend::GetExitCode()); 62 | } 63 | 64 | /*Queries an event's status.*/ 65 | extern CUresult cuEventQuery(CUevent hEvent) { 66 | CudaDrFrontend::Prepare(); 67 | CudaDrFrontend::AddDevicePointerForArguments((void*) hEvent); 68 | CudaDrFrontend::Execute("cuEventQuery"); 69 | return (CUresult) CudaDrFrontend::GetExitCode(); 70 | } 71 | 72 | /*Records an event.*/ 73 | extern CUresult cuEventRecord(CUevent hEvent, CUstream hStream) { 74 | CudaDrFrontend::Prepare(); 75 | CudaDrFrontend::AddDevicePointerForArguments((void*) hEvent); 76 | CudaDrFrontend::AddDevicePointerForArguments((void*) hStream); 77 | CudaDrFrontend::Execute("cuEventRecord"); 78 | return (CUresult) CudaDrFrontend::GetExitCode(); 79 | } 80 | 81 | /*Waits for an event to complete.*/ 82 | extern CUresult cuEventSynchronize(CUevent hEvent) { 83 | CudaDrFrontend::Prepare(); 84 | CudaDrFrontend::AddDevicePointerForArguments((void*) hEvent); 85 | CudaDrFrontend::Execute("cuEventSynchronize"); 86 | return (CUresult) CudaDrFrontend::GetExitCode(); 87 | } 88 | -------------------------------------------------------------------------------- /plugins/cudadr/frontend/CudaDr_initialization.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Flora Giannone , 23 | * Department of Applied Science 24 | */ 25 | 26 | 27 | #include 28 | #include "CudaDrFrontend.h" 29 | #include "CudaUtil.h" 30 | #include 31 | 32 | using namespace std; 33 | 34 | /* Initialize the CUDA driver API */ 35 | extern CUresult cuInit(unsigned int flags) { 36 | /* 37 | CudaDrFrontend *pFrontEnd=FrontEndFactory.newFrontEnd(); 38 | pFrontEnd->Prepare(); 39 | pFrontEnd->AddVariableForArguments(flags); 40 | pFrontEnd->Execute("cuInit"); 41 | CUresult result=pFrontEnd->GetExitCode(); 42 | FrontEndFactory.deleteFrontEnd(pFrontEnd); 43 | return result; 44 | */ 45 | CudaDrFrontend::Prepare(); 46 | CudaDrFrontend::AddVariableForArguments(flags); 47 | CudaDrFrontend::Execute("cuInit"); 48 | return (CUresult) (CudaDrFrontend::GetExitCode()); 49 | } 50 | -------------------------------------------------------------------------------- /plugins/cudadr/frontend/CudaDr_stream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Flora Giannone , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include 27 | #include "CudaDrFrontend.h" 28 | #include "CudaUtil.h" 29 | #include "CudaDr.h" 30 | #include 31 | 32 | using namespace std; 33 | 34 | /*Create a stream.*/ 35 | extern CUresult cuStreamCreate(CUstream *phStream, unsigned int Flags) { 36 | CudaDrFrontend::Prepare(); 37 | CudaDrFrontend::AddVariableForArguments(Flags); 38 | CudaDrFrontend::Execute("cuStreamCreate"); 39 | if (CudaDrFrontend::Success()) 40 | *phStream = (CUstream) (CudaDrFrontend::GetOutputDevicePointer()); 41 | return (CUresult) (CudaDrFrontend::GetExitCode()); 42 | } 43 | 44 | /*Destroys a stream.*/ 45 | extern CUresult cuStreamDestroy(CUstream hStream) { 46 | CudaDrFrontend::Prepare(); 47 | CudaDrFrontend::AddDevicePointerForArguments((void*) hStream); 48 | CudaDrFrontend::Execute("cuStreamDestroy"); 49 | return (CUresult) CudaDrFrontend::GetExitCode(); 50 | } 51 | 52 | /*Determine status of a compute stream.*/ 53 | extern CUresult cuStreamQuery(CUstream hStream) { 54 | CudaDrFrontend::Prepare(); 55 | CudaDrFrontend::AddDevicePointerForArguments((void*) hStream); 56 | CudaDrFrontend::Execute("cuStreamQuery"); 57 | return (CUresult) CudaDrFrontend::GetExitCode(); 58 | } 59 | 60 | /*Wait until a stream's tasks are completed.*/ 61 | extern CUresult cuStreamSynchronize(CUstream hStream) { 62 | CudaDrFrontend::Prepare(); 63 | CudaDrFrontend::AddDevicePointerForArguments((void*) hStream); 64 | CudaDrFrontend::Execute("cuStreamSynchronize"); 65 | return (CUresult) CudaDrFrontend::GetExitCode(); 66 | } 67 | -------------------------------------------------------------------------------- /plugins/cudadr/frontend/CudaDr_version.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Flora Giannone , 23 | * Department of Applied Science 24 | */ 25 | 26 | 27 | #include 28 | #include "CudaDrFrontend.h" 29 | #include "CudaUtil.h" 30 | #include "CudaDr.h" 31 | #include 32 | 33 | using namespace std; 34 | 35 | /*Return the Cuda Driver Version */ 36 | extern CUresult cuDriverGetVersion(int *driverVersion) { 37 | CudaDrFrontend::Prepare(); 38 | CudaDrFrontend::AddHostPointerForArguments(driverVersion); 39 | CudaDrFrontend::Execute("cuDriverGetVersion"); 40 | if (CudaDrFrontend::Success()) 41 | *driverVersion = *(CudaDrFrontend::GetOutputHostPointer()); 42 | return (CUresult) (CudaDrFrontend::GetExitCode()); 43 | } 44 | -------------------------------------------------------------------------------- /plugins/cudart/3rdparty/include/CudaRt_internal.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Raffaele Montella on 06/11/21. 3 | // 4 | 5 | #ifndef GVIRTUS_CUDART_INTERNAL_H 6 | #define GVIRTUS_CUDART_INTERNAL_H 7 | 8 | #include 9 | 10 | #define EIFMT_NVAL 0x01 11 | #define EIFMT_HVAL 0x03 12 | #define EIFMT_SVAL 0x04 13 | 14 | #define EIATTR_ERROR 0x00 15 | #define EIATTR_PAD 0x01 16 | #define EIATTR_IMAGE_SLOT 0x02 17 | #define EIATTR_JUMPTABLE_RELOCS 0x03 18 | #define EIATTR_CTAIDZ_USED 0x04 19 | #define EIATTR_MAX_THREADS 0x05 20 | #define EIATTR_IMAGE_OFFSET 0x06 21 | #define EIATTR_IMAGE_SIZE 0x07 22 | #define EIATTR_TEXTURE_NORMALIZED 0x08 23 | #define EIATTR_SAMPLER_INIT 0x09 24 | #define EIATTR_PARAM_CBANK 0x0a 25 | #define EIATTR_SMEM_PARAM_OFFSETS 0x0b 26 | #define EIATTR_CBANK_PARAM_OFFSETS 0x0c 27 | #define EIATTR_SYNC_STACK 0x0d 28 | #define EIATTR_TEXID_SAMPID_MAP 0x0e 29 | #define EIATTR_EXTERNS 0x0f 30 | #define EIATTR_REQNTID 0x10 31 | #define EIATTR_FRAME_SIZE 0x11 32 | #define EIATTR_MIN_STACK_SIZE 0x12 33 | #define EIATTR_SAMPLER_FORCE_UNNORMALIZED 0x13 34 | #define EIATTR_BINDLESS_IMAGE_OFFSETS 0x14 35 | #define EIATTR_BINDLESS_TEXTURE_BANK 0x15 36 | #define EIATTR_BINDLESS_SURFACE_BANK 0x16 37 | #define EIATTR_KPARAM_INFO 0x17 38 | #define EIATTR_SMEM_PARAM_SIZE 0x18 39 | #define EIATTR_CBANK_PARAM_SIZE 0x19 40 | #define EIATTR_QUERY_NUMATTRIB 0x1a 41 | #define EIATTR_MAXREG_COUNT 0x1b 42 | #define EIATTR_EXIT_INSTR_OFFSETS 0x1c 43 | #define EIATTR_S2RCTAID_INSTR_OFFSETS 0x1d 44 | #define EIATTR_CRS_STACK_SIZE 0x1e 45 | #define EIATTR_NEED_CNP_WRAPPER 0x1f 46 | #define EIATTR_NEED_CNP_PATCH 0x20 47 | #define EIATTR_EXPLICIT_CACHING 0x21 48 | #define EIATTR_ISTYPEP_USED 0x22 49 | #define EIATTR_MAX_STACK_SIZE 0x23 50 | #define EIATTR_SUQ_USED 0x24 51 | #define EIATTR_LD_CACHEMOD_INSTR_OFFSETS 0x25 52 | #define EIATTR_LOAD_CACHE_REQUEST 0x26 53 | #define EIATTR_ATOM_SYS_INSTR_OFFSETS 0x27 54 | #define EIATTR_COOP_GROUP_INSTR_OFFSETS 0x28 55 | #define EIATTR_COOP_GROUP_MASK_REGIDS 0x29 56 | #define EIATTR_SW1850030_WAR 0x2a 57 | #define EIATTR_WMMA_USED 0x2b 58 | #define EIATTR_SW2393858_WAR 0x30 59 | #define EIATTR_CUDA_API_VERSION 0x37 60 | 61 | #include 62 | #include 63 | 64 | typedef struct { 65 | uint8_t dummy1[5*16]; 66 | Elf64_Ehdr elf; 67 | } NvFatCubin; 68 | 69 | typedef struct { 70 | uint8_t fmt; 71 | uint8_t attr; 72 | uint16_t value; 73 | } NvInfoAttribute; 74 | 75 | typedef struct { 76 | NvInfoAttribute nvInfoAttribute; 77 | uint16_t index; 78 | uint16_t align; 79 | uint16_t ordinal; 80 | uint16_t offset; 81 | uint16_t a; 82 | uint8_t size; 83 | uint8_t b; 84 | } NvInfoKParam; 85 | 86 | 87 | 88 | typedef struct __infoFunction { 89 | std::vector params; 90 | } NvInfoFunction; 91 | 92 | 93 | 94 | typedef struct __infoFunctionEx { 95 | NvInfoFunction infoFunction; 96 | cudaStream_t stream; 97 | bool adHocStream; 98 | void **args; 99 | } NvInfoFunctionEx; 100 | 101 | 102 | 103 | 104 | 105 | #endif //GVIRTUS_CUDART_INTERNAL_H 106 | -------------------------------------------------------------------------------- /plugins/cudart/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.17) 2 | project(gvirtus-plugin-cudart) 3 | find_package(CUDA REQUIRED) 4 | 5 | find_path(CUDART_INCLUDE_DIRECTORY 6 | cuda_runtime_api.h 7 | PATHS ${CUDA_INCLUDE_DIRS}) 8 | if(NOT CUDART_INCLUDE_DIRECTORY) 9 | message(FATAL_ERROR "cuda_runtime_api.h not found") 10 | endif() 11 | include_directories(${CUDART_INCLUDE_DIRECTORY} ${CUDA_INCLUDE_DIRS} util 3rdparty/include) 12 | 13 | get_filename_component(CUDA_LIBRARIES_PATH ${CUDA_CUDART_LIBRARY} DIRECTORY FALSE) 14 | find_library(CUDART_LIBRARY 15 | cudart 16 | PATHS ${CUDA_LIBRARIES_PATH}) 17 | if(NOT CUDART_LIBRARY) 18 | message(FATAL_ERROR "cudart library not found") 19 | endif() 20 | message(STATUS "Found cudaRT library: ${CUDART_LIBRARY}") 21 | 22 | set(CUDART_VERSION "${CUDART_LIBRARY}") 23 | while(IS_SYMLINK "${CUDART_VERSION}") 24 | message(STATUS "${CUDART_VERSION}") 25 | execute_process(COMMAND readlink "${CUDART_VERSION}" 26 | OUTPUT_VARIABLE CUDART_VERSION 27 | OUTPUT_STRIP_TRAILING_WHITESPACE) 28 | endwhile() 29 | string(REGEX REPLACE ".*\\.so\\.([0-9]+\\.[0-9]+\\.[0-9]+)" "\\1" CUDART_VERSION "${CUDART_VERSION}") 30 | 31 | message(STATUS "Found cudaRt: ${CUDART_VERSION} (${CUDART_INCLUDE_DIRECTORY}/cuda_runtime_api.h, ${CUDART_LIBRARY})") 32 | 33 | gvirtus_add_backend(cudart ${CUDA_VERSION} 34 | backend/CudaRtHandler_texture.cpp 35 | backend/CudaRtHandler_event.cpp 36 | backend/CudaRtHandler_opengl.cpp 37 | backend/CudaRtHandler_surface.cpp 38 | backend/CudaRtHandler_thread.cpp 39 | backend/CudaRtHandler_internal.cpp 40 | backend/CudaRtHandler_occupancy.cpp 41 | backend/CudaRtHandler_execution.cpp 42 | backend/CudaRtHandler_device.cpp 43 | backend/CudaRtHandler_stream.cpp 44 | backend/CudaRtHandler_memory.cpp 45 | backend/CudaRtHandler_version.cpp 46 | backend/CudaRtHandler_error.cpp 47 | backend/CudaRtHandler.cpp 48 | util/CudaUtil.cpp) 49 | target_link_libraries(${PROJECT_NAME} ${CUDA_CUDART_LIBRARY}) 50 | 51 | gvirtus_add_frontend(cudart ${CUDA_VERSION} 52 | frontend/CudaRt.cpp 53 | frontend/CudaRt_device.cpp 54 | frontend/CudaRt_error.cpp 55 | frontend/CudaRt_event.cpp 56 | frontend/CudaRt_execution.cpp 57 | frontend/CudaRtFrontend.cpp 58 | frontend/CudaRt_internal.cpp 59 | frontend/CudaRt_memory.cpp 60 | frontend/CudaRt_occupancy.cpp 61 | frontend/CudaRt_opengl.cpp 62 | frontend/CudaRt_stream.cpp 63 | frontend/CudaRt_surface.cpp 64 | frontend/CudaRt_texture.cpp 65 | frontend/CudaRt_thread.cpp 66 | frontend/CudaRt_version.cpp 67 | util/CudaUtil.cpp) 68 | 69 | add_subdirectory(demo) -------------------------------------------------------------------------------- /plugins/cudart/backend/CudaRtHandler_error.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include "CudaRtHandler.h" 27 | 28 | CUDA_ROUTINE_HANDLER(GetErrorString) { 29 | /* const char* cudaGetErrorString(cudaError_t error) */ 30 | 31 | try { 32 | cudaError_t error = input_buffer->Get(); 33 | const char *error_string = cudaGetErrorString(error); 34 | std::shared_ptr output_buffer = std::make_shared(); 35 | 36 | output_buffer->AddString(error_string); 37 | return std::make_shared(cudaSuccess, output_buffer); 38 | } catch (string e) { 39 | cerr << e << endl; 40 | return std::make_shared(cudaErrorMemoryAllocation); 41 | } 42 | } 43 | CUDA_ROUTINE_HANDLER(PeekAtLastError) { 44 | /* cudaError_t cudaPeekAtLastError(void) */ 45 | return std::make_shared(cudaPeekAtLastError()); 46 | } 47 | 48 | CUDA_ROUTINE_HANDLER(GetLastError) { 49 | /* cudaError_t cudaGetLastError(void) */ 50 | return std::make_shared(cudaGetLastError()); 51 | } 52 | -------------------------------------------------------------------------------- /plugins/cudart/backend/CudaRtHandler_occupancy.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Flora Giannone , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include "CudaRtHandler.h" 27 | 28 | #ifndef CUDART_VERSION 29 | #error CUDART_VERSION not defined 30 | #endif 31 | 32 | /*OccupancyMaxActiveBlocksPerMultiprocessor.*/ 33 | CUDA_ROUTINE_HANDLER(OccupancyMaxActiveBlocksPerMultiprocessor) { 34 | int *numBlocks = input_buffer->Assign(); 35 | const char *func = (const char *)(input_buffer->Get()); 36 | int blockSize = input_buffer->Get(); 37 | size_t dynamicSMemSize = input_buffer->Get(); 38 | 39 | cudaError_t exit_code = cudaOccupancyMaxActiveBlocksPerMultiprocessor( 40 | numBlocks, func, blockSize, dynamicSMemSize); 41 | 42 | std::shared_ptr out = std::make_shared(); 43 | 44 | try { 45 | out->Add(numBlocks); 46 | } catch (string e) { 47 | cerr << e << endl; 48 | return std::make_shared(cudaErrorMemoryAllocation); 49 | } 50 | 51 | return std::make_shared(exit_code, out); 52 | } 53 | 54 | /*OccupancyMaxActiveBlocksPerMultiprocessorWithFlags.*/ 55 | #if (CUDART_VERSION >= 7000) 56 | CUDA_ROUTINE_HANDLER(OccupancyMaxActiveBlocksPerMultiprocessorWithFlags) { 57 | int *numBlocks = input_buffer->Assign(); 58 | const char *func = (const char *)(input_buffer->Get()); 59 | int blockSize = input_buffer->Get(); 60 | size_t dynamicSMemSize = input_buffer->Get(); 61 | unsigned int flags = input_buffer->Get(); 62 | 63 | cudaError_t exit_code = 64 | cudaOccupancyMaxActiveBlocksPerMultiprocessorWithFlags( 65 | numBlocks, func, blockSize, dynamicSMemSize, flags); 66 | 67 | std::shared_ptr out = std::make_shared(); 68 | 69 | try { 70 | out->Add(numBlocks); 71 | } catch (string e) { 72 | cerr << e << endl; 73 | return std::make_shared(cudaErrorMemoryAllocation); 74 | } 75 | 76 | return std::make_shared(exit_code, out); 77 | } 78 | #endif 79 | -------------------------------------------------------------------------------- /plugins/cudart/backend/CudaRtHandler_surface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Carlo Palmieri , 23 | * Department of Science and technology 24 | */ 25 | #include 26 | 27 | #include "CudaRtHandler.h" 28 | 29 | using namespace std; 30 | 31 | // extern const surfaceReference *getSurface(const surfaceReference *handler); 32 | 33 | CUDA_ROUTINE_HANDLER(BindSurfaceToArray) { 34 | char *surfrefHandler = input_buffer->AssignString(); 35 | 36 | surfaceReference *guestSurfref = input_buffer->Assign(); 37 | 38 | surfaceReference *surfref = pThis->GetSurface(surfrefHandler); 39 | cudaChannelFormatDesc *a = &(surfref->channelDesc); 40 | memmove(surfref, guestSurfref, sizeof(surfaceReference)); 41 | cudaArray *array = (cudaArray *)input_buffer->Get(); 42 | cudaChannelFormatDesc *desc = input_buffer->Assign(); 43 | 44 | cudaError_t exit_code = cudaBindSurfaceToArray(surfref, array, desc); 45 | 46 | return std::make_shared(exit_code); 47 | } 48 | 49 | // CUDA_ROUTINE_HANDLER(GetTextureReference) { 50 | // textureReference *texref; 51 | // char *symbol_handler = input_buffer->AssignString(); 52 | // char *symbol = input_buffer->AssignString(); 53 | // 54 | // char *our_symbol = const_cast (pThis->GetVar(symbol_handler)); 55 | // if (our_symbol != NULL) 56 | // symbol = const_cast (our_symbol); 57 | // 58 | // cudaError_t exit_code = cudaGetTextureReference( 59 | // (const textureReference ** ) &texref, symbol); 60 | // 61 | // Buffer *out = new Buffer(); 62 | // if(exit_code == cudaSuccess) 63 | // out->AddString(pThis->GetTextureHandler(texref)); 64 | // else 65 | // out->AddString("0x0"); 66 | // 67 | // return std::make_shared(exit_code, out); 68 | //} 69 | -------------------------------------------------------------------------------- /plugins/cudart/backend/CudaRtHandler_thread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include "CudaRtHandler.h" 27 | 28 | CUDA_ROUTINE_HANDLER(ThreadExit) { 29 | return std::make_shared(cudaThreadExit()); 30 | } 31 | 32 | CUDA_ROUTINE_HANDLER(ThreadSynchronize) { 33 | return std::make_shared(cudaThreadSynchronize()); 34 | } 35 | -------------------------------------------------------------------------------- /plugins/cudart/backend/CudaRtHandler_version.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include "CudaRtHandler.h" 27 | 28 | #ifndef CUDART_VERSION 29 | #error CUDART_VERSION not defined 30 | #endif 31 | #if CUDART_VERSION >= 2030 32 | CUDA_ROUTINE_HANDLER(DriverGetVersion) { 33 | try { 34 | int *driverVersion = input_buffer->Assign(); 35 | cudaError_t exit_code = cudaDriverGetVersion(driverVersion); 36 | 37 | std::shared_ptr out = std::make_shared(); 38 | 39 | out->Add(driverVersion); 40 | return std::make_shared(exit_code, out); 41 | } catch (string e) { 42 | cerr << e << endl; 43 | return std::make_shared(cudaErrorMemoryAllocation); 44 | } 45 | } 46 | 47 | CUDA_ROUTINE_HANDLER(RuntimeGetVersion) { 48 | try { 49 | int *runtimeVersion = input_buffer->Assign(); 50 | cudaError_t exit_code = cudaRuntimeGetVersion(runtimeVersion); 51 | std::shared_ptr out = std::make_shared(); 52 | 53 | out->Add(runtimeVersion); 54 | return std::make_shared(exit_code, out); 55 | } catch (string e) { 56 | cerr << e << endl; 57 | return std::make_shared(cudaErrorMemoryAllocation); 58 | } 59 | } 60 | #endif 61 | -------------------------------------------------------------------------------- /plugins/cudart/backend/cuda_runtime_compat.h: -------------------------------------------------------------------------------- 1 | #if !defined(__CUDA_RUNTIME_COMPAT_H__) 2 | #define __CUDA_RUNTIME_COMPAT_H__ 3 | 4 | /** \cond impl_private */ 5 | #if !defined(__dv) 6 | 7 | #if defined(__cplusplus) 8 | 9 | #define __dv(v) = v 10 | 11 | #else /* __cplusplus */ 12 | 13 | #define __dv(v) 14 | 15 | #endif /* __cplusplus */ 16 | 17 | #endif /* !__dv */ 18 | /** \endcond impl_private */ 19 | 20 | extern __host__ cudaError_t CUDARTAPI cudaSetupArgument(const void *arg, 21 | size_t size, 22 | size_t offset); 23 | extern __host__ cudaError_t CUDARTAPI 24 | cudaConfigureCall(dim3 gridDim, dim3 blockDim, size_t sharedMem __dv(0), 25 | cudaStream_t stream __dv(0)); 26 | extern __host__ __device__ unsigned cudaConfigureCall(dim3 gridDim, 27 | dim3 blockDim, 28 | size_t sharedMem = 0, 29 | void *stream = 0); 30 | 31 | template 32 | static __inline__ __host__ cudaError_t cudaLaunch(T *func) { 33 | return ::cudaLaunch((const void *)func); 34 | } 35 | 36 | template 37 | static __inline__ __host__ cudaError_t cudaSetupArgument(T arg, size_t offset) { 38 | return ::cudaSetupArgument((const void *)&arg, sizeof(T), offset); 39 | } 40 | 41 | #endif /* !__CUDA_RUNTIME_COMPAT_H__ */ 42 | -------------------------------------------------------------------------------- /plugins/cudart/backend/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file main.cpp 28 | * @author Giuseppe Coviello 29 | * @date Wed Sep 30 12:21:51 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | /** 37 | * @mainpage gVirtuS - A GPGPU transparent virtualization component 38 | * 39 | * @section Introduction 40 | * gVirtuS tries to fill the gap between in-house hosted computing clusters, 41 | * equipped with GPGPUs devices, and pay-for-use high performance virtual 42 | * clusters deployed via public or private computing clouds. gVirtuS allows an 43 | * instanced virtual machine to access GPGPUs in a transparent way, with an 44 | * overhead slightly greater than a real machine/GPGPU setup. gVirtuS is 45 | * hypervisor independent, and, even though it currently virtualizes nVIDIA CUDA 46 | * based GPUs, it is not limited to a specific brand technology. The performance 47 | * of the components of gVirtuS is assessed through a suite of tests in 48 | * different deployment scenarios, such as providing GPGPU power to cloud 49 | * computing based HPC clusters and sharing remotely hosted GPGPUs among HPC 50 | * nodes. 51 | * 52 | * @section License 53 | * Copyright (C) 2009 - 2010 54 | * Giuseppe Coviello 55 | * 56 | * This program is free software; you can redistribute it and/or modify it under 57 | * the terms of the GNU General Public License as published by the Free Software 58 | * Foundation; either version 2 of the License, or (at your option) any later 59 | * version. 60 | * 61 | * This program is distributed in the hope that it will be useful, 62 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 63 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 64 | * GNU General Public License for more details. 65 | * 66 | * You should have received a copy of the GNU General Public License 67 | * along with this program; if not, write to the Free Software 68 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 69 | * 70 | */ 71 | 72 | #include 73 | #include "ConfigFile.h" 74 | #include "Communicator.h" 75 | #include "CudaRtBackend.h" 76 | 77 | using namespace std; 78 | 79 | int main(int argc, char** argv) { 80 | string conf = _CONFIG_FILE; 81 | if(argc == 2) 82 | conf = string(argv[1]); 83 | try { 84 | ConfigFile *cf = new ConfigFile(conf.c_str()); 85 | Communicator *c = Communicator::Get(cf->Get("communicator")); 86 | delete cf; 87 | CudaRtBackend b; 88 | b.Start(c); 89 | delete c; 90 | } catch (string &e) { 91 | cerr << "Exception: " << e << endl; 92 | } catch(const char *e) { 93 | cerr << "Exception: " << e << endl; 94 | } 95 | return 0; 96 | } 97 | 98 | -------------------------------------------------------------------------------- /plugins/cudart/demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cuda_add_executable( add_grid.e add_grid.cu OPTIONS --cudart=shared) 2 | #set_target_properties(add_grid.e PROPERTIES CUDA_RUNTIME_LIBRARY shared EXTRA_NVCCFLAGS --cudart=shared) 3 | install(TARGETS add_grid.e RUNTIME DESTINATION ${GVIRTUS_HOME}/demo/cudart) 4 | 5 | cuda_add_executable( dummy0.e dummy0.cu OPTIONS --cudart=shared) 6 | #set_target_properties(dummy0.e PROPERTIES CUDA_RUNTIME_LIBRARY shared EXTRA_NVCCFLAGS --cudart=shared) 7 | install(TARGETS dummy0.e RUNTIME DESTINATION ${GVIRTUS_HOME}/demo/cudart) 8 | 9 | cuda_add_executable(launchKernel.e launchKernel.cu OPTIONS --cudart=shared) 10 | #set_target_properties(launchKernel.e PROPERTIES CUDA_RUNTIME_LIBRARY shared EXTRA_NVCCFLAGS --cudart=shared) 11 | install(TARGETS launchKernel.e RUNTIME DESTINATION ${GVIRTUS_HOME}/demo/cudart) 12 | 13 | message(STATUS "COMPILING...") 14 | message(STATUS LD_LIBRARY_PATH ${LD_LIBRARY_PATH}) 15 | message(STATUS EXTRA_NVCC_FLAGS ${EXTRA_NVCC_FLAGS}) 16 | cuda_add_executable(matrixMul.e matrixMul.cu OPTIONS --cudart=shared) 17 | set(CMAKE_CUDA_RUNTIME_LIBRARY Shared) 18 | set_target_properties(matrixMul.e PROPERTIES 19 | CUDA_RUNTIME_LIBRARY Shared 20 | EXTRA_NVCCFLAGS --cudart=shared) 21 | install(TARGETS matrixMul.e RUNTIME DESTINATION ${GVIRTUS_HOME}/demo/cudart) -------------------------------------------------------------------------------- /plugins/cudart/demo/README.md: -------------------------------------------------------------------------------- 1 | nvcc matrixMul.cu -o matrixMul.e --cudart=shared -------------------------------------------------------------------------------- /plugins/cudart/demo/add_grid.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } 6 | 7 | inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) 8 | { 9 | if (code != cudaSuccess) 10 | { 11 | fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line); 12 | if (abort) exit(code); 13 | } 14 | } 15 | 16 | // CUDA kernel to add elements of two arrays 17 | __global__ 18 | void add(int n, float *x, float *y) 19 | { 20 | int index = blockIdx.x * blockDim.x + threadIdx.x; 21 | int stride = blockDim.x * gridDim.x; 22 | for (int i = index; i < n; i += stride) 23 | y[i] = x[i] + y[i]; 24 | } 25 | 26 | int main(void) 27 | { 28 | int N = 1<<20; 29 | float *x, *y; 30 | 31 | printf("Allocate Unified Memory -- accessible from CPU or GPU\n"); 32 | gpuErrchk(cudaMallocManaged(&x, N*sizeof(float))); 33 | gpuErrchk(cudaMallocManaged(&y, N*sizeof(float))); 34 | 35 | printf("Initialize x and y arrays on the host\n"); 36 | for (int i = 0; i < N; i++) { 37 | x[i] = 1.0f; 38 | y[i] = 2.0f; 39 | } 40 | 41 | printf("Launch kernel on 1M elements on the GPU\n"); 42 | int blockSize = 256; 43 | int numBlocks = (N + blockSize - 1) / blockSize; 44 | add<<>>(N, x, y); 45 | 46 | printf("Wait for GPU to finish before accessing on host\n"); 47 | gpuErrchk(cudaDeviceSynchronize()); 48 | 49 | printf("Check for errors (all values should be 3.0f)\n"); 50 | float maxError = 0.0f; 51 | for (int i = 0; i < N; i++) 52 | maxError = fmax(maxError, fabs(y[i]-3.0f)); 53 | std::cout << "Max error: " << maxError << std::endl; 54 | 55 | printf("Free memory\n"); 56 | gpuErrchk(cudaFree(x)); 57 | gpuErrchk(cudaFree(y)); 58 | 59 | return 0; 60 | } -------------------------------------------------------------------------------- /plugins/cudart/demo/dummy0.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | __global__ 6 | void dummy0() 7 | { 8 | int i = blockIdx.x * blockDim.x + threadIdx.x; 9 | } 10 | 11 | 12 | int main(void) 13 | { 14 | int N=1 << 20; 15 | unsigned int threads = 256; 16 | unsigned int blocks = (N + 255) / threads; 17 | 18 | // dummy0<<>>(); 19 | 20 | 21 | void *args[] = {}; 22 | 23 | printf("cudaLaunchKernel with 0 arguments\n"); 24 | cudaError_t cudaError = cudaLaunchKernel((void*)dummy0, dim3(blocks), dim3(threads), args, 0, NULL); 25 | 26 | printf("cudaError:%d\n",cudaError); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /plugins/cudart/demo/launchKernel.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | __global__ 6 | void saxpy(int n, float a, float *x, float *y) 7 | { 8 | int i = blockIdx.x * blockDim.x + threadIdx.x; 9 | if (i < n) y[i] = a * x[i] + y[i]; 10 | } 11 | 12 | int main(void) 13 | { 14 | int N = 1 << 20; 15 | float *hx, *hy, *dx, *dy; 16 | hx = (float*)malloc(N * sizeof(float)); 17 | hy = (float*)malloc(N * sizeof(float)); 18 | 19 | cudaMalloc(&dx, N * sizeof(float)); 20 | cudaMalloc(&dy, N * sizeof(float)); 21 | 22 | for (int idx = 0; idx < N; idx++) 23 | { 24 | hx[idx] = 1.0f; 25 | hy[idx] = 2.0f; 26 | } 27 | 28 | cudaMemcpy(dx, hx, N * sizeof(float), cudaMemcpyHostToDevice); 29 | cudaMemcpy(dy, hy, N * sizeof(float), cudaMemcpyHostToDevice); 30 | 31 | unsigned int threads = 256; 32 | unsigned int blocks = (N + 255) / threads; 33 | 34 | float ratio = 2.0f; 35 | 36 | //saxpy<<>>(N, ratio, dx, dy); 37 | 38 | void *args[] = { &N, &ratio, &dx, &dy }; 39 | cudaLaunchKernel((void*)saxpy, dim3(blocks), dim3(threads), args, 0, NULL); 40 | 41 | cudaMemcpy(hy, dy, N * sizeof(float), cudaMemcpyDeviceToHost); 42 | 43 | float max_error = 0.0f; 44 | for (int jdx = 0; jdx < N; jdx++) 45 | { 46 | max_error = max(max_error, abs(hy[jdx] - 4.0f)); 47 | } 48 | 49 | printf("Max Error: %f\n", max_error); 50 | 51 | cudaFree(dx); 52 | cudaFree(dy); 53 | free(hx); 54 | free(hy); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /plugins/cudart/frontend/CudaRt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file CudaRt.cpp 28 | * @author Giuseppe Coviello 29 | * @date Fri Oct 9 15:55:40 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #include "CudaRt.h" -------------------------------------------------------------------------------- /plugins/cudart/frontend/CudaRt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file CudaRt.h 28 | * @author Giuseppe Coviello 29 | * @date Fri Oct 9 15:55:40 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #ifndef _CUDART_H 37 | #define _CUDART_H 38 | 39 | #include 40 | #include 41 | 42 | #include 43 | #include "CudaRtFrontend.h" 44 | 45 | #endif /* _CUDART_H */ 46 | -------------------------------------------------------------------------------- /plugins/cudart/frontend/CudaRtFrontend.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | 27 | #include "CudaRtFrontend.h" 28 | 29 | using namespace std; 30 | 31 | using gvirtus::common::mappedPointer; 32 | using gvirtus::common::pointer_t; 33 | 34 | extern "C" { 35 | void __cudaInitModule() {} 36 | } 37 | 38 | CudaRtFrontend msInstance __attribute_used__; 39 | 40 | map* CudaRtFrontend::mappedPointers = NULL; 41 | set* CudaRtFrontend::devicePointers = NULL; 42 | map*>* CudaRtFrontend::toManage = NULL; 43 | 44 | map* CudaRtFrontend::mapHost2DeviceFunc = NULL; 45 | map* CudaRtFrontend::mapDeviceFunc2InfoFunc = NULL; 46 | 47 | CudaRtFrontend::CudaRtFrontend() { 48 | if (devicePointers == NULL) devicePointers = new set(); 49 | if (mappedPointers == NULL) 50 | mappedPointers = new map(); 51 | 52 | if (mapHost2DeviceFunc == NULL) mapHost2DeviceFunc = new map(); 53 | if (mapDeviceFunc2InfoFunc == NULL) mapDeviceFunc2InfoFunc = new map(); 54 | 55 | if (toManage == NULL) toManage = new map*>(); 56 | gvirtus::frontend::Frontend::GetFrontend(); 57 | } 58 | 59 | // static CudaRtFrontend* CudaRtFrontend::GetFrontend(){ 60 | // return (CudaRtFrontend*) Frontend::GetFrontend(); 61 | //} 62 | -------------------------------------------------------------------------------- /plugins/cudart/frontend/CudaRt_error.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include "CudaRt.h" 27 | 28 | using namespace std; 29 | 30 | extern "C" __host__ const char* CUDARTAPI 31 | cudaGetErrorString(cudaError_t error) { 32 | CudaRtFrontend::Prepare(); 33 | CudaRtFrontend::AddVariableForArguments(error); 34 | CudaRtFrontend::Execute("cudaGetErrorString"); 35 | #ifdef _WIN32 36 | char* error_string = _strdup(CudaRtFrontend::GetOutputString()); 37 | #else 38 | char* error_string = strdup(CudaRtFrontend::GetOutputString()); 39 | #endif 40 | return error_string; 41 | } 42 | extern "C" __host__ cudaError_t CUDARTAPI cudaPeekAtLastError(void) { 43 | CudaRtFrontend::Prepare(); 44 | CudaRtFrontend::Execute("cudaPeekAtLastError"); 45 | return CudaRtFrontend::GetExitCode(); 46 | } 47 | 48 | extern "C" __host__ cudaError_t CUDARTAPI cudaGetLastError(void) { 49 | CudaRtFrontend::Prepare(); 50 | CudaRtFrontend::Execute("cudaGetLastError"); 51 | return CudaRtFrontend::GetExitCode(); 52 | } 53 | -------------------------------------------------------------------------------- /plugins/cudart/frontend/CudaRt_occupancy.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Raffaele Montella , 23 | * Department of Science and Technologies 24 | */ 25 | 26 | #include "CudaRt.h" 27 | using namespace std; 28 | 29 | using gvirtus::common::pointer_t; 30 | 31 | /* cudaOccupancyMaxActiveBlocksPerMultiprocessor */ 32 | extern "C" __host__ cudaError_t cudaOccupancyMaxActiveBlocksPerMultiprocessor( 33 | int* numBlocks, const void* func, int blockSize, size_t dynamicSMemSize) { 34 | CudaRtFrontend::Prepare(); 35 | CudaRtFrontend::AddHostPointerForArguments(numBlocks); 36 | CudaRtFrontend::AddVariableForArguments((pointer_t)func); 37 | CudaRtFrontend::AddVariableForArguments(blockSize); 38 | CudaRtFrontend::AddVariableForArguments(dynamicSMemSize); 39 | CudaRtFrontend::Execute("cudaOccupancyMaxActiveBlocksPerMultiprocessor"); 40 | 41 | if (CudaRtFrontend::Success()) 42 | *numBlocks = *(CudaRtFrontend::GetOutputHostPointer()); 43 | return CudaRtFrontend::GetExitCode(); 44 | } 45 | 46 | /* cudaOccupancyMaxActiveBlocksPerMultiprocessorWithFlags */ 47 | #if (CUDART_VERSION >= 7000) 48 | extern "C" __host__ cudaError_t 49 | cudaOccupancyMaxActiveBlocksPerMultiprocessorWithFlags(int* numBlocks, 50 | const void* func, 51 | int blockSize, 52 | size_t dynamicSMemSize, 53 | unsigned int flags) { 54 | CudaRtFrontend::Prepare(); 55 | CudaRtFrontend::AddHostPointerForArguments(numBlocks); 56 | CudaRtFrontend::AddVariableForArguments((pointer_t)func); 57 | CudaRtFrontend::AddVariableForArguments(blockSize); 58 | CudaRtFrontend::AddVariableForArguments(dynamicSMemSize); 59 | CudaRtFrontend::AddVariableForArguments(flags); 60 | CudaRtFrontend::Execute( 61 | "cudaOccupancyMaxActiveBlocksPerMultiprocessorWithFlags"); 62 | 63 | if (CudaRtFrontend::Success()) 64 | *numBlocks = *(CudaRtFrontend::GetOutputHostPointer()); 65 | return CudaRtFrontend::GetExitCode(); 66 | } 67 | #endif 68 | -------------------------------------------------------------------------------- /plugins/cudart/frontend/CudaRt_surface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Carlo Palmieri , 23 | * Department of Science and Technology 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include "CudaRt.h" 30 | 31 | using namespace std; 32 | 33 | extern "C" __host__ cudaError_t CUDARTAPI 34 | cudaBindSurfaceToArray(const surfaceReference *surfref, const cudaArray *array, 35 | const cudaChannelFormatDesc *desc) { 36 | CudaRtFrontend::Prepare(); 37 | 38 | // cerr << CudaUtil::MarshalHostPointer(surfref) << " " << hex << array << 39 | // endl; 40 | 41 | // Achtung: passing the address and the content of the textureReference 42 | CudaRtFrontend::AddStringForArguments(CudaUtil::MarshalHostPointer(surfref)); 43 | CudaRtFrontend::AddHostPointerForArguments(surfref); 44 | CudaRtFrontend::AddDevicePointerForArguments((void *)array); 45 | CudaRtFrontend::AddHostPointerForArguments(desc); 46 | CudaRtFrontend::Execute("cudaBindSurfaceToArray"); 47 | return CudaRtFrontend::GetExitCode(); 48 | } 49 | 50 | // extern "C" __host__ cudaError_t CUDARTAPI cudaGetTextureReference(const 51 | // textureReference **texref, 52 | // const void *symbol) { 53 | // CudaRtFrontend::Prepare(); 54 | // // Achtung: skipping to add texref 55 | // // Achtung: passing the address and the content of symbol 56 | // CudaRtFrontend::AddStringForArguments(CudaUtil::MarshalHostPointer(symbol)); 57 | // CudaRtFrontend::AddStringForArguments((char*)symbol); 58 | // CudaRtFrontend::Execute("cudaGetTextureReference"); 59 | // if (CudaRtFrontend::Success()) { 60 | // char *texrefHandler = CudaRtFrontend::GetOutputString(); 61 | // *texref = (textureReference *) strtoul(texrefHandler, NULL, 16); 62 | // } 63 | // return CudaRtFrontend::GetExitCode(); 64 | //} 65 | // 66 | -------------------------------------------------------------------------------- /plugins/cudart/frontend/CudaRt_thread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include "CudaRt.h" 27 | 28 | using namespace std; 29 | 30 | extern "C" __host__ cudaError_t CUDARTAPI cudaThreadSynchronize() { 31 | CudaRtFrontend::Prepare(); 32 | CudaRtFrontend::Execute("cudaThreadSynchronize"); 33 | return CudaRtFrontend::GetExitCode(); 34 | } 35 | 36 | extern "C" __host__ cudaError_t CUDARTAPI cudaThreadExit() { 37 | CudaRtFrontend::Prepare(); 38 | CudaRtFrontend::Execute("cudaThreadExit"); 39 | return CudaRtFrontend::GetExitCode(); 40 | } 41 | -------------------------------------------------------------------------------- /plugins/cudart/frontend/CudaRt_version.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include "CudaRt.h" 27 | 28 | using namespace std; 29 | 30 | extern "C" __host__ cudaError_t CUDARTAPI 31 | cudaDriverGetVersion(int *driverVersion) { 32 | CudaRtFrontend::Prepare(); 33 | CudaRtFrontend::AddHostPointerForArguments(driverVersion); 34 | CudaRtFrontend::Execute("cudaDriverGetVersion"); 35 | if (CudaRtFrontend::Success()) 36 | *driverVersion = *(CudaRtFrontend::GetOutputHostPointer()); 37 | return CudaRtFrontend::GetExitCode(); 38 | } 39 | 40 | extern "C" __host__ cudaError_t CUDARTAPI 41 | cudaRuntimeGetVersion(int *runtimeVersion) { 42 | CudaRtFrontend::Prepare(); 43 | CudaRtFrontend::AddHostPointerForArguments(runtimeVersion); 44 | CudaRtFrontend::Execute("cudaDriverGetVersion"); 45 | if (CudaRtFrontend::Success()) 46 | *runtimeVersion = *(CudaRtFrontend::GetOutputHostPointer()); 47 | return CudaRtFrontend::GetExitCode(); 48 | } 49 | -------------------------------------------------------------------------------- /plugins/cudnn/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.17) 2 | project(gvirtus-plugin-cudnn) 3 | 4 | find_package(CUDA REQUIRED) 5 | 6 | find_path(CUDNN_INCLUDE_DIRECTORY 7 | cudnn.h 8 | PATHS ${CUDA_INCLUDE_DIRS}) 9 | if(NOT CUDNN_INCLUDE_DIRECTORY) 10 | message(FATAL_ERROR "cudnn.h not found") 11 | endif() 12 | include_directories(${CUDNN_INCLUDE_DIRECTORY} ${CUDA_INCLUDE_DIRS}) 13 | 14 | get_filename_component(CUDA_LIBRARIES_PATH ${CUDA_CUDART_LIBRARY} DIRECTORY FALSE) 15 | find_library(CUDNN_LIBRARY 16 | cudnn 17 | PATHS ${CUDA_LIBRARIES_PATH}) 18 | if(NOT CUDNN_LIBRARY) 19 | message(FATAL_ERROR "cudnn library not found") 20 | endif() 21 | message(STATUS "Found cuDNN library: ${CUDNN_LIBRARY}") 22 | 23 | set(CUDNN_VERSION "${CUDNN_LIBRARY}") 24 | while(IS_SYMLINK "${CUDNN_VERSION}") 25 | message(STATUS "${CUDNN_VERSION}") 26 | execute_process(COMMAND readlink "${CUDNN_VERSION}" 27 | OUTPUT_VARIABLE CUDNN_VERSION 28 | OUTPUT_STRIP_TRAILING_WHITESPACE) 29 | endwhile() 30 | string(REGEX REPLACE ".*\\.so\\.([0-9]+\\.[0-9]+\\.[0-9]+)" "\\1" CUDNN_VERSION "${CUDNN_VERSION}") 31 | 32 | message(STATUS "Found cuDNN: ${CUDNN_VERSION} (${CUDNN_INCLUDE_DIRECTORY}/cudnn.h, ${CUDNN_LIBRARY})") 33 | 34 | gvirtus_add_backend(cudnn ${CUDNN_VERSION} 35 | backend/CudnnHandler.cpp) 36 | target_link_libraries(${PROJECT_NAME} ${CUDNN_LIBRARY}) 37 | 38 | gvirtus_add_frontend(cudnn ${CUDNN_VERSION} 39 | frontend/Cudnn.cpp 40 | frontend/Cudnn_helper.cpp 41 | frontend/CudnnFrontend.cpp) 42 | -------------------------------------------------------------------------------- /plugins/cudnn/frontend/CudnnFrontend.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include "CudnnFrontend.h" 27 | 28 | using namespace std; 29 | 30 | CudnnFrontend msInstance __attribute_used__; 31 | 32 | void * CudnnFrontend::handler = NULL; 33 | 34 | CudnnFrontend::CudnnFrontend() { 35 | Frontend::GetFrontend(); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /plugins/cudnn/frontend/Cudnn_helper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "CudnnFrontend.h" 31 | 32 | using namespace std; 33 | 34 | extern "C" cudnnStatus_t CUDNNWINAPI cudnnCreate (cudnnHandle_t *handle) { 35 | CudnnFrontend::Prepare(); 36 | //CudnnFrontend::AddHostPointerForArguments(handle); 37 | CudnnFrontend::Execute("cudnnCreate"); 38 | if(CudnnFrontend::Success()) 39 | *handle = *(CudnnFrontend::GetOutputHostPointer()); 40 | return CudnnFrontend::GetExitCode(); 41 | } 42 | 43 | extern "C" cudnnStatus_t CUDNNWINAPI cudnnDestroy (cudnnHandle_t handle) { 44 | CudnnFrontend::Prepare(); 45 | CudnnFrontend::AddDevicePointerForArguments(handle); 46 | CudnnFrontend::Execute("cudnnDestroy"); 47 | return CudnnFrontend::GetExitCode(); 48 | } 49 | extern "C" cudnnStatus_t CUDNNWINAPI cudnnSetStream (cudnnHandle_t handle, cudaStream_t streamId) { 50 | CudnnFrontend::Prepare(); 51 | CudnnFrontend::AddDevicePointerForArguments(handle); 52 | CudnnFrontend::AddDevicePointerForArguments(streamId); 53 | CudnnFrontend::Execute("cudnnSetStream"); 54 | return CudnnFrontend::GetExitCode(); 55 | } 56 | extern "C" cudnnStatus_t CUDNNWINAPI cudnnGetStream (cudnnHandle_t handle, cudaStream_t *streamId) { 57 | CudnnFrontend::Prepare(); 58 | CudnnFrontend::AddDevicePointerForArguments(handle); 59 | CudnnFrontend::Execute("cudnnGetStream"); 60 | return CudnnFrontend::GetExitCode(); 61 | } 62 | -------------------------------------------------------------------------------- /plugins/cufft/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.17) 2 | project(gvirtus-plugin-cufft) 3 | find_package(CUDA REQUIRED) 4 | 5 | find_path(CUFFT_INCLUDE_DIRECTORY 6 | cufft.h 7 | PATHS ${CUDA_INCLUDE_DIRS}) 8 | if(NOT CUFFT_INCLUDE_DIRECTORY) 9 | message(FATAL_ERROR "cufft.h not found") 10 | endif() 11 | include_directories(${CUFFT_INCLUDE_DIRECTORY} ${CUDA_INCLUDE_DIRS} util 3rdparty/include) 12 | 13 | get_filename_component(CUDA_LIBRARIES_PATH ${CUDA_CUDART_LIBRARY} DIRECTORY FALSE) 14 | find_library(CUFFT_LIBRARY 15 | cufft 16 | PATHS ${CUDA_LIBRARIES_PATH}) 17 | if(NOT CUFFT_LIBRARY) 18 | message(FATAL_ERROR "cufft library not found") 19 | endif() 20 | message(STATUS "Found cuFFT library: ${CUFFT_LIBRARY}") 21 | 22 | set(CUFFT_VERSION "${CUFFT_LIBRARY}") 23 | while(IS_SYMLINK "${CUFFT_VERSION}") 24 | message(STATUS "${CUFFT_VERSION}") 25 | execute_process(COMMAND readlink "${CUFFT_VERSION}" 26 | OUTPUT_VARIABLE CUFFT_VERSION 27 | OUTPUT_STRIP_TRAILING_WHITESPACE) 28 | endwhile() 29 | string(REGEX REPLACE ".*\\.so\\.([0-9]+\\.[0-9]+\\.[0-9]+)" "\\1" CUFFT_VERSION "${CUFFT_VERSION}") 30 | 31 | message(STATUS "Found cuFFT: ${CUFFT_VERSION} (${CUFFT_INCLUDE_DIRECTORY}/cufft.h, ${CUFFT_LIBRARY})") 32 | 33 | gvirtus_add_backend(cufft ${CUDA_VERSION} 34 | backend/CufftHandler.cpp) 35 | target_link_libraries(${PROJECT_NAME} ${CUDA_cublas_LIBRARY} ${CUDA_CUDART_LIBRARY}) 36 | 37 | gvirtus_add_frontend(cufft ${CUDA_VERSION} 38 | frontend/Cufft.cpp 39 | frontend/CufftFrontend.cpp) 40 | -------------------------------------------------------------------------------- /plugins/cufft/frontend/Cufft.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2011 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include 27 | #if ( __WORDSIZE == 64 ) 28 | #define BUILD_64 1 29 | #endif 30 | -------------------------------------------------------------------------------- /plugins/cufft/frontend/CufftFrontend.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file CufftFrontend.cpp 3 | * @author Vincenzo Santopietro 4 | * @date Jan 26, 2017, 10:01 AM 5 | * 6 | * @brief 7 | * 8 | */ 9 | 10 | #include "CufftFrontend.h" 11 | 12 | using namespace std; 13 | 14 | using gvirtus::frontend::Frontend; 15 | using gvirtus::common::mappedPointer; 16 | 17 | CufftFrontend msInstance __attribute_used__; 18 | 19 | map* CufftFrontend::mappedPointers = NULL; 20 | set* CufftFrontend::devicePointers = NULL; 21 | map *>* CufftFrontend::toManage = NULL; 22 | 23 | 24 | CufftFrontend::CufftFrontend() { 25 | if (devicePointers == NULL) 26 | devicePointers = new set(); 27 | if (mappedPointers == NULL) 28 | mappedPointers = new map(); 29 | if (toManage == NULL) 30 | toManage = new map *>(); 31 | Frontend::GetFrontend(); 32 | } 33 | 34 | 35 | CufftFrontend::~CufftFrontend() { 36 | } 37 | 38 | -------------------------------------------------------------------------------- /plugins/curand/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.17) 2 | project(gvirtus-plugin-curand) 3 | find_package(CUDA REQUIRED) 4 | 5 | include_directories(${CUDA_INCLUDE_DIRS}) 6 | 7 | gvirtus_add_backend(curand ${CUDA_VERSION} 8 | backend/CurandHandler.cpp) 9 | target_link_libraries(${PROJECT_NAME} ${CUDA_curand_LIBRARY} ${CUDA_CUDART_LIBRARY}) 10 | 11 | gvirtus_add_frontend(curand ${CUDA_VERSION} 12 | frontend/Curand.cpp 13 | frontend/CurandFrontend.cpp) 14 | -------------------------------------------------------------------------------- /plugins/curand/backend/CurandHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | #include "CurandHandler.h" 24 | #include "CurandHandler_host.cpp" 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | 31 | using namespace std; 32 | using namespace log4cplus; 33 | 34 | std::map * CurandHandler::mspHandlers = NULL; 35 | 36 | extern "C" std::shared_ptr create_t() { 37 | return std::make_shared(); 38 | } 39 | 40 | CurandHandler::CurandHandler() { 41 | logger=Logger::getInstance(LOG4CPLUS_TEXT("CurandHandler")); 42 | Initialize(); 43 | } 44 | 45 | CurandHandler::~CurandHandler() { 46 | } 47 | 48 | bool CurandHandler::CanExecute(std::string routine) { 49 | return mspHandlers->find(routine) != mspHandlers->end(); 50 | } 51 | 52 | std::shared_ptr CurandHandler::Execute(std::string routine, std::shared_ptr in) { 53 | LOG4CPLUS_DEBUG(logger,"Called " << routine); 54 | map::iterator it; 55 | it = mspHandlers->find(routine); 56 | if (it == mspHandlers->end()) 57 | throw "No handler for '" + routine + "' found!"; 58 | try { 59 | return it->second(this, in); 60 | } catch (const char *ex) { 61 | cout << ex << endl; 62 | cout << strerror(errno) << endl; 63 | } 64 | return NULL; 65 | } 66 | 67 | 68 | void CurandHandler::Initialize() { 69 | if (mspHandlers != NULL) 70 | return; 71 | mspHandlers = new map (); 72 | 73 | /* CurandHandler Query Platform Info */ 74 | mspHandlers->insert(CURAND_ROUTINE_HANDLER_PAIR(CreateGenerator)); 75 | mspHandlers->insert(CURAND_ROUTINE_HANDLER_PAIR(CreateGeneratorHost)); 76 | mspHandlers->insert(CURAND_ROUTINE_HANDLER_PAIR(Generate)); 77 | mspHandlers->insert(CURAND_ROUTINE_HANDLER_PAIR(GenerateLongLong)); 78 | mspHandlers->insert(CURAND_ROUTINE_HANDLER_PAIR(GenerateUniform)); 79 | mspHandlers->insert(CURAND_ROUTINE_HANDLER_PAIR(GenerateNormal)); 80 | mspHandlers->insert(CURAND_ROUTINE_HANDLER_PAIR(GenerateLogNormal)); 81 | mspHandlers->insert(CURAND_ROUTINE_HANDLER_PAIR(GeneratePoisson)); 82 | mspHandlers->insert(CURAND_ROUTINE_HANDLER_PAIR(GenerateUniformDouble)); 83 | mspHandlers->insert(CURAND_ROUTINE_HANDLER_PAIR(GenerateNormalDouble)); 84 | mspHandlers->insert(CURAND_ROUTINE_HANDLER_PAIR(GenerateLogNormalDouble)); 85 | mspHandlers->insert(CURAND_ROUTINE_HANDLER_PAIR(SetPseudoRandomGeneratorSeed)); 86 | } 87 | -------------------------------------------------------------------------------- /plugins/curand/backend/CurandHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Vincenzo Santopietro , 23 | * Department of Science and Technologies 24 | */ 25 | 26 | #ifndef _CURANDHANDLER_H 27 | #define _CURANDHANDLER_H 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | #include "log4cplus/logger.h" 35 | #include "log4cplus/loggingmacros.h" 36 | #include "log4cplus/configurator.h" 37 | 38 | class CurandHandler : public gvirtus::backend::Handler { 39 | public: 40 | CurandHandler(); 41 | virtual ~CurandHandler(); 42 | bool CanExecute(std::string routine); 43 | std::shared_ptr Execute(std::string routine, 44 | std::shared_ptr input_buffer); 45 | 46 | /*void * RegisterPointer(void *,size_t); 47 | 48 | void RegisterMapObject(char *,char *); 49 | char * GetMapObject(char *); 50 | */ 51 | private: 52 | log4cplus::Logger logger; 53 | void Initialize(); 54 | typedef std::shared_ptr (*CurandRoutineHandler)(CurandHandler *, 55 | std::shared_ptr); 56 | static std::map * mspHandlers; 57 | //void **pointers; 58 | //int nPointers; 59 | 60 | //std::map * mpMapObject; 61 | 62 | //void *mpShm; 63 | //int mShmFd; 64 | }; 65 | 66 | #define CURAND_ROUTINE_HANDLER(name) std::shared_ptr handle##name(CurandHandler * pThis, std::shared_ptr in) 67 | #define CURAND_ROUTINE_HANDLER_PAIR(name) make_pair("curand" #name, handle##name) 68 | 69 | /* CudnnHandler_Platform */ 70 | CURAND_ROUTINE_HANDLER(CreateGenerator); 71 | CURAND_ROUTINE_HANDLER(CreateGeneratorHost); 72 | CURAND_ROUTINE_HANDLER(Generate); 73 | CURAND_ROUTINE_HANDLER(GenerateLongLong); 74 | CURAND_ROUTINE_HANDLER(GenerateUniform); 75 | CURAND_ROUTINE_HANDLER(GenerateNormal); 76 | CURAND_ROUTINE_HANDLER(GenerateLogNormal); 77 | CURAND_ROUTINE_HANDLER(GeneratePoisson); 78 | CURAND_ROUTINE_HANDLER(GenerateUniformDouble); 79 | CURAND_ROUTINE_HANDLER(GenerateNormalDouble); 80 | CURAND_ROUTINE_HANDLER(GenerateLogNormalDouble); 81 | CURAND_ROUTINE_HANDLER(SetPseudoRandomGeneratorSeed); 82 | 83 | #endif //_CURANDHANDLER_H 84 | 85 | -------------------------------------------------------------------------------- /plugins/curand/frontend/CurandFrontend.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include "CurandFrontend.h" 27 | 28 | using namespace std; 29 | 30 | CurandFrontend msInstance __attribute_used__; 31 | void * CurandFrontend::handler = NULL; 32 | 33 | using gvirtus::frontend::Frontend; 34 | 35 | CurandFrontend::CurandFrontend() { 36 | Frontend::GetFrontend(); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /plugins/cusolver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.17) 2 | project(gvirtus-plugin-cusolver) 3 | find_package(CUDA REQUIRED) 4 | 5 | find_path(CUSOLVER_INCLUDE_DIRECTORY 6 | cusolverDn.h 7 | PATHS ${CUDA_INCLUDE_DIRS}) 8 | if(NOT CUSOLVER_INCLUDE_DIRECTORY) 9 | message(FATAL_ERROR "cusolverDn.h not found") 10 | endif() 11 | include_directories(${CUSOLVER_INCLUDE_DIRECTORY} ${CUDA_INCLUDE_DIRS}) 12 | 13 | get_filename_component(CUDA_LIBRARIES_PATH ${CUDA_CUDART_LIBRARY} DIRECTORY FALSE) 14 | find_library(CUSOLVER_LIBRARY 15 | cusolver 16 | PATHS ${CUDA_LIBRARIES_PATH}) 17 | if(NOT CUSOLVER_LIBRARY) 18 | message(FATAL_ERROR "cusolver library not found") 19 | endif() 20 | message(STATUS "Found cuSolver library: ${CUSOLVER_LIBRARY}") 21 | 22 | set(CUSOLVER_VERSION "${CUSOLVER_LIBRARY}") 23 | while(IS_SYMLINK "${CUSOLVER_VERSION}") 24 | message(STATUS "${CUSOLVER_VERSION}") 25 | execute_process(COMMAND readlink "${CUSOLVER_VERSION}" 26 | OUTPUT_VARIABLE CUSOLVER_VERSION 27 | OUTPUT_STRIP_TRAILING_WHITESPACE) 28 | endwhile() 29 | string(REGEX REPLACE ".*\\.so\\.([0-9]+\\.[0-9]+\\.[0-9]+)" "\\1" CUSOLVER_VERSION "${CUSOLVER_VERSION}") 30 | 31 | message(STATUS "Found cuSolver: ${CUSOLVER_VERSION} (${CUSOLVER_INCLUDE_DIRECTORY}/cusolverDn.h, ${CUSOLVER_LIBRARY})") 32 | 33 | gvirtus_add_backend(cusolver ${CUDA_VERSION} 34 | backend/CusolverHandler.cpp 35 | ) 36 | target_link_libraries(${PROJECT_NAME} ${CUDA_cusolver_LIBRARY} ${CUDA_CUDART_LIBRARY}) 37 | 38 | gvirtus_add_frontend(cusolver ${CUDA_VERSION} 39 | frontend/Cusolver.cpp 40 | frontend/CusolverFrontend.cpp 41 | frontend/Cusolver_helper.cpp 42 | ) 43 | -------------------------------------------------------------------------------- /plugins/cusolver/backend/CusolverHandler.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * gVirtuS -- A GPGPU transparent virtualization component. 4 | * 5 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 6 | * 7 | * This file is part of gVirtuS. 8 | * 9 | * gVirtuS is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * gVirtuS is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with gVirtuS; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | * Written by: Antonio Pilato , 24 | * Department of Science and Technologies 25 | */ 26 | 27 | #ifndef CUSOLVERHANDLER_H 28 | #define CUSOLVERHANDLER_H 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | using gvirtus::common::pointer_t; 36 | using gvirtus::communicators::Buffer; 37 | using gvirtus::communicators::Result; 38 | 39 | #include "log4cplus/logger.h" 40 | #include "log4cplus/loggingmacros.h" 41 | #include "log4cplus/configurator.h" 42 | 43 | #include 44 | #if ( __WORDSIZE == 64 ) 45 | #define BUILD_64 1 46 | #endif 47 | 48 | using namespace std; 49 | using namespace log4cplus; 50 | 51 | class CusolverHandler : public gvirtus::backend::Handler { 52 | public: 53 | CusolverHandler(); 54 | virtual ~CusolverHandler(); 55 | bool CanExecute(std::string routine); 56 | std::shared_ptr Execute(std::string routine, std::shared_ptr input_buffer); 57 | static void setLogLevel(Logger *logger); 58 | private: 59 | log4cplus::Logger logger; 60 | void Initialize(); 61 | typedef std::shared_ptr (*CusolverRoutineHandler)(CusolverHandler *, std::shared_ptr); 62 | static std::map * mspHandlers; 63 | }; 64 | 65 | #define CUSOLVER_ROUTINE_HANDLER(name) std::shared_ptr handle##name(CusolverHandler * pThis, std::shared_ptr in) 66 | #define CUSOLVER_ROUTINE_HANDLER_PAIR(name) make_pair("cusolver" #name, handle##name) 67 | 68 | CUSOLVER_ROUTINE_HANDLER(GetVersion); 69 | CUSOLVER_ROUTINE_HANDLER(GetErrorString); 70 | CUSOLVER_ROUTINE_HANDLER(Create); 71 | CUSOLVER_ROUTINE_HANDLER(Destroy); 72 | CUSOLVER_ROUTINE_HANDLER(SetStream); 73 | CUSOLVER_ROUTINE_HANDLER(GetStream); 74 | 75 | #endif /* CUSOLVERHANDLER_H */ 76 | -------------------------------------------------------------------------------- /plugins/cusolver/frontend/Cusolver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "CusolverFrontend.h" 31 | 32 | using namespace std; 33 | 34 | 35 | size_t CUSOLVERAPI cusolverDnGetVersion(){ 36 | CusolverFrontend::Prepare(); 37 | 38 | CusolverFrontend::Execute("cusolverDnGetVersion"); 39 | return CusolverFrontend::GetExitCode(); 40 | } 41 | 42 | extern "C" const char * CUSOLVERAPI cusolverDnGetErrorString(cusolverStatus_t status){ 43 | CusolverFrontend::Prepare(); 44 | 45 | CusolverFrontend::AddVariableForArguments(status); 46 | CusolverFrontend::Execute("cusolverDnGetErrorString"); 47 | return (const char *) CusolverFrontend::GetOutputHostPointer(); 48 | } 49 | 50 | extern "C" cusolverStatus_t CUSOLVERAPI cusolverDnCreate(cusolverDnHandle_t *handle){ 51 | CusolverFrontend::Prepare(); 52 | CusolverFrontend::AddHostPointerForArguments(handle); 53 | CusolverFrontend::Execute("cusolverDnCreate"); 54 | if(CusolverFrontend::Success()) 55 | *handle = CusolverFrontend::GetOutputVariable(); 56 | return CusolverFrontend::GetExitCode(); 57 | } 58 | 59 | extern "C" cusolverStatus_t CUSOLVERAPI cusolverDnDestroy(cusolverDnHandle_t handle){ 60 | CusolverFrontend::Prepare(); 61 | 62 | CusolverFrontend::AddVariableForArguments((long long int)handle); 63 | CusolverFrontend::Execute("cusolverDnDestroy"); 64 | return CusolverFrontend::GetExitCode(); 65 | } 66 | 67 | extern "C" cusolverStatus_t CUSOLVERAPI cusolverDnSetStream(cusolverDnHandle_t handle, cudaStream_t streamId){ 68 | CusolverFrontend::Prepare(); 69 | 70 | CusolverFrontend::AddVariableForArguments((long long int)handle); 71 | CusolverFrontend::AddVariableForArguments((long long int)streamId); 72 | CusolverFrontend::Execute("cusolverSetStream"); 73 | return CusolverFrontend::GetExitCode(); 74 | } 75 | 76 | extern "C" cusolverStatus_t CUSOLVERAPI cusolverDnGetStream(cusolverDnHandle_t handle, cudaStream_t *streamId){ 77 | CusolverFrontend::Prepare(); 78 | 79 | CusolverFrontend::AddVariableForArguments((long long int)handle); 80 | CusolverFrontend::Execute("cusolverDnGetStream"); 81 | if(CusolverFrontend::Success()) 82 | *streamId = (cudaStream_t) CusolverFrontend::GetOutputVariable(); 83 | return CusolverFrontend::GetExitCode(); 84 | } 85 | -------------------------------------------------------------------------------- /plugins/cusolver/frontend/CusolverFrontend.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Antonio Pilato , 23 | * Department of Science and Technology 24 | */ 25 | 26 | #include "CusolverFrontend.h" 27 | 28 | using namespace std; 29 | 30 | CusolverFrontend msInstance __attribute_used__; 31 | 32 | void * CusolverFrontend::handler = NULL; 33 | 34 | CusolverFrontend::CusolverFrontend() { 35 | Frontend::GetFrontend(); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /plugins/cusolver/frontend/Cusolver_helper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Antonio Pilato , 23 | * Department of Science andTechnology 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "CusolverFrontend.h" 31 | 32 | using namespace std; 33 | 34 | extern "C" cusolverStatus_t CUSOLVERAPI cusolverDnCreate(cusolverDnHandle_t *handle) { 35 | CusolverFrontend::Prepare(); 36 | //CusolverFrontend::AddHostPointerForArguments(handle); 37 | CusolverFrontend::Execute("cusolverDnCreate"); 38 | if(CusolverFrontend::Success()) 39 | *handle = *(CusolverFrontend::GetOutputHostPointer()); 40 | return CusolverFrontend::GetExitCode(); 41 | } 42 | 43 | extern "C" cusolverStatus_t CUSOLVERAPI cuSolverDnDestroy(cusolverDnHandle_t handle) { 44 | CusolverFrontend::Prepare(); 45 | CusolverFrontend::AddVariableForArguments(handle); 46 | CusolverFrontend::Execute("cusolverDnDestroy"); 47 | return CusolverFrontend::GetExitCode(); 48 | } 49 | extern "C" cusolverStatus_t CUSOLVERAPI cusolverDnSetStream(cusolverDnHandle_t handle, cudaStream_t streamId) { 50 | CusolverFrontend::Prepare(); 51 | CusolverFrontend::AddVariableForArguments(handle); 52 | CusolverFrontend::AddVariableForArguments(streamId); 53 | CusolverFrontend::Execute("cusolverDnSetStream"); 54 | return CusolverFrontend::GetExitCode(); 55 | } 56 | extern "C" cusolverStatus_t CUSOLVERAPI cusolverDnGetStream(cusolverDnHandle_t handle, cudaStream_t *streamId) { 57 | CusolverFrontend::Prepare(); 58 | CusolverFrontend::AddVariableForArguments(handle); 59 | CusolverFrontend::Execute("cusolverDnGetStream"); 60 | return CusolverFrontend::GetExitCode(); 61 | } 62 | -------------------------------------------------------------------------------- /plugins/cusparse/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.17) 2 | project(gvirtus-plugin-cusparse) 3 | find_package(CUDA REQUIRED) 4 | 5 | find_path(CUSPARSE_INCLUDE_DIRECTORY 6 | cusparse.h 7 | PATHS ${CUDA_INCLUDE_DIRS}) 8 | if(NOT CUSPARSE_INCLUDE_DIRECTORY) 9 | message(FATAL_ERROR "cusparse.h not found") 10 | endif() 11 | include_directories(${CUSPARSE_INCLUDE_DIRECTORY} ${CUDA_INCLUDE_DIRS}) 12 | 13 | get_filename_component(CUDA_LIBRARIES_PATH ${CUDA_CUDART_LIBRARY} DIRECTORY FALSE) 14 | find_library(CUSPARSE_LIBRARY 15 | cusparse 16 | PATHS ${CUDA_LIBRARIES_PATH}) 17 | if(NOT CUSPARSE_LIBRARY) 18 | message(FATAL_ERROR "cusparse library not found") 19 | endif() 20 | message(STATUS "Found cuSparse library: ${CUSPARSE_LIBRARY}") 21 | 22 | set(CUSPARSE_VERSION "${CUSPARSE_LIBRARY}") 23 | while(IS_SYMLINK "${CUSPARSE_VERSION}") 24 | message(STATUS "${CUSPARSE_VERSION}") 25 | execute_process(COMMAND readlink "${CUSPARSE_VERSION}" 26 | OUTPUT_VARIABLE CUSPARSE_VERSION 27 | OUTPUT_STRIP_TRAILING_WHITESPACE) 28 | endwhile() 29 | string(REGEX REPLACE ".*\\.so\\.([0-9]+\\.[0-9]+\\.[0-9]+)" "\\1" CUSPARSE_VERSION "${CUSPARSE_VERSION}") 30 | 31 | message(STATUS "Found cuSparse: ${CUSPARSE_VERSION} (${CUSPARSE_INCLUDE_DIRECTORY}/cusparse.h, ${CUSPARSE_LIBRARY})") 32 | include_directories(${CUDA_INCLUDE_DIRS}) 33 | 34 | gvirtus_add_backend(cusparse ${CUDA_VERSION} 35 | backend/CusparseHandler.cpp) 36 | target_link_libraries(${PROJECT_NAME} ${CUDA_cusparse_LIBRARY} ${CUDA_CUDART_LIBRARY}) 37 | 38 | gvirtus_add_frontend(cusparse ${CUDA_VERSION} 39 | frontend/Cusparse.cpp 40 | frontend/Cusparse_helper.cpp 41 | frontend/CusparseFrontend.cpp 42 | ) 43 | -------------------------------------------------------------------------------- /plugins/cusparse/backend/CusparseHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Antonio Pilato , 23 | * Department of Science and Technologies 24 | */ 25 | 26 | #ifndef CUSPARSEHANDLER_H 27 | #define CUSPARSEHANDLER_H 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | #include "log4cplus/logger.h" 35 | #include "log4cplus/loggingmacros.h" 36 | #include "log4cplus/configurator.h" 37 | 38 | #include 39 | #if ( __WORDSIZE == 64 ) 40 | #define BUILD_64 1 41 | #endif 42 | using namespace std; 43 | using namespace log4cplus; 44 | 45 | class CusparseHandler : public Handler { 46 | public: 47 | CusparseHandler(); 48 | virtual ~CusparseHandler(); 49 | bool CanExecute(std::string routine); 50 | std::shared_ptr Execute(std::string routine, std::shared_ptr input_buffer); 51 | static void setLogLevel(Logger *logger); 52 | private: 53 | log4cplus::Logger logger; 54 | void Initialize(); 55 | typedef std::shared_ptr (*CusparseRoutineHandler)(CusparseHandler *, std::shared_ptr); 56 | static std::map * mspHandlers; 57 | }; 58 | 59 | #define CUSPARSE_ROUTINE_HANDLER(name) std::shared_ptr handle##name(CusparseHandler * pThis, std::shared_ptr in) 60 | #define CUSPARSE_ROUTINE_HANDLER_PAIR(name) make_pair("cusparse" #name, handle##name) 61 | 62 | CUSPARSE_ROUTINE_HANDLER(GetVersion); 63 | CUSPARSE_ROUTINE_HANDLER(GetErrorString); 64 | CUSPARSE_ROUTINE_HANDLER(Create); 65 | CUSPARSE_ROUTINE_HANDLER(Destroy); 66 | CUSPARSE_ROUTINE_HANDLER(SetStream); 67 | CUSPARSE_ROUTINE_HANDLER(GetStream); 68 | 69 | #endif /* CUSPARSEHANDLER_H */ 70 | -------------------------------------------------------------------------------- /plugins/cusparse/frontend/Cusparse.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * * gVirtuS -- A GPGPU transparent virtualization component. 3 | * * 4 | * * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * * 6 | * * This file is part of gVirtuS. 7 | * * 8 | * * gVirtuS is free software; you can redistribute it and/or modify 9 | * * it under the terms of the GNU General Public License as published by 10 | * * the Free Software Foundation; either version 2 of the License, or 11 | * * (at your option) any later version. 12 | * * 13 | * * gVirtuS is distributed in the hope that it will be useful, 14 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * * GNU Lesser General Public License for more details. 17 | * * 18 | * * You should have received a copy of the GNU General Public License 19 | * * along with gVirtuS; if not, write to the Free Software 20 | * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * * 22 | * * Written by: Antonio Pilato , 23 | * * Department of Science and Technologies 24 | * */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "CusparseFrontend.h" 31 | 32 | using namespace std; 33 | 34 | extern "C" cusparseStatus_t cusparseGetVersion(cusparseHandle_t handle, int* version){ 35 | CusparseFrontend::Prepare(); 36 | CusparseFrontend::AddHostPointerForArguments(handle); 37 | CusparseFrontend::AddHostPointerForArguments(version); 38 | CusparseFrontend::Execute("cusparseGetVersion"); 39 | return CusparseFrontend::GetExitCode(); 40 | } 41 | 42 | extern "C" const char *cusparseGetErrorString(cusparseStatus_t status){ 43 | CusparseFrontend::Prepare(); 44 | 45 | CusparseFrontend::AddVariableForArguments(status); 46 | CusparseFrontend::Execute("cusparseGetErrorString"); 47 | return (const char *) CusparseFrontend::GetOutputHostPointer(); 48 | } 49 | 50 | /* 51 | extern "C" cusparseStatus_t CUSPARSEAPI cusparseCreate(cusparseHandle_t *handle){ 52 | CusparseFrontend::Prepare(); 53 | CusparseFrontend::AddHostPointerForArguments(handle); 54 | CusparseFrontend::Execute("cusparseCreate"); 55 | if(CusparseFrontend::Success()) 56 | *handle = CusparseFrontend::GetOutputVariable(); 57 | return CusparseFrontend::GetExitCode(); 58 | } 59 | 60 | extern "C" cusparseStatus_t CUSPARSEAPI cusparseDestroy(cusparseHandle_t handle){ 61 | CusparseFrontend::Prepare(); 62 | 63 | CusparseFrontend::AddVariableForArguments((long long int)handle); 64 | CusparseFrontend::Execute("cusparseDestroy"); 65 | return CusparseFrontend::GetExitCode(); 66 | } 67 | 68 | extern "C" cusparseStatus_t CUSPARSEAPI cusparseSetStream(cusparseHandle_t handle, cudaStream_t streamId){ 69 | CusparseFrontend::Prepare(); 70 | 71 | CusparseFrontend::AddVariableForArguments((long long int)handle); 72 | CusparseFrontend::AddVariableForArguments((long long int)streamId); 73 | CusparseFrontend::Execute("cusparseSetStream"); 74 | return CusparseFrontend::GetExitCode(); 75 | } 76 | 77 | extern "C" cusparseStatus_t CUSPARSEAPI cusparseGetStream(cusparseHandle_t handle, cudaStream_t *streamId){ 78 | CusparseFrontend::Prepare(); 79 | 80 | CusparseFrontend::AddVariableForArguments((long long int)handle); 81 | CusparseFrontend::Execute("cusparseGetStream"); 82 | if(CusparseFrontend::Success()) 83 | *streamId = (cudaStream_t) CusparseFrontend::GetOutputVariable(); 84 | return CusparseFrontend::GetExitCode(); 85 | } 86 | */ -------------------------------------------------------------------------------- /plugins/cusparse/frontend/CusparseFrontend.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * * gVirtuS -- A GPGPU transparent virtualization component. 3 | * * 4 | * * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * * 6 | * * This file is part of gVirtuS. 7 | * * 8 | * * gVirtuS is free software; you can redistribute it and/or modify 9 | * * it under the terms of the GNU General Public License as published by 10 | * * the Free Software Foundation; either version 2 of the License, or 11 | * * (at your option) any later version. 12 | * * 13 | * * gVirtuS is distributed in the hope that it will be useful, 14 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * * GNU Lesser General Public License for more details. 17 | * * 18 | * * You should have received a copy of the GNU General Public License 19 | * * along with gVirtuS; if not, write to the Free Software 20 | * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * * 22 | * * Written by: Giuseppe Coviello , 23 | * * Department of Applied Science 24 | * */ 25 | 26 | #include "CusparseFrontend.h" 27 | 28 | using namespace std; 29 | 30 | CusparseFrontend msInstance __attribute_used__; 31 | 32 | void * CusparseFrontend::handler = NULL; 33 | 34 | CusparseFrontend::CusparseFrontend() { 35 | Frontend::GetFrontend(); 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /plugins/cusparse/frontend/Cusparse_helper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * * gVirtuS -- A GPGPU transparent virtualization component. 3 | * * 4 | * * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * * 6 | * * This file is part of gVirtuS. 7 | * * 8 | * * gVirtuS is free software; you can redistribute it and/or modify 9 | * * it under the terms of the GNU General Public License as published by 10 | * * the Free Software Foundation; either version 2 of the License, or 11 | * * (at your option) any later version. 12 | * * 13 | * * gVirtuS is distributed in the hope that it will be useful, 14 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * * GNU Lesser General Public License for more details. 17 | * * 18 | * * You should have received a copy of the GNU General Public License 19 | * * along with gVirtuS; if not, write to the Free Software 20 | * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * * 22 | * * Written by: Giuseppe Coviello , 23 | * * Department of Applied Science 24 | * */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "CusparseFrontend.h" 31 | 32 | using namespace std; 33 | 34 | extern "C" cusparseStatus_t cusparseCreate(cusparseHandle_t *handle) { 35 | CusparseFrontend::Prepare(); 36 | CusparseFrontend::Execute("cusparseCreate"); 37 | if(CusparseFrontend::Success()) 38 | *handle = *(CusparseFrontend::GetOutputHostPointer()); 39 | return CusparseFrontend::GetExitCode(); 40 | } 41 | 42 | extern "C" cusparseStatus_t cusparseDestroy(cusparseHandle_t handle) { 43 | CusparseFrontend::Prepare(); 44 | CusparseFrontend::AddVariableForArguments(handle); 45 | CusparseFrontend::Execute("cusparseDestroy"); 46 | return CusparseFrontend::GetExitCode(); 47 | } 48 | extern "C" cusparseStatus_t cusparseSetStream(cusparseHandle_t handle, cudaStream_t streamId) { 49 | CusparseFrontend::Prepare(); 50 | CusparseFrontend::AddVariableForArguments(handle); 51 | CusparseFrontend::AddVariableForArguments(streamId); 52 | CusparseFrontend::Execute("cusparseSetStream"); 53 | return CusparseFrontend::GetExitCode(); 54 | } 55 | extern "C" cusparseStatus_t cusparseGetStream(cusparseHandle_t handle, cudaStream_t *streamId) { 56 | CusparseFrontend::Prepare(); 57 | CusparseFrontend::AddVariableForArguments(handle); 58 | CusparseFrontend::Execute("cusparseGetStream"); 59 | return CusparseFrontend::GetExitCode(); 60 | } 61 | 62 | -------------------------------------------------------------------------------- /src/backend/Property.cpp: -------------------------------------------------------------------------------- 1 | #include "gvirtus/backend/Property.h" 2 | #include 3 | 4 | using gvirtus::backend::Property; 5 | 6 | Property &Property::endpoints(const int endpoints) { 7 | this->_endpoints = endpoints; 8 | return *this; 9 | } 10 | 11 | Property &Property::plugins(const std::vector &plugins) { 12 | _plugins.emplace_back(plugins); 13 | return *this; 14 | } 15 | 16 | Property &Property::secure(bool secure) { 17 | _secure = secure; 18 | return *this; 19 | } 20 | -------------------------------------------------------------------------------- /src/backend/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @mainpage gVirtuS - A GPGPU transparent virtualization component 3 | * 4 | * @section Introduction 5 | * gVirtuS tries to fill the gap between in-house hosted computing clusters, 6 | * equipped with GPGPUs devices, and pay-for-use high performance virtual 7 | * clusters deployed via public or private computing clouds. gVirtuS allows an 8 | * instanced virtual machine to access GPGPUs in a transparent way, with an 9 | * overhead slightly greater than a real machine/GPGPU setup. gVirtuS is 10 | * hypervisor independent, and, even though it currently virtualizes nVIDIA CUDA 11 | * based GPUs, it is not limited to a specific brand technology. The performance 12 | * of the components of gVirtuS is assessed through a suite of tests in 13 | * different deployment scenarios, such as providing GPGPU power to cloud 14 | * computing based HPC clusters and sharing remotely hosted GPGPUs among HPC 15 | * nodes. 16 | */ 17 | 18 | #include /* getenv */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "gvirtus/backend/Backend.h" 26 | #include "gvirtus/backend/Property.h" 27 | 28 | #include "log4cplus/configurator.h" 29 | #include "log4cplus/logger.h" 30 | #include "log4cplus/loggingmacros.h" 31 | 32 | log4cplus::Logger logger; 33 | 34 | std::string getEnvVar(std::string const & key) { 35 | char * env_var = getenv(key.c_str()); 36 | return (env_var == nullptr) ? std::string("") : std::string(env_var); 37 | } 38 | 39 | void loggerConfig() { 40 | // Logger configuration 41 | log4cplus::BasicConfigurator basicConfigurator; 42 | basicConfigurator.configure(); 43 | logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("GVirtuS")); 44 | 45 | // Set the logging level 46 | std::string logLevelString = getEnvVar("GVIRTUS_LOGLEVEL"); 47 | log4cplus::LogLevel logLevel = logLevelString.empty() ? log4cplus::INFO_LOG_LEVEL : std::stoi(logLevelString); 48 | 49 | logger.setLogLevel(logLevel); 50 | } 51 | 52 | int main(int argc, char **argv) { 53 | loggerConfig(); 54 | 55 | LOG4CPLUS_INFO(logger, "🛈 - GVirtuS backend: 0.0.12 version"); 56 | 57 | std::string config_path; 58 | #ifdef _CONFIG_FILE_JSON 59 | config_path = _CONFIG_FILE_JSON; 60 | #endif 61 | config_path = (argc == 2) ? std::string(argv[1]) : std::string(""); 62 | 63 | LOG4CPLUS_INFO(logger, "🛈 - Configuration: " << config_path); 64 | 65 | // FIXME: Try - Catch? No. 66 | try { 67 | gvirtus::backend::Backend backend(config_path); 68 | 69 | LOG4CPLUS_INFO(logger, "🛈 - [Process " << getpid() << "] Up and running!"); 70 | backend.Start(); 71 | } 72 | catch (std::string & exc) { 73 | LOG4CPLUS_ERROR(logger, "✖ - Exception:" << exc); 74 | } 75 | catch (const char * exc) { 76 | LOG4CPLUS_ERROR(logger, "✖ - Exception:" << exc); 77 | } 78 | 79 | LOG4CPLUS_INFO(logger, "🛈 - [Process " << getpid() << "] Shutdown"); 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /src/common/Encoder.cpp: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * @file Encoder.cpp 4 | * @author Raffaele Montella 5 | * @date Wed Nov 30 17:16:48 2016 6 | * 7 | * @brief 8 | * 9 | * 10 | */ 11 | 12 | #include "gvirtus/common/Encoder.h" 13 | 14 | #include 15 | #include 16 | 17 | using namespace std; 18 | using gvirtus::common::Encoder; 19 | 20 | Encoder::Encoder() { 21 | CHARS_PER_LINE = 72; 22 | step = step_A; 23 | result = 0; 24 | stepcount = 0; 25 | } 26 | 27 | Encoder::Encoder(const Encoder &orig) {} 28 | 29 | Encoder::~Encoder() {} 30 | 31 | int Encoder::Encode(char value_in) { return Value(value_in); } 32 | 33 | int Encoder::Encode(const char *code_in, const int length_in, 34 | char *plaintext_out) { 35 | return Block(code_in, length_in, plaintext_out); 36 | } 37 | 38 | int Encoder::EncodeEnd(char *plaintext_out) { return BlockEnd(plaintext_out); } 39 | 40 | int Encoder::Value(char value_in) { 41 | static const char *encoding = 42 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 43 | if (value_in > 63) return '='; 44 | return encoding[(int)value_in]; 45 | } 46 | 47 | int Encoder::Block(const char *plaintext_in, int length_in, char *code_out) { 48 | const char *plainchar = plaintext_in; 49 | const char *const plaintextend = plaintext_in + length_in; 50 | char *codechar = code_out; 51 | char result; 52 | char fragment; 53 | 54 | result = this->result; 55 | 56 | switch (this->step) { 57 | while (1) { 58 | case step_A: 59 | if (plainchar == plaintextend) { 60 | this->result = result; 61 | this->step = step_A; 62 | return codechar - code_out; 63 | } 64 | fragment = *plainchar++; 65 | result = (fragment & 0x0fc) >> 2; 66 | *codechar++ = Value(result); 67 | result = (fragment & 0x003) << 4; 68 | case step_B: 69 | if (plainchar == plaintextend) { 70 | this->result = result; 71 | this->step = step_B; 72 | return codechar - code_out; 73 | } 74 | fragment = *plainchar++; 75 | result |= (fragment & 0x0f0) >> 4; 76 | *codechar++ = Value(result); 77 | result = (fragment & 0x00f) << 2; 78 | case step_C: 79 | if (plainchar == plaintextend) { 80 | this->result = result; 81 | this->step = step_C; 82 | return codechar - code_out; 83 | } 84 | fragment = *plainchar++; 85 | result |= (fragment & 0x0c0) >> 6; 86 | *codechar++ = Value(result); 87 | result = (fragment & 0x03f) >> 0; 88 | *codechar++ = Value(result); 89 | 90 | ++(this->stepcount); 91 | if (this->stepcount == CHARS_PER_LINE / 4) { 92 | *codechar++ = '\n'; 93 | this->stepcount = 0; 94 | } 95 | } 96 | } 97 | /* control should not reach here */ 98 | return codechar - code_out; 99 | } 100 | 101 | int Encoder::BlockEnd(char *code_out) { 102 | char *codechar = code_out; 103 | 104 | switch (this->step) { 105 | case step_B: 106 | *codechar++ = Value(this->result); 107 | *codechar++ = '='; 108 | *codechar++ = '='; 109 | break; 110 | case step_C: 111 | *codechar++ = Value(this->result); 112 | *codechar++ = '='; 113 | break; 114 | case step_A: 115 | break; 116 | } 117 | *codechar++ = '\n'; 118 | 119 | return codechar - code_out; 120 | } 121 | 122 | void Encoder::Encode(std::istream &istream_in, std::ostream &ostream_in) { 123 | step = step_A; 124 | result = 0; 125 | stepcount = 0; 126 | // 127 | const int N = _buffersize; 128 | char *plaintext = new char[N]; 129 | char *code = new char[2 * N]; 130 | int plainlength; 131 | int codelength; 132 | 133 | do { 134 | istream_in.read(plaintext, N); 135 | plainlength = istream_in.gcount(); 136 | // 137 | codelength = Encode(plaintext, plainlength, code); 138 | ostream_in.write(code, codelength); 139 | } while (istream_in.good() && plainlength > 0); 140 | 141 | codelength = EncodeEnd(code); 142 | ostream_in.write(code, codelength); 143 | // 144 | step = step_A; 145 | result = 0; 146 | stepcount = 0; 147 | 148 | delete[] code; 149 | delete[] plaintext; 150 | } 151 | -------------------------------------------------------------------------------- /src/common/JSON.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by gco on 3/21/20. 3 | // 4 | 5 | #include -------------------------------------------------------------------------------- /src/common/LD_Lib.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by gco on 3/21/20. 3 | // 4 | 5 | #include 6 | -------------------------------------------------------------------------------- /src/common/MessageDispatcher.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: MessageDispatcher.cpp 3 | * Author: cpalmieri 4 | * 5 | * Created on March 4, 2016, 2:22 PM 6 | */ 7 | 8 | #include "gvirtus/common/MessageDispatcher.h" 9 | 10 | using gvirtus::common::MessageDispatcher; 11 | 12 | MessageDispatcher::MessageDispatcher() {} 13 | 14 | MessageDispatcher::MessageDispatcher(const MessageDispatcher& orig) {} 15 | 16 | MessageDispatcher::~MessageDispatcher() {} 17 | -------------------------------------------------------------------------------- /src/common/Mutex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file Mutex.cpp 28 | * @author Giuseppe Coviello 29 | * @date Thu Oct 1 11:54:04 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #include "gvirtus/common/Mutex.h" 37 | 38 | using gvirtus::common::Mutex; 39 | 40 | Mutex::Mutex() { pthread_mutex_init(&mMutex, NULL); } 41 | 42 | Mutex::~Mutex() { pthread_mutex_destroy(&mMutex); } 43 | 44 | bool Mutex::Lock() { return pthread_mutex_lock(&mMutex) == 0; } 45 | 46 | void Mutex::Unlock() { pthread_mutex_unlock(&mMutex); } 47 | -------------------------------------------------------------------------------- /src/common/Observable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file Observable.cpp 28 | * @author Giuseppe Coviello 29 | * @date Sat Oct 3 9:26:26 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #include "gvirtus/common/Observable.h" 37 | 38 | using namespace std; 39 | using gvirtus::common::Observable; 40 | 41 | Observable::Observable() { 42 | mObservers = new map *>(); 43 | } 44 | 45 | Observable::~Observable() { 46 | for (map *>::iterator it = mObservers->begin(); 47 | it != mObservers->end(); it++) 48 | delete it->second; 49 | delete mObservers; 50 | } 51 | 52 | void Observable::AddObserver(std::string &event, const Observer *observer) { 53 | vector *observers; 54 | map *>::iterator it = mObservers->find(event); 55 | if (it == mObservers->end()) { 56 | observers = new vector(); 57 | mObservers->insert(make_pair(event, observers)); 58 | } else 59 | observers = it->second; 60 | for (vector::iterator it = observers->begin(); 61 | it != observers->end(); it++) 62 | if (*it == observer) return; 63 | observers->push_back(const_cast(observer)); 64 | } 65 | 66 | void Observable::AddObserver(const char *event, const Observer *observer) { 67 | string tmp(event); 68 | AddObserver(tmp, observer); 69 | } 70 | 71 | void Observable::Notify(std::string &event) { 72 | vector *observers; 73 | map *>::iterator it = mObservers->find(event); 74 | if (it == mObservers->end()) return; 75 | observers = it->second; 76 | for (vector::iterator it = observers->begin(); 77 | it != observers->end(); it++) 78 | (*it)->EventOccurred(event, this); 79 | } 80 | 81 | void Observable::Notify(const char *event) { 82 | string tmp(event); 83 | Notify(tmp); 84 | } 85 | -------------------------------------------------------------------------------- /src/common/Observer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file Observer.cpp 28 | * @author Giuseppe Coviello 29 | * @date Fri Oct 2 15:54:38 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #include "gvirtus/common/Observer.h" 37 | 38 | using gvirtus::common::Observer; 39 | 40 | Observer::~Observer() {} 41 | -------------------------------------------------------------------------------- /src/common/SignalException.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by gco on 3/21/20. 3 | // 4 | 5 | #include 6 | -------------------------------------------------------------------------------- /src/common/SignalState.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | using gvirtus::common::SignalState; 7 | 8 | void SignalState::setup_signal_state(int signo) { 9 | struct sigaction a; 10 | a.sa_handler = true_flag; 11 | a.sa_flags = 0; 12 | sigemptyset(&a.sa_mask); 13 | 14 | if (sigaction(signo, &a, nullptr) < 0) 15 | throw SignalException("Impossibile installare l'handler per il segnale!"); 16 | 17 | _signals_state.insert(std::make_pair(signo, false)); 18 | } 19 | 20 | std::map SignalState::_signals_state = {}; 21 | -------------------------------------------------------------------------------- /src/common/Util.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file Util.cpp 28 | * @author Giuseppe Coviello 29 | * @date Sun Oct 11 17:16:48 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #include "gvirtus/common/Util.h" 37 | 38 | #include 39 | #include 40 | 41 | using namespace std; 42 | using gvirtus::common::Util; 43 | 44 | Util::Util() {} 45 | 46 | Util::Util(const Util &orig) {} 47 | 48 | Util::~Util() {} 49 | 50 | char *Util::MarshalHostPointer(const void *ptr) { 51 | char *marshal = new char[Util::MarshaledHostPointerSize]; 52 | MarshalHostPointer(ptr, marshal); 53 | return marshal; 54 | } 55 | 56 | void Util::MarshalHostPointer(const void *ptr, char *marshal) { 57 | #ifdef _WIN32 58 | sprintf_s(marshal, 10, "%p", ptr); 59 | #else 60 | sprintf(marshal, "%p", ptr); 61 | #endif 62 | } 63 | 64 | char *Util::MarshalDevicePointer(const void *devPtr) { 65 | char *marshal = new char[Util::MarshaledDevicePointerSize]; 66 | MarshalDevicePointer(devPtr, marshal); 67 | return marshal; 68 | } 69 | 70 | void Util::MarshalDevicePointer(const void *devPtr, char *marshal) { 71 | #ifdef _WIN32 72 | sprintf_s(marshal, 10, "%p", devPtr); 73 | #else 74 | sprintf(marshal, "%p", devPtr); 75 | #endif 76 | } 77 | -------------------------------------------------------------------------------- /src/communicators/CommunicatorFactory.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by gco on 3/21/20. 3 | // 4 | 5 | #include 6 | -------------------------------------------------------------------------------- /src/communicators/EndpointFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "gvirtus/communicators/EndpointFactory.h" 2 | 3 | int gvirtus::communicators::EndpointFactory::ind_endpoint = 0; 4 | -------------------------------------------------------------------------------- /src/communicators/Endpoint_Rdma.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Mariano Aponte on 18/12/23. 3 | // 4 | 5 | #include "gvirtus/communicators/Endpoint_Rdma.h" 6 | #include "gvirtus/communicators/Endpoint_Tcp.h" 7 | #include 8 | #include "gvirtus/communicators/EndpointFactory.h" 9 | 10 | gvirtus::communicators::Endpoint_Rdma::Endpoint_Rdma(const std::string &endp_suite, const std::string &endp_protocol, 11 | const std::string &endp_address, const std::string &endp_port) { 12 | suite(endp_suite); 13 | protocol(endp_protocol); 14 | address(endp_address); 15 | port(endp_port); 16 | } 17 | 18 | gvirtus::communicators::Endpoint &gvirtus::communicators::Endpoint_Rdma::suite(const std::string &suite) { 19 | std::regex pattern{R"([[:alpha:]]*-[[:alpha:]]*)"}; 20 | 21 | std::smatch matches; 22 | 23 | std::regex_search(suite, matches, pattern); 24 | 25 | if (suite == matches[0]) _suite = suite; 26 | 27 | return *this; 28 | } 29 | 30 | 31 | gvirtus::communicators::Endpoint &gvirtus::communicators::Endpoint_Rdma::protocol(const std::string &protocol) { 32 | std::regex pattern{R"([[:alpha:]]*)"}; 33 | 34 | std::smatch matches; 35 | 36 | std::regex_search(protocol, matches, pattern); 37 | 38 | if (protocol == matches[0]) _protocol = protocol; 39 | 40 | return *this; 41 | } 42 | 43 | gvirtus::communicators::Endpoint_Rdma &gvirtus::communicators::Endpoint_Rdma::address(const std::string &address) { 44 | std::regex pattern{ 45 | R"(^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$)"}; 46 | std::smatch matches; 47 | 48 | std::regex_search(address, matches, pattern); 49 | 50 | if (address == matches[0]) _address = address; 51 | 52 | return *this; 53 | } 54 | 55 | gvirtus::communicators::Endpoint_Rdma &gvirtus::communicators::Endpoint_Rdma::port(const std::string &port) { 56 | std::regex pattern{ 57 | R"((6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3}))"}; 58 | 59 | std::smatch matches; 60 | 61 | std::regex_search(port, matches, pattern); 62 | 63 | if (port == matches[0]) _port = (uint16_t)std::stoi(port); 64 | 65 | return *this; 66 | } 67 | 68 | void gvirtus::communicators::from_json(const nlohmann::json &j, Endpoint_Rdma &end) { 69 | auto el = j["communicator"][EndpointFactory::index()]["endpoint"]; 70 | 71 | end.suite(el.at("suite")); 72 | end.protocol(el.at("protocol")); 73 | end.address(el.at("server_address")); 74 | end.port(el.at("port")); 75 | } -------------------------------------------------------------------------------- /src/communicators/Endpoint_Tcp.cpp: -------------------------------------------------------------------------------- 1 | #include "gvirtus/communicators/Endpoint_Tcp.h" 2 | #include "gvirtus/communicators/Endpoint_Rdma.h" 3 | #include 4 | #include "gvirtus/communicators/EndpointFactory.h" 5 | 6 | using gvirtus::communicators::Endpoint; 7 | using gvirtus::communicators::Endpoint_Tcp; 8 | using gvirtus::communicators::EndpointFactory; 9 | 10 | Endpoint_Tcp::Endpoint_Tcp(const std::string &endp_suite, 11 | const std::string &endp_protocol, 12 | const std::string &endp_address, 13 | const std::string &endp_port) { 14 | suite(endp_suite); 15 | protocol(endp_protocol); 16 | address(endp_address); 17 | port(endp_port); 18 | } 19 | 20 | Endpoint &Endpoint_Tcp::suite(const std::string &suite) { 21 | std::regex pattern{R"([[:alpha:]]*/[[:alpha:]]*)"}; 22 | 23 | std::smatch matches; 24 | 25 | std::regex_search(suite, matches, pattern); 26 | 27 | if (suite == matches[0]) _suite = suite; 28 | 29 | return *this; 30 | } 31 | 32 | Endpoint &Endpoint_Tcp::protocol(const std::string &protocol) { 33 | std::regex pattern{R"([[:alpha:]]*)"}; 34 | 35 | std::smatch matches; 36 | 37 | std::regex_search(protocol, matches, pattern); 38 | 39 | if (protocol == matches[0]) _protocol = protocol; 40 | 41 | return *this; 42 | } 43 | 44 | Endpoint_Tcp &Endpoint_Tcp::address(const std::string &address) { 45 | std::regex pattern{ 46 | R"(^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$)"}; 47 | std::smatch matches; 48 | 49 | std::regex_search(address, matches, pattern); 50 | 51 | if (address == matches[0]) _address = address; 52 | 53 | return *this; 54 | } 55 | 56 | Endpoint_Tcp &Endpoint_Tcp::port(const std::string &port) { 57 | std::regex pattern{ 58 | R"((6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3}))"}; 59 | 60 | std::smatch matches; 61 | 62 | std::regex_search(port, matches, pattern); 63 | 64 | if (port == matches[0]) _port = (uint16_t)std::stoi(port); 65 | 66 | return *this; 67 | } 68 | 69 | void gvirtus::communicators::from_json(const nlohmann::json &j, Endpoint_Tcp &end) { 70 | auto el = j["communicator"][EndpointFactory::index()]["endpoint"]; 71 | 72 | end.suite(el.at("suite")); 73 | end.protocol(el.at("protocol")); 74 | end.address(el.at("server_address")); 75 | end.port(el.at("port")); 76 | } 77 | -------------------------------------------------------------------------------- /src/communicators/Result.cpp: -------------------------------------------------------------------------------- 1 | #include "gvirtus/communicators/Result.h" 2 | 3 | using gvirtus::communicators::Result; 4 | 5 | Result::Result(int exit_code) { 6 | mExitCode = exit_code; 7 | mpOutputBuffer = NULL; 8 | } 9 | 10 | Result::Result(int exit_code, const std::shared_ptr output_buffer) { 11 | mExitCode = exit_code; 12 | mpOutputBuffer = (output_buffer); 13 | } 14 | 15 | int Result::GetExitCode() { return mExitCode; } 16 | 17 | void Result::Dump(Communicator *c) { 18 | c->Write((char *)&mExitCode, sizeof(int)); 19 | c->Write(reinterpret_cast(&mTimeTaken), sizeof(mTimeTaken)); 20 | if (mpOutputBuffer != NULL) 21 | mpOutputBuffer->Dump(c); 22 | else { 23 | size_t size = 0; 24 | c->Write((char *)&size, sizeof(size_t)); 25 | c->Sync(); 26 | } 27 | } 28 | 29 | void Result::TimeTaken(double time_taken) { 30 | mTimeTaken = time_taken; 31 | } 32 | 33 | double Result::TimeTaken() const { 34 | return mTimeTaken; 35 | } 36 | -------------------------------------------------------------------------------- /src/communicators/VMSocketCommunicator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: VMSocketCommunicator.cpp 3 | * Author: cjg 4 | * 5 | * Created on February 14, 2011, 3:57 PM 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include "VMSocketCommunicator.h" 16 | 17 | using namespace std; 18 | 19 | namespace gvirtus { 20 | 21 | VMSocketCommunicator::VMSocketCommunicator(const std::string &communicator) { 22 | const char *deviceptr = strstr(communicator.c_str(), "://") + 3; 23 | const char *pathptr = strchr(deviceptr, ':'); 24 | if (pathptr == NULL) 25 | throw "VMSocketCommunicator: path not specified."; 26 | mDevice = string(deviceptr).substr(0, pathptr - deviceptr); 27 | mPath = string(pathptr + 1); 28 | } 29 | 30 | void 31 | VMSocketCommunicator::Serve() { 32 | throw "VMSocketCommunicator: cannot Serve"; 33 | } 34 | 35 | const Communicator *const 36 | VMSocketCommunicator::Accept() const { 37 | throw "VMSocketCommunicator: cannot Accept"; 38 | } 39 | 40 | void 41 | VMSocketCommunicator::Connect() { 42 | if ((mFd = open(mDevice.c_str(), O_RDWR)) < 0) 43 | throw "VMSocketCommunicator: cannot open device."; 44 | if (ioctl(mFd, 0, mPath.c_str()) != 0) 45 | throw "VMSocketCommunicator: cannot connect."; 46 | } 47 | 48 | size_t 49 | VMSocketCommunicator::Read(char *buffer, size_t size) { 50 | size_t offset = 0; 51 | int readed; 52 | while (offset < size) { 53 | readed = read(mFd, buffer + offset, size - offset); 54 | if (readed <= 0 && offset == 0) 55 | return readed; 56 | offset += readed; 57 | } 58 | return size; 59 | } 60 | 61 | size_t 62 | VMSocketCommunicator::Write(const char *buffer, size_t size) { 63 | size_t offset = 0; 64 | int written; 65 | while (offset < size) { 66 | written = write(mFd, buffer + offset, size - offset); 67 | offset += written; 68 | } 69 | return size; 70 | } 71 | 72 | void 73 | VMSocketCommunicator::Sync() { 74 | fsync(mFd); 75 | } 76 | 77 | void 78 | VMSocketCommunicator::Close() { 79 | close(mFd); 80 | } 81 | } // namespace gvirtus -------------------------------------------------------------------------------- /src/communicators/VirtioCommunicator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file VirtioCommunicator.cpp 28 | * @author Abhijeet Dev 29 | * @date Tue Mar 6 15:31:54 2012 30 | * 31 | * @brief 32 | * 33 | */ 34 | 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | #include 41 | 42 | #include "VirtioCommunicator.h" 43 | 44 | using namespace std; 45 | 46 | namespace gvirtus { 47 | 48 | VirtioCommunicator::VirtioCommunicator(const std::string &communicator) { 49 | const char *deviceptr = strstr(communicator.c_str(), "://") + 3; 50 | mDevice = string(deviceptr); 51 | } 52 | 53 | void 54 | VirtioCommunicator::Serve() { 55 | throw "VirtioCommunicator: cannot Serve"; 56 | } 57 | 58 | const Communicator *const 59 | VirtioCommunicator::Accept() const { 60 | throw "VirtioCommunicator: cannot Accept"; 61 | } 62 | 63 | void 64 | VirtioCommunicator::Connect() { 65 | if ((mFd = open(mDevice.c_str(), O_RDWR)) < 0) 66 | throw "VirtioCommunicator: cannot open device."; 67 | } 68 | 69 | size_t 70 | VirtioCommunicator::Read(char *buffer, size_t size) { 71 | size_t offset = 0; 72 | int readed; 73 | while (offset < size) { 74 | readed = read(mFd, buffer + offset, size - offset); 75 | if (readed <= 0 && offset == 0) 76 | return readed; 77 | offset += readed; 78 | } 79 | return size; 80 | } 81 | 82 | size_t 83 | VirtioCommunicator::Write(const char *buffer, size_t size) { 84 | size_t offset = 0; 85 | int written; 86 | while (offset < size) { 87 | written = write(mFd, buffer + offset, size - offset); 88 | offset += written; 89 | } 90 | return size; 91 | } 92 | 93 | void 94 | VirtioCommunicator::Sync() { 95 | fsync(mFd); 96 | } 97 | 98 | void 99 | VirtioCommunicator::Close() { 100 | close(mFd); 101 | } 102 | } // namespace gvirtus -------------------------------------------------------------------------------- /src/communicators/rdma/RdmaCommunicator.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Mariano Aponte on 07/12/23. 3 | // 4 | 5 | #ifndef RDMACM_RDMACOMMUNICATOR_H 6 | #define RDMACM_RDMACOMMUNICATOR_H 7 | 8 | #include "gvirtus/communicators/Communicator.h" 9 | #include "ktmrdma.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #define BACKLOG 8 16 | #define BUF_SIZE 1024 17 | #define DEBUG 18 | 19 | /** 20 | * @brief RdmaCommunicator represents a communication interface using RDMA (Remote Direct Memory Access). 21 | */ 22 | namespace gvirtus::communicators { 23 | class RdmaCommunicator : public Communicator { 24 | private: 25 | rdma_cm_id * rdmaCmId; 26 | rdma_cm_id * rdmaCmListenId; 27 | 28 | char hostname[256]; 29 | char port[6]; 30 | 31 | ibv_wc workCompletion; 32 | 33 | ibv_mr * memoryRegion; 34 | 35 | char preregisteredBuffer[1024 * 5]; 36 | ibv_mr * preregisteredMr; 37 | 38 | public: 39 | RdmaCommunicator() = default; 40 | RdmaCommunicator(char * hostname, char * port); 41 | RdmaCommunicator(rdma_cm_id * rdmaCmId); 42 | 43 | ~RdmaCommunicator(); 44 | 45 | void Serve(); 46 | const Communicator *const Accept() const; 47 | 48 | void Connect(); 49 | 50 | size_t Read(char * buffer, size_t size); 51 | size_t Write(const char * buffer, size_t size); 52 | 53 | void Sync(); 54 | 55 | void Close(); 56 | 57 | std::string to_string() {return "rdmacommunicator";}; 58 | }; 59 | 60 | } 61 | 62 | #endif //RDMACM_RDMACOMMUNICATOR_H 63 | -------------------------------------------------------------------------------- /src/communicators/tcp/TcpCommunicator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * gVirtuS -- A GPGPU transparent virtualization component. 3 | * 4 | * Copyright (C) 2009-2010 The University of Napoli Parthenope at Naples. 5 | * 6 | * This file is part of gVirtuS. 7 | * 8 | * gVirtuS is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * gVirtuS is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with gVirtuS; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | * Written by: Giuseppe Coviello , 23 | * Department of Applied Science 24 | */ 25 | 26 | /** 27 | * @file TcpCommunicator.h 28 | * @author Giuseppe Coviello 29 | * @date Thu Oct 8 12:08:33 2009 30 | * 31 | * @brief 32 | * 33 | * 34 | */ 35 | 36 | #pragma once 37 | 38 | #ifdef _WIN32 39 | #include 40 | #else 41 | #include 42 | #endif 43 | 44 | #include "gvirtus/communicators/Communicator.h" 45 | 46 | namespace gvirtus::communicators { 47 | /** 48 | * TcpCommunicator implements a Communicator for the TCP/IP socket. 49 | */ 50 | class TcpCommunicator : public Communicator { 51 | public: 52 | TcpCommunicator() = default; 53 | TcpCommunicator(const std::string &communicator); 54 | TcpCommunicator(const char *hostname, short port); 55 | TcpCommunicator(int fd, const char *hostname); 56 | virtual ~TcpCommunicator(); 57 | void Serve(); 58 | const Communicator *const Accept() const; 59 | void Connect(); 60 | size_t Read(char *buffer, size_t size); 61 | size_t Write(const char *buffer, size_t size); 62 | void Sync(); 63 | void Close(); 64 | 65 | std::string to_string() override { return "tcpcommunicator"; } 66 | 67 | private: 68 | void InitializeStream(); 69 | std::istream *mpInput; 70 | std::ostream *mpOutput; 71 | std::string mHostname; 72 | char *mInAddr; 73 | int mInAddrSize; 74 | short mPort; 75 | int mSocketFd; 76 | #ifdef _WIN32 77 | std::filebuf *mpInputBuf; 78 | std::filebuf *mpOutputBuf; 79 | #else 80 | __gnu_cxx::stdio_filebuf *mpInputBuf; 81 | __gnu_cxx::stdio_filebuf *mpOutputBuf; 82 | #endif 83 | }; 84 | } // namespace gvirtus::communicators 85 | -------------------------------------------------------------------------------- /tools/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gvirtus/GVirtuS/18f16dc300352f4e3d6caf010ae81f43d565b036/tools/CMakeLists.txt -------------------------------------------------------------------------------- /tools/protocol-generator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.18) 2 | project("protocol-generator") 3 | 4 | find_library(LIBCLANG_CPP_LIBRARY clang) 5 | 6 | if(LIBCLANG_CPP_LIBRARY) 7 | message(STATUS "Found Clang library (${LIBCLANG_CPP_LIBRARY}") 8 | else() 9 | message(STATUS "NOT found Clang library") 10 | endif() 11 | 12 | find_file(CLANG_AST_HEADER clang/AST/AST.h) 13 | 14 | if(CLANG_AST_HEADER) 15 | get_filename_component(LIBCLANG_INCLUDES ${CLANG_AST_HEADER} DIRECTORY) 16 | get_filename_component(LIBCLANG_INCLUDES ${LIBCLANG_INCLUDES} DIRECTORY) 17 | get_filename_component(LIBCLANG_INCLUDES ${LIBCLANG_INCLUDES} DIRECTORY) 18 | message(STATUS "Found Clang headers (${LIBCLANG_INCLUDES})") 19 | else() 20 | message(STATUS "NOT found Clang headers") 21 | endif() 22 | 23 | if(LIBCLANG_CPP_LIBRARY AND CLANG_AST_HEADER) 24 | message(STATUS "Building ${PROJECT_NAME}") 25 | add_executable(${PROJECT_NAME} 26 | main.cpp) 27 | target_link_libraries(${PROJECT_NAME} ${LIBCLANG_CPP_LIBRARY}) 28 | else() 29 | message(STATUS "NOT building ${PROJECT_NAME}") 30 | endif() 31 | -------------------------------------------------------------------------------- /tools/protocol-generator/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by cjg on 10/31/21. 3 | // 4 | 5 | #include 6 | 7 | #include 8 | 9 | class Generator { 10 | public: 11 | void Generate(); 12 | 13 | private: 14 | static CXChildVisitResult visit(CXCursor cursor, CXCursor parent, CXClientData client_data); 15 | CXChildVisitResult visit(CXCursor cursor, CXCursor parent); 16 | }; 17 | 18 | void Generator::Generate() { 19 | char *args[] = { "-I/usr/local/cuda/include" }; 20 | auto index = clang_createIndex(0, 0); 21 | auto tu = clang_createTranslationUnitFromSourceFile(index, "test.cpp", 1, args, 22 | 0, nullptr); 23 | clang_visitChildren(clang_getTranslationUnitCursor(tu), 24 | Generator::visit, this); 25 | clang_disposeTranslationUnit(tu); 26 | } 27 | 28 | CXChildVisitResult Generator::visit(CXCursor cursor, CXCursor parent, CXClientData client_data) { 29 | return reinterpret_cast(client_data)->visit(cursor, parent); 30 | } 31 | 32 | CXChildVisitResult Generator::visit(CXCursor cursor, CXCursor parent) { 33 | auto kind = clang_getCursorKind(cursor); 34 | auto name = clang_getCursorDisplayName(cursor); 35 | if (kind == CXCursor_FunctionDecl) { 36 | if (clang_isCursorDefinition(cursor)) { 37 | // ignoring local function definitions 38 | return CXChildVisit_Continue; 39 | } 40 | name = clang_Cursor_getMangling(cursor); 41 | std::cout << "Function: " << reinterpret_cast(name.data) << std::endl; 42 | auto resultType = clang_getCursorResultType(cursor); 43 | name = clang_getTypeSpelling(resultType); 44 | std::cout << " Return: " << reinterpret_cast(name.data) << std::endl; 45 | } else if (kind == CXCursor_ParmDecl) { 46 | auto indirections = 0; 47 | CXType type = clang_getCursorType(cursor); 48 | while (true) { 49 | type = clang_getCanonicalType(type); 50 | if (!(type.kind & CXType_Pointer)) { 51 | break; 52 | } 53 | type = clang_getPointeeType(type); 54 | indirections++; 55 | } 56 | auto typeSpelling = clang_getTypeSpelling(type); 57 | std::string typeName(reinterpret_cast(typeSpelling.data)); 58 | if (typeName.empty()) { 59 | typeName = "void"; 60 | } 61 | std::cout << " Param: " << typeName; 62 | for (auto i = 0; i < indirections; i++) { 63 | std::cout << "*"; 64 | } 65 | std::cout << " " << reinterpret_cast(name.data) << std::endl; 66 | } else if (kind == CXCursor_StructDecl && clang_isCursorDefinition(cursor)) { 67 | std::cout << "Struct: " << reinterpret_cast(name.data) << std::endl; 68 | } else if (kind == CXCursor_FieldDecl) { 69 | auto type = clang_getCursorType(cursor); 70 | type = clang_getCanonicalType(type); 71 | auto typeName = clang_getTypeSpelling(type); 72 | std::cout << " Field: " << reinterpret_cast(typeName.data) << " " 73 | << reinterpret_cast(name.data) << std::endl; 74 | } else if (kind == CXCursor_EnumDecl) { 75 | std::cout << "Enum: " << reinterpret_cast(name.data) << std::endl; 76 | } 77 | return CXChildVisit_Recurse; 78 | } 79 | 80 | int main() { 81 | Generator g; 82 | g.Generate(); 83 | } 84 | --------------------------------------------------------------------------------