| 419 | //------------------------------------------------------------------------------ |
| 420 | |
| 421 | void rmm_wrap_deallocate( void *p, std::size_t size) |
| 422 | { |
| 423 | if (rmm_wrap_context == NULL) return ; |
| 424 | |
| 425 | // Note: there are 3 PANIC cases below. The API of rmm_wrap_deallocate |
| 426 | // does not allow an error condition to be returned. These PANICs could be |
| 427 | // logged, or they could terminate the program if debug mode enabled, etc. |
| 428 | // In production, all we can do is ignore the PANIC. |
| 429 | |
| 430 | if (p == NULL) |
| 431 | { |
| 432 | // nothing to do; ignore a double-free |
| 433 | if (size > 0) |
| 434 | { |
| 435 | // PANIC! Why does a NULL pointer have a nonzero size?? |
| 436 | } |
| 437 | return ; |
| 438 | } |
| 439 | |
| 440 | // check the size given. If the input size is zero, then the |
| 441 | // size is unknown (say rmm_wrap_free(p)). In that case, just trust the |
| 442 | // hashmap. Otherwise, double-check to make sure the size is correct. |
| 443 | alloc_map *am = rmm_wrap_context->size_map.get() ; |
| 444 | size_t actual_size = 0 ; |
| 445 | if (am == NULL) |
| 446 | { |
| 447 | // PANIC! |
| 448 | // std::cout<< "Uh oh, can't deallocate before initializing RMM" |
| 449 | // << std::endl; |
| 450 | return ; |
| 451 | } |
| 452 | else |
| 453 | { |
| 454 | //actual_size = am->at( (std::size_t)(p) ) ; |
| 455 | auto iter = am->find( (std::size_t)(p) ) ; |
| 456 | if (iter != am->end() ) actual_size = iter->second; |
| 457 | else std::cout<< " rmm_wrap:: tried to free unallocated pointer ! " << p ; |
| 458 | } |
| 459 | |
| 460 | if (actual_size == 0) |
| 461 | { |
| 462 | // PANIC! oops, p is not in the hashmap. Ignore it. TODO: could add |
| 463 | // a printf here, write to a log file, etc. if debug mode, abort, etc. |
| 464 | return ; |
| 465 | } |
| 466 | |
| 467 | if (size > 0 && size != actual_size) |
| 468 | { |
| 469 | // PANIC! oops, invalid old size. Ignore the input size, and free p |
| 470 | // anyway. TODO: could add a printf here, write to a log file, etc. |
| 471 | // if debug mode, abort, etc. |
| 472 | } |
| 473 | |
| 474 | // remove p from the hashmap |
| 475 | am->erase ( (std::size_t)(p) ) ; |
| 476 | |
| 477 | // deallocate the block of memory |
| 478 | rmm::mr::device_memory_resource *memoryresource = |