@ -20,6 +20,12 @@ limitations under the License. */
# include "paddle/fluid/memory/detail/system_allocator.h"
# include "paddle/fluid/platform/gpu_info.h"
DEFINE_bool ( init_allocated_mem , false ,
" It is a mistake that the values of the memory allocated by "
" BuddyAllocator are always zeroed in some op's implementation. "
" To find this error in time, we use init_allocated_mem to indicate "
" that initializing the allocated memory with a small value "
" during unit testing. " ) ;
DECLARE_double ( fraction_of_gpu_memory_to_use ) ;
namespace paddle {
@ -41,6 +47,9 @@ template <>
void * Alloc < platform : : CPUPlace > ( platform : : CPUPlace place , size_t size ) {
VLOG ( 10 ) < < " Allocate " < < size < < " bytes on " < < platform : : Place ( place ) ;
void * p = GetCPUBuddyAllocator ( ) - > Alloc ( size ) ;
if ( FLAGS_init_allocated_mem ) {
memset ( p , 0xEF , size ) ;
}
VLOG ( 10 ) < < " pointer= " < < p ;
return p ;
}
@ -104,6 +113,9 @@ void* Alloc<platform::CUDAPlace>(platform::CUDAPlace place, size_t size) {
LOG ( WARNING ) < < " GPU memory used: " < < Used < platform : : CUDAPlace > ( place ) ;
platform : : SetDeviceId ( cur_dev ) ;
}
if ( FLAGS_init_allocated_mem ) {
cudaMemset ( ptr , 0xEF , size ) ;
}
return ptr ;
}
@ -137,6 +149,9 @@ void* Alloc<platform::CUDAPinnedPlace>(platform::CUDAPinnedPlace place,
LOG ( WARNING ) < < " cudaMallocHost Cannot allocate " < < size
< < " bytes in CUDAPinnedPlace " ;
}
if ( FLAGS_init_allocated_mem ) {
memset ( ptr , 0xEF , size ) ;
}
return ptr ;
}