99 * University of Stuttgart. All rights reserved.
1010 * Copyright (c) 2004-2005 The Regents of the University of California.
1111 * 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.
1313 * $COPYRIGHT$
1414 *
1515 * Additional copyrights may follow
2727#include "opal/mca/allocator/allocator.h"
2828#include "opal/mca/allocator/base/base.h"
2929#include "common_ompio.h"
30- #include "common_ompio_cuda .h"
30+ #include "common_ompio_buffer .h"
3131
3232
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 */
3434static mca_allocator_base_component_t * mca_common_ompio_allocator_component = NULL ;
3535static mca_allocator_base_module_t * mca_common_ompio_allocator = NULL ;
3636
37- static opal_atomic_int32_t mca_common_ompio_cuda_init = 0 ;
37+ static opal_atomic_int32_t mca_common_ompio_buffer_init = 0 ;
3838static 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 );
4141
42+ #if OPAL_CUDA_SUPPORT
4243void mca_common_ompio_check_gpu_buf ( ompio_file_t * fh , const void * buf , int * is_gpu ,
4344 int * is_managed )
4445{
@@ -57,8 +58,9 @@ void mca_common_ompio_check_gpu_buf ( ompio_file_t *fh, const void *buf, int *is
5758
5859 return ;
5960}
61+ #endif
6062
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 )
6264{
6365 char * buf = NULL ;
6466 size_t realsize , numpages ;
@@ -67,64 +69,67 @@ static void* mca_common_ompio_cuda_alloc_seg ( void*ctx, size_t *size )
6769 realsize = numpages * mca_common_ompio_pagesize ;
6870
6971 buf = malloc ( realsize );
72+ #if OPAL_CUDA_SUPPORT
7073 if ( NULL != buf ) {
7174 mca_common_cuda_register ( ( char * )buf , realsize , NULL );
7275 }
76+ #endif
7377 * size = realsize ;
7478 return buf ;
7579}
7680
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 )
7882{
7983 if ( NULL != buf ) {
84+ #if OPAL_CUDA_SUPPORT
8085 mca_common_cuda_unregister ( (char * ) buf , NULL );
86+ #endif
8187 free ( buf );
8288 }
8389 return ;
8490}
8591
86- int mca_common_ompio_cuda_alloc_init ( void )
92+ int mca_common_ompio_buffer_alloc_init ( void )
8793{
8894 bool thread_safe = true;
8995
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 )
9197 return OMPI_SUCCESS ;
9298
9399 /* 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 );
95101
96- OPAL_THREAD_LOCK (& mca_common_ompio_cuda_mutex );
102+ OPAL_THREAD_LOCK (& mca_common_ompio_buffer_mutex );
97103 /* lookup name of the allocator to use */
98104 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 );
100106 return OMPI_ERR_BUFFER ;
101107 }
102108
103109 /* create an instance of the allocator */
104110 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 ,
107113 NULL );
108114 if (NULL == mca_common_ompio_allocator ) {
109- OPAL_THREAD_UNLOCK (& mca_common_ompio_cuda_mutex );
115+ OPAL_THREAD_UNLOCK (& mca_common_ompio_buffer_mutex );
110116 return OMPI_ERR_BUFFER ;
111117 }
112118
113- // mca_common_ompio_pagesize = sysconf(_SC_PAGESIZE);
114119 mca_common_ompio_pagesize = opal_getpagesize ();
115120
116- OPAL_THREAD_UNLOCK (& mca_common_ompio_cuda_mutex );
121+ OPAL_THREAD_UNLOCK (& mca_common_ompio_buffer_mutex );
117122 return OMPI_SUCCESS ;
118123}
119124
120- int mca_common_ompio_cuda_alloc_fini ( void )
125+ int mca_common_ompio_buffer_alloc_fini ( void )
121126{
122127 if ( NULL != mca_common_ompio_allocator ) {
123- OPAL_THREAD_LOCK (& mca_common_ompio_cuda_mutex );
128+ OPAL_THREAD_LOCK (& mca_common_ompio_buffer_mutex );
124129 mca_common_ompio_allocator -> alc_finalize (mca_common_ompio_allocator );
125130 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 );
128133 }
129134
130135 return OMPI_SUCCESS ;
@@ -134,31 +139,31 @@ void *mca_common_ompio_alloc_buf ( ompio_file_t *fh, size_t bufsize )
134139{
135140 char * tmp = NULL ;
136141
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 ();
139144 }
140145
141- OPAL_THREAD_LOCK (& mca_common_ompio_cuda_mutex );
146+ OPAL_THREAD_LOCK (& mca_common_ompio_buffer_mutex );
142147 tmp = mca_common_ompio_allocator -> alc_alloc (mca_common_ompio_allocator ,
143148 bufsize , 0 );
144- OPAL_THREAD_UNLOCK (& mca_common_ompio_cuda_mutex );
149+ OPAL_THREAD_UNLOCK (& mca_common_ompio_buffer_mutex );
145150 return tmp ;
146151}
147152
148153void mca_common_ompio_release_buf ( ompio_file_t * fh , void * buf )
149154{
150155
151- if ( !mca_common_ompio_cuda_init ){
156+ if ( !mca_common_ompio_buffer_init ){
152157 /* Should not happen. You can not release a buf without
153158 ** having it allocated first.
154159 */
155160 opal_output (1 , "error in mca_common_ompio_release_buf: allocator not initialized\n" );
156161 }
157162
158- OPAL_THREAD_LOCK (& mca_common_ompio_cuda_mutex );
163+ OPAL_THREAD_LOCK (& mca_common_ompio_buffer_mutex );
159164 mca_common_ompio_allocator -> alc_free (mca_common_ompio_allocator ,
160165 buf );
161- OPAL_THREAD_UNLOCK (& mca_common_ompio_cuda_mutex );
166+ OPAL_THREAD_UNLOCK (& mca_common_ompio_buffer_mutex );
162167
163168 return ;
164169}
0 commit comments