9
9
* University of Stuttgart. All rights reserved.
10
10
* Copyright (c) 2004-2005 The Regents of the University of California.
11
11
* All rights reserved.
12
- * Copyright (c) 2008-2018 University of Houston. All rights reserved.
12
+ * Copyright (c) 2008-2019 University of Houston. All rights reserved.
13
13
* $COPYRIGHT$
14
14
*
15
15
* Additional copyrights may follow
27
27
#include "opal/mca/allocator/allocator.h"
28
28
#include "opal/mca/allocator/base/base.h"
29
29
#include "common_ompio.h"
30
- #include "common_ompio_cuda .h"
30
+ #include "common_ompio_buffer .h"
31
31
32
32
33
- static opal_mutex_t mca_common_ompio_cuda_mutex ; /* lock for thread safety */
33
+ static opal_mutex_t mca_common_ompio_buffer_mutex ; /* lock for thread safety */
34
34
static mca_allocator_base_component_t * mca_common_ompio_allocator_component = NULL ;
35
35
static mca_allocator_base_module_t * mca_common_ompio_allocator = NULL ;
36
36
37
- static opal_atomic_int32_t mca_common_ompio_cuda_init = 0 ;
37
+ static opal_atomic_int32_t mca_common_ompio_buffer_init = 0 ;
38
38
static int32_t mca_common_ompio_pagesize = 4096 ;
39
- static void * mca_common_ompio_cuda_alloc_seg ( void * ctx , size_t * size );
40
- static void mca_common_ompio_cuda_free_seg ( void * ctx , void * buf );
39
+ static void * mca_common_ompio_buffer_alloc_seg ( void * ctx , size_t * size );
40
+ static void mca_common_ompio_buffer_free_seg ( void * ctx , void * buf );
41
41
42
+ #if OPAL_CUDA_SUPPORT
42
43
void mca_common_ompio_check_gpu_buf ( ompio_file_t * fh , const void * buf , int * is_gpu ,
43
44
int * is_managed )
44
45
{
@@ -57,8 +58,9 @@ void mca_common_ompio_check_gpu_buf ( ompio_file_t *fh, const void *buf, int *is
57
58
58
59
return ;
59
60
}
61
+ #endif
60
62
61
- static void * mca_common_ompio_cuda_alloc_seg ( void * ctx , size_t * size )
63
+ static void * mca_common_ompio_buffer_alloc_seg ( void * ctx , size_t * size )
62
64
{
63
65
char * buf = NULL ;
64
66
size_t realsize , numpages ;
@@ -67,64 +69,67 @@ static void* mca_common_ompio_cuda_alloc_seg ( void*ctx, size_t *size )
67
69
realsize = numpages * mca_common_ompio_pagesize ;
68
70
69
71
buf = malloc ( realsize );
72
+ #if OPAL_CUDA_SUPPORT
70
73
if ( NULL != buf ) {
71
74
mca_common_cuda_register ( ( char * )buf , realsize , NULL );
72
75
}
76
+ #endif
73
77
* size = realsize ;
74
78
return buf ;
75
79
}
76
80
77
- static void mca_common_ompio_cuda_free_seg ( void * ctx , void * buf )
81
+ static void mca_common_ompio_buffer_free_seg ( void * ctx , void * buf )
78
82
{
79
83
if ( NULL != buf ) {
84
+ #if OPAL_CUDA_SUPPORT
80
85
mca_common_cuda_unregister ( (char * ) buf , NULL );
86
+ #endif
81
87
free ( buf );
82
88
}
83
89
return ;
84
90
}
85
91
86
- int mca_common_ompio_cuda_alloc_init ( void )
92
+ int mca_common_ompio_buffer_alloc_init ( void )
87
93
{
88
94
bool thread_safe = true;
89
95
90
- if (OPAL_THREAD_ADD_FETCH32 (& mca_common_ompio_cuda_init , 1 ) > 1 )
96
+ if (OPAL_THREAD_ADD_FETCH32 (& mca_common_ompio_buffer_init , 1 ) > 1 )
91
97
return OMPI_SUCCESS ;
92
98
93
99
/* initialize static objects */
94
- OBJ_CONSTRUCT (& mca_common_ompio_cuda_mutex , opal_mutex_t );
100
+ OBJ_CONSTRUCT (& mca_common_ompio_buffer_mutex , opal_mutex_t );
95
101
96
- OPAL_THREAD_LOCK (& mca_common_ompio_cuda_mutex );
102
+ OPAL_THREAD_LOCK (& mca_common_ompio_buffer_mutex );
97
103
/* lookup name of the allocator to use */
98
104
if (NULL == (mca_common_ompio_allocator_component = mca_allocator_component_lookup ("basic" ))) {
99
- OPAL_THREAD_UNLOCK (& mca_common_ompio_cuda_mutex );
105
+ OPAL_THREAD_UNLOCK (& mca_common_ompio_buffer_mutex );
100
106
return OMPI_ERR_BUFFER ;
101
107
}
102
108
103
109
/* create an instance of the allocator */
104
110
mca_common_ompio_allocator = mca_common_ompio_allocator_component -> allocator_init (thread_safe ,
105
- mca_common_ompio_cuda_alloc_seg ,
106
- mca_common_ompio_cuda_free_seg ,
111
+ mca_common_ompio_buffer_alloc_seg ,
112
+ mca_common_ompio_buffer_free_seg ,
107
113
NULL );
108
114
if (NULL == mca_common_ompio_allocator ) {
109
- OPAL_THREAD_UNLOCK (& mca_common_ompio_cuda_mutex );
115
+ OPAL_THREAD_UNLOCK (& mca_common_ompio_buffer_mutex );
110
116
return OMPI_ERR_BUFFER ;
111
117
}
112
118
113
- // mca_common_ompio_pagesize = sysconf(_SC_PAGESIZE);
114
119
mca_common_ompio_pagesize = opal_getpagesize ();
115
120
116
- OPAL_THREAD_UNLOCK (& mca_common_ompio_cuda_mutex );
121
+ OPAL_THREAD_UNLOCK (& mca_common_ompio_buffer_mutex );
117
122
return OMPI_SUCCESS ;
118
123
}
119
124
120
- int mca_common_ompio_cuda_alloc_fini ( void )
125
+ int mca_common_ompio_buffer_alloc_fini ( void )
121
126
{
122
127
if ( NULL != mca_common_ompio_allocator ) {
123
- OPAL_THREAD_LOCK (& mca_common_ompio_cuda_mutex );
128
+ OPAL_THREAD_LOCK (& mca_common_ompio_buffer_mutex );
124
129
mca_common_ompio_allocator -> alc_finalize (mca_common_ompio_allocator );
125
130
mca_common_ompio_allocator = NULL ;
126
- OPAL_THREAD_UNLOCK (& mca_common_ompio_cuda_mutex );
127
- OBJ_DESTRUCT (& mca_common_ompio_cuda_mutex );
131
+ OPAL_THREAD_UNLOCK (& mca_common_ompio_buffer_mutex );
132
+ OBJ_DESTRUCT (& mca_common_ompio_buffer_mutex );
128
133
}
129
134
130
135
return OMPI_SUCCESS ;
@@ -134,31 +139,31 @@ void *mca_common_ompio_alloc_buf ( ompio_file_t *fh, size_t bufsize )
134
139
{
135
140
char * tmp = NULL ;
136
141
137
- if ( !mca_common_ompio_cuda_init ){
138
- mca_common_ompio_cuda_alloc_init ();
142
+ if ( !mca_common_ompio_buffer_init ){
143
+ mca_common_ompio_buffer_alloc_init ();
139
144
}
140
145
141
- OPAL_THREAD_LOCK (& mca_common_ompio_cuda_mutex );
146
+ OPAL_THREAD_LOCK (& mca_common_ompio_buffer_mutex );
142
147
tmp = mca_common_ompio_allocator -> alc_alloc (mca_common_ompio_allocator ,
143
148
bufsize , 0 );
144
- OPAL_THREAD_UNLOCK (& mca_common_ompio_cuda_mutex );
149
+ OPAL_THREAD_UNLOCK (& mca_common_ompio_buffer_mutex );
145
150
return tmp ;
146
151
}
147
152
148
153
void mca_common_ompio_release_buf ( ompio_file_t * fh , void * buf )
149
154
{
150
155
151
- if ( !mca_common_ompio_cuda_init ){
156
+ if ( !mca_common_ompio_buffer_init ){
152
157
/* Should not happen. You can not release a buf without
153
158
** having it allocated first.
154
159
*/
155
160
opal_output (1 , "error in mca_common_ompio_release_buf: allocator not initialized\n" );
156
161
}
157
162
158
- OPAL_THREAD_LOCK (& mca_common_ompio_cuda_mutex );
163
+ OPAL_THREAD_LOCK (& mca_common_ompio_buffer_mutex );
159
164
mca_common_ompio_allocator -> alc_free (mca_common_ompio_allocator ,
160
165
buf );
161
- OPAL_THREAD_UNLOCK (& mca_common_ompio_cuda_mutex );
166
+ OPAL_THREAD_UNLOCK (& mca_common_ompio_buffer_mutex );
162
167
163
168
return ;
164
169
}
0 commit comments