| 41 | bool is_host(int loc) { return loc >= NCARD; } |
| 42 | int card_of(int loc) { return loc % NCARD; } |
| 43 | CUmemAllocationProp prop_of(int loc) { |
| 44 | CUmemAllocationProp p{}; |
| 45 | p.type = CU_MEM_ALLOCATION_TYPE_PINNED; |
| 46 | p.requestedHandleTypes = CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR; |
| 47 | if (is_host(loc)) { |
| 48 | CUdevice d; |
| 49 | cu(cuDeviceGet(&d, card_of(loc)), "device"); |
| 50 | int numa = 0; |
| 51 | cu(cuDeviceGetAttribute(&numa, CU_DEVICE_ATTRIBUTE_HOST_NUMA_ID, d), "host NUMA id"); |
| 52 | p.location.type = CU_MEM_LOCATION_TYPE_HOST_NUMA; |
| 53 | p.location.id = numa < 0 ? 0 : numa; |
| 54 | } else { |
| 55 | p.location.type = CU_MEM_LOCATION_TYPE_DEVICE; |
| 56 | p.location.id = loc; |
| 57 | } |
| 58 | return p; |
| 59 | } |
| 60 | // device chunks: their card; host chunks: every card and the CPU. A worker maps the holder's chunks read only: the |
| 61 | // weights are shared by every later worker, and a stray write by a faulting kernel (CUDA traps none inside an |
| 62 | // allocation) would poison them for all of them; read only, it faults in the worker that made it |