summaryrefslogtreecommitdiff
path: root/libcuda
diff options
context:
space:
mode:
authorMengchi Zhang <[email protected]>2019-06-12 00:42:37 -0400
committerMengchi Zhang <[email protected]>2019-06-12 00:42:37 -0400
commitba1ed2941753ae8406bc9ec4a0de1eddc6454a1c (patch)
tree6fae9e92c22c29138f0c33048bd79483d09ad480 /libcuda
parent269fbbdb72dacdf4dc3c482b213174336c3eeb1f (diff)
Move some vars
Signed-off-by: Mengchi Zhang <[email protected]>
Diffstat (limited to 'libcuda')
-rw-r--r--libcuda/cuda_api_object.h5
-rw-r--r--libcuda/cuda_runtime_api.cc74
2 files changed, 48 insertions, 31 deletions
diff --git a/libcuda/cuda_api_object.h b/libcuda/cuda_api_object.h
index d931fd5..f9a4fde 100644
--- a/libcuda/cuda_api_object.h
+++ b/libcuda/cuda_api_object.h
@@ -171,6 +171,7 @@ class cuda_runtime_api {
public:
cuda_runtime_api() {
g_glbmap = NULL;
+ g_active_device = 0; //active gpu that runs the code
}
// global list
std::list<cuobjdumpSection*> cuobjdumpSectionList;
@@ -185,6 +186,7 @@ class cuda_runtime_api {
std::map<void *,void **> pinned_memory; //support for pinned memories added
std::map<void *, size_t> pinned_memory_size;
glbmap_entry_t* g_glbmap;
+ int g_active_device; //active gpu that runs the code
// member function list
void cuobjdumpInit();
void extract_code_using_cuobjdump();
@@ -201,5 +203,8 @@ class cuda_runtime_api {
struct dim3 gridDim,
struct dim3 blockDim,
struct CUctx_st* context );
+ int load_static_globals( symbol_table *symtab, unsigned min_gaddr, unsigned max_gaddr, gpgpu_t *gpu );
+ int load_constants( symbol_table *symtab, addr_t min_gaddr, gpgpu_t *gpu );
+
};
#endif /* __cuda_api_object_h__ */
diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc
index c5ebc20..09a13a7 100644
--- a/libcuda/cuda_runtime_api.cc
+++ b/libcuda/cuda_runtime_api.cc
@@ -153,15 +153,6 @@
extern void synchronize();
extern void exit_simulation();
-static int load_static_globals( symbol_table *symtab, unsigned min_gaddr, unsigned max_gaddr, gpgpu_t *gpu );
-static int load_constants( symbol_table *symtab, addr_t min_gaddr, gpgpu_t *gpu );
-
-//static kernel_info_t *gpgpu_cuda_ptx_sim_init_grid( const char *kernel_key,
-// gpgpu_ptx_sim_arg_list_t args,
-// struct dim3 gridDim,
-// struct dim3 blockDim,
-// struct CUctx_st* context );
-
/*DEVICE_BUILTIN*/
struct cudaArray
{
@@ -353,7 +344,6 @@ typedef std::map<unsigned,CUevent_st*> event_tracker_t;
int CUevent_st::m_next_event_uid;
event_tracker_t g_timer_events;
-int g_active_device = 0; //active gpu that runs the code
extern int cuobjdump_lex_init(yyscan_t* scanner);
extern void cuobjdump_set_in (FILE * _in_str ,yyscan_t yyscanner );
@@ -492,6 +482,41 @@ void cuda_runtime_api::cuobjdumpRegisterFatBinary(unsigned int handle, const cha
/*******************************************************************************
* Add internal cuda runtime API call to accept gpgpu_context *
*******************************************************************************/
+cudaError_t cudaSetDeviceInternal(int device, gpgpu_context* gpgpu_ctx = NULL)
+{
+ gpgpu_context *ctx;
+ if (gpgpu_ctx){
+ ctx = gpgpu_ctx;
+ } else {
+ ctx = GPGPU_Context();
+ }
+ if(g_debug_execution >= 3){
+ announce_call(__my_func__);
+ }
+ //set the active device to run cuda
+ if ( device <= GPGPUSim_Init()->num_devices() ) {
+ ctx->api->g_active_device = device;
+ return g_last_cudaError = cudaSuccess;
+ } else {
+ return g_last_cudaError = cudaErrorInvalidDevice;
+ }
+}
+
+cudaError_t cudaGetDeviceInternal(int *device, gpgpu_context* gpgpu_ctx = NULL)
+{
+ gpgpu_context *ctx;
+ if (gpgpu_ctx){
+ ctx = gpgpu_ctx;
+ } else {
+ ctx = GPGPU_Context();
+ }
+ if(g_debug_execution >= 3){
+ announce_call(__my_func__);
+ }
+ *device = ctx->api->g_active_device;
+ return g_last_cudaError = cudaSuccess;
+}
+
void** cudaRegisterFatBinaryInternal( void *fatCubin, gpgpu_context* gpgpu_ctx = NULL)
{
@@ -618,8 +643,8 @@ void** cudaRegisterFatBinaryInternal( void *fatCubin, gpgpu_context* gpgpu_ctx =
gpgpu_ptxinfo_load_from_string( ptx, source_num, max_capability, context->no_of_ptx );
}
source_num++;
- load_static_globals(symtab,STATIC_ALLOC_LIMIT,0xFFFFFFFF,context->get_device()->get_gpgpu());
- load_constants(symtab,STATIC_ALLOC_LIMIT,context->get_device()->get_gpgpu());
+ ctx->api->load_static_globals(symtab,STATIC_ALLOC_LIMIT,0xFFFFFFFF,context->get_device()->get_gpgpu());
+ ctx->api->load_constants(symtab,STATIC_ALLOC_LIMIT,context->get_device()->get_gpgpu());
} else {
printf("GPGPU-Sim PTX: warning -- did not find an appropriate PTX in cubin\n");
}
@@ -988,8 +1013,8 @@ cuLinkAddFileInternal(CUlinkState state, CUjitInputType type, const char *path,
std::string fname(path);
ctx->api->name_symtab[fname] = symtab;
context->add_binary(symtab, 1);
- load_static_globals(symtab,STATIC_ALLOC_LIMIT,0xFFFFFFFF,context->get_device()->get_gpgpu());
- load_constants(symtab,STATIC_ALLOC_LIMIT,context->get_device()->get_gpgpu());
+ ctx->api->load_static_globals(symtab,STATIC_ALLOC_LIMIT,0xFFFFFFFF,context->get_device()->get_gpgpu());
+ ctx->api->load_constants(symtab,STATIC_ALLOC_LIMIT,context->get_device()->get_gpgpu());
addedFile = true;
return CUDA_SUCCESS;
}
@@ -1692,25 +1717,12 @@ __host__ cudaError_t CUDARTAPI cudaChooseDevice(int *device, const struct cudaDe
__host__ cudaError_t CUDARTAPI cudaSetDevice(int device)
{
- if(g_debug_execution >= 3){
- announce_call(__my_func__);
- }
- //set the active device to run cuda
- if ( device <= GPGPUSim_Init()->num_devices() ) {
- g_active_device = device;
- return g_last_cudaError = cudaSuccess;
- } else {
- return g_last_cudaError = cudaErrorInvalidDevice;
- }
+ return cudaSetDeviceInternal(device);
}
__host__ cudaError_t CUDARTAPI cudaGetDevice(int *device)
{
- if(g_debug_execution >= 3){
- announce_call(__my_func__);
- }
- *device = g_active_device;
- return g_last_cudaError = cudaSuccess;
+ return cudaGetDeviceInternal(device);
}
__host__ cudaError_t CUDARTAPI cudaDeviceGetLimit ( size_t* pValue, cudaLimit limit )
@@ -3269,7 +3281,7 @@ int CUDARTAPI __cudaSynchronizeThreads(void**, void*)
/// static functions
-static int load_static_globals( symbol_table *symtab, unsigned min_gaddr, unsigned max_gaddr, gpgpu_t *gpu )
+int cuda_runtime_api::load_static_globals( symbol_table *symtab, unsigned min_gaddr, unsigned max_gaddr, gpgpu_t *gpu )
{
if(g_debug_execution >= 3){
announce_call(__my_func__);
@@ -3308,7 +3320,7 @@ static int load_static_globals( symbol_table *symtab, unsigned min_gaddr, unsign
return ng_bytes;
}
-static int load_constants( symbol_table *symtab, addr_t min_gaddr, gpgpu_t *gpu )
+int cuda_runtime_api::load_constants( symbol_table *symtab, addr_t min_gaddr, gpgpu_t *gpu )
{
if(g_debug_execution >= 3){
announce_call(__my_func__);