Commit 49fdd9d8 authored by Cianciosa, Mark's avatar Cianciosa, Mark
Browse files

Statically initialize cuda.

parent f0cdc3c0
Loading
Loading
Loading
Loading
+36 −32
Original line number Diff line number Diff line
@@ -16,32 +16,6 @@
#include "node.hpp"

namespace gpu {
//------------------------------------------------------------------------------
///   @brief Initalize cuda.
//------------------------------------------------------------------------------
    static void init() {
        cuInit(0);
    }

//------------------------------------------------------------------------------
///  @brief Class representing a cuda gpu context.
//------------------------------------------------------------------------------
    template<typename T, bool SAFE_MATH=false>
    class cuda_context {
    private:
///  The cuda device.
        CUdevice device;
///  The cuda context.
        CUcontext context;
///  The cuda code library.
        CUmodule module;
///  Argument map.
        std::map<graph::leaf_node<T, SAFE_MATH> *, CUdeviceptr> kernel_arguments;
///  Result buffer.
        CUdeviceptr result_buffer;
///  Cuda stream.
        CUstream stream;

//------------------------------------------------------------------------------
///  @brief  Check results of realtime compile.
///  @params[in] name   Name of the operation.
@@ -61,7 +35,7 @@ namespace gpu {
///  @params[in] result Result code of the operation.
///  @params[in] name   Name of the operation.
//------------------------------------------------------------------------------
        static void check_error(CUresult result,
    static check_error(CUresult result,
                            const std::string &name) {
#ifndef NDEBUG
        const char *error;
@@ -72,6 +46,36 @@ namespace gpu {
#endif
    }

//------------------------------------------------------------------------------
///   @brief Initalize cuda.
//------------------------------------------------------------------------------
    static CUresult cuda_init() {
        const CUresult result = cuInit(0);
        check_error(result, "cuInit");
        return result;
    }
///  Initalize Cuda.
    static const result = cuda_init();

//------------------------------------------------------------------------------
///  @brief Class representing a cuda gpu context.
//------------------------------------------------------------------------------
    template<typename T, bool SAFE_MATH=false>
    class cuda_context {
    private:
///  The cuda device.
        CUdevice device;
///  The cuda context.
        CUcontext context;
///  The cuda code library.
        CUmodule module;
///  Argument map.
        std::map<graph::leaf_node<T, SAFE_MATH> *, CUdeviceptr> kernel_arguments;
///  Result buffer.
        CUdeviceptr result_buffer;
///  Cuda stream.
        CUstream stream;

//------------------------------------------------------------------------------
///  @brief  Check results of async cuda functions.
///