Yet Another eXchange Tool 0.11.3
Loading...
Searching...
No Matches
xt_cuda.c File Reference
#include "xt_cuda.h"
#include <cuda.h>
#include <dlfcn.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "core/core.h"
#include "core/ppm_xfuncs.h"
#include "xt_gpu.h"
Include dependency graph for xt_cuda.c:

Go to the source code of this file.

Macros

#define MAX(a, b)
 
#define STRINGIFY2(x)
 
#define STRINGIFY(x)
 
#define DLSYM(name)
 
#define CU_ERROR_CHECK(ret)
 

Functions

static void * xt_cuda_malloc (size_t alloc_size, enum xt_memtype memtype)
 
static void xt_cuda_free (void *ptr, enum xt_memtype memtype)
 
static void xt_cuda_memcpy (void *dst, void const *src, size_t buffer_size, enum xt_memtype dst_memtype, enum xt_memtype src_memtype)
 
static enum xt_memtype xt_cuda_get_memtype (const void *ptr)
 
static int dummy_instr_push (char const *XT_UNUSED(name))
 
static int dummy_instr_pop ()
 
static int load_cuda_library (void)
 
const struct xt_gpu_vtablext_cuda_init (void)
 

Variables

static const char filename [] = "xt_cuda.c"
 
static CUresult(* func_cuGetErrorString )(CUresult error, const char **pStr)
 
static CUresult(* func_cuPointerGetAttribute )(void *data, CUpointer_attribute attribute, CUdeviceptr ptr)
 
static CUresult(* func_cuMemAlloc )(CUdeviceptr *dptr, size_t bytesize)
 
static CUresult(* func_cuMemFree )(CUdeviceptr dptr)
 
static CUresult(* func_cuMemcpyDtoD )(CUdeviceptr dstDevice, CUdeviceptr srcDevice, size_t ByteCount)
 
static CUresult(* func_cuMemcpyHtoD )(CUdeviceptr dstDevice, const void *srcHost, size_t ByteCount)
 
static CUresult(* func_cuMemcpyDtoH )(void *dstHost, CUdeviceptr srcDevice, size_t ByteCount)
 
static struct xt_gpu_vtable const cuda_vtable
 

Detailed Description

Author
Jörg Behrens behre.nosp@m.ns@d.nosp@m.krz.d.nosp@m.e Moritz Hanke hanke.nosp@m.@dkr.nosp@m.z.de Thomas Jahns jahns.nosp@m.@dkr.nosp@m.z.de

Definition in file xt_cuda.c.

Macro Definition Documentation

◆ CU_ERROR_CHECK

#define CU_ERROR_CHECK ( ret)
Value:
do{ \
CUresult err = ret; \
if(err != CUDA_SUCCESS) \
{ \
char const * err_string; \
if (CUDA_SUCCESS != \
func_cuGetErrorString(err, &err_string)) \
err_string = "undefined error"; \
fprintf(stderr, "Cuda driver error %d %s:: %s\n", \
__LINE__, __func__, err_string); \
exit(EXIT_FAILURE); \
} \
} while(0)
static CUresult(* func_cuGetErrorString)(CUresult error, const char **pStr)
Definition xt_cuda.c:101

Definition at line 86 of file xt_cuda.c.

◆ DLSYM

#define DLSYM ( name)
Value:
do { \
void * ptr = dlsym(libcuda_handle, STRINGIFY(name)); \
if (ptr != NULL) { \
*(void **)(&(func_ ## name)) = ptr; \
} else { \
load_successful = false; \
fprintf( \
stderr, "ERROR:failed to load routine \"%s\" " \
"from %s\n", STRINGIFY(name), lib); \
} \
} while(0)
char name[32]
Definition xt_config.c:93
#define STRINGIFY(x)
Definition xt_cuda.c:71

Definition at line 73 of file xt_cuda.c.

◆ MAX

#define MAX ( a,
b )
Value:
((a) >= (b) ? (a) : (b))

Definition at line 68 of file xt_cuda.c.

◆ STRINGIFY

#define STRINGIFY ( x)
Value:
#define STRINGIFY2(x)
Definition xt_cuda.c:70

Definition at line 71 of file xt_cuda.c.

◆ STRINGIFY2

#define STRINGIFY2 ( x)
Value:
#x

Definition at line 70 of file xt_cuda.c.

Function Documentation

◆ dummy_instr_pop()

static int dummy_instr_pop ( )
static

Definition at line 224 of file xt_cuda.c.

◆ dummy_instr_push()

static int dummy_instr_push ( char const * XT_UNUSEDname)
static

Definition at line 223 of file xt_cuda.c.

◆ load_cuda_library()

static int load_cuda_library ( void )
static

Definition at line 227 of file xt_cuda.c.

Here is the caller graph for this function:

◆ xt_cuda_free()

static void xt_cuda_free ( void * ptr,
enum xt_memtype memtype )
static

Definition at line 134 of file xt_cuda.c.

◆ xt_cuda_get_memtype()

static enum xt_memtype xt_cuda_get_memtype ( const void * ptr)
static

Definition at line 203 of file xt_cuda.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xt_cuda_init()

const struct xt_gpu_vtable * xt_cuda_init ( void )

Initialises CUDA

Returns
NULL if CUDA could not be initialised
otherwise a valid vtable is returned

Definition at line 314 of file xt_cuda.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xt_cuda_malloc()

static void * xt_cuda_malloc ( size_t alloc_size,
enum xt_memtype memtype )
static

Definition at line 113 of file xt_cuda.c.

◆ xt_cuda_memcpy()

static void xt_cuda_memcpy ( void * dst,
void const * src,
size_t buffer_size,
enum xt_memtype dst_memtype,
enum xt_memtype src_memtype )
static

Definition at line 152 of file xt_cuda.c.

Variable Documentation

◆ cuda_vtable

struct xt_gpu_vtable const cuda_vtable
static
Initial value:
= {
.Malloc = xt_cuda_malloc,
.Free = xt_cuda_free,
.Memcpy = xt_cuda_memcpy,
.Get_memtype = xt_cuda_get_memtype,
.Instr_push = dummy_instr_push,
.Instr_pop = dummy_instr_pop,
}
static int dummy_instr_pop()
Definition xt_cuda.c:224
static void xt_cuda_free(void *ptr, enum xt_memtype memtype)
Definition xt_cuda.c:134
static int dummy_instr_push(char const *XT_UNUSED(name))
Definition xt_cuda.c:223
static void * xt_cuda_malloc(size_t alloc_size, enum xt_memtype memtype)
Definition xt_cuda.c:113
static void xt_cuda_memcpy(void *dst, void const *src, size_t buffer_size, enum xt_memtype dst_memtype, enum xt_memtype src_memtype)
Definition xt_cuda.c:152
static enum xt_memtype xt_cuda_get_memtype(const void *ptr)
Definition xt_cuda.c:203

Definition at line 300 of file xt_cuda.c.

◆ filename

const char filename[] = "xt_cuda.c"
static

Definition at line 66 of file xt_cuda.c.

◆ func_cuGetErrorString

CUresult(* func_cuGetErrorString) (CUresult error, const char **pStr) ( CUresult error,
const char ** pStr )
static

Definition at line 101 of file xt_cuda.c.

◆ func_cuMemAlloc

CUresult(* func_cuMemAlloc) (CUdeviceptr *dptr, size_t bytesize) ( CUdeviceptr * dptr,
size_t bytesize )
static

Definition at line 104 of file xt_cuda.c.

◆ func_cuMemcpyDtoD

CUresult(* func_cuMemcpyDtoD) (CUdeviceptr dstDevice, CUdeviceptr srcDevice, size_t ByteCount) ( CUdeviceptr dstDevice,
CUdeviceptr srcDevice,
size_t ByteCount )
static

Definition at line 106 of file xt_cuda.c.

◆ func_cuMemcpyDtoH

CUresult(* func_cuMemcpyDtoH) (void *dstHost, CUdeviceptr srcDevice, size_t ByteCount) ( void * dstHost,
CUdeviceptr srcDevice,
size_t ByteCount )
static

Definition at line 110 of file xt_cuda.c.

◆ func_cuMemcpyHtoD

CUresult(* func_cuMemcpyHtoD) (CUdeviceptr dstDevice, const void *srcHost, size_t ByteCount) ( CUdeviceptr dstDevice,
const void * srcHost,
size_t ByteCount )
static

Definition at line 108 of file xt_cuda.c.

◆ func_cuMemFree

CUresult(* func_cuMemFree) (CUdeviceptr dptr) ( CUdeviceptr dptr)
static

Definition at line 105 of file xt_cuda.c.

◆ func_cuPointerGetAttribute

CUresult(* func_cuPointerGetAttribute) (void *data, CUpointer_attribute attribute, CUdeviceptr ptr) ( void * data,
CUpointer_attribute attribute,
CUdeviceptr ptr )
static

Definition at line 102 of file xt_cuda.c.