MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / rmm_wrap_realloc

Function rmm_wrap_realloc

deps/GraphBLAS/rmm_wrap/rmm_wrap.cpp:305–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

303// it uses RMM underneath to allocate the space.
304
305void *rmm_wrap_realloc (void *p, std::size_t newsize)
306{
307 if (p == NULL)
308 {
309 // allocate a new block. This is OK.
310 return (rmm_wrap_allocate (&newsize)) ;
311 }
312
313 if (newsize == 0)
314 {
315 // free the block. This OK.
316 rmm_wrap_deallocate (p, 0) ;
317 return (NULL) ;
318 }
319
320 alloc_map *am = rmm_wrap_context->size_map.get() ;
321 std::size_t oldsize = am->at( (std::size_t)(p) ) ;
322
323 if (oldsize == 0)
324 {
325 // the block is not in the hashmap; cannot realloc it.
326 // This is a failure.
327 return (NULL) ;
328 }
329
330 // check for quick return
331 if (newsize >= oldsize/2 && newsize <= oldsize)
332 {
333 // Be lazy. If the block does not change, or is shrinking but only by a
334 // small amount, then leave the block as-is.
335 return (p) ;
336 }
337
338 // allocate the new space
339 void *pnew = rmm_wrap_allocate (&newsize) ;
340 if (pnew == NULL)
341 {
342 // old block is not modified. This is a failure, but the old block is
343 // still in the hashmap.
344 return (NULL) ;
345 }
346
347 // copy the old space into the new space
348 std::size_t s = (oldsize < newsize) ? oldsize : newsize ;
349 // FIXME: query the pointer if it's on the GPU.
350 memcpy (pnew, p, s) ; // NOTE: single-thread CPU, not GPU. Slow!
351
352 // free the old space
353 rmm_wrap_deallocate (p, oldsize) ;
354
355 // return the new space
356 return (pnew) ;
357}
358
359//------------------------------------------------------------------------------
360// rmm_wrap_free: free a block of memory, size not needed

Callers

nothing calls this directly

Calls 2

rmm_wrap_allocateFunction · 0.85
rmm_wrap_deallocateFunction · 0.85

Tested by

no test coverage detected