device chunks: their card; host chunks: every card and the CPU. A worker maps the holder's chunks read only: the weights are shared by every later worker, and a stray write by a faulting kernel (CUDA traps none inside an allocation) would poison them for all of them; read only, it faults in the worker that made it
| 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 |
| 63 | void grant(int loc, uint64_t va, size_t size, bool read_only) { |
| 64 | const CUmemAccess_flags prot = read_only ? CU_MEM_ACCESS_FLAGS_PROT_READ : CU_MEM_ACCESS_FLAGS_PROT_READWRITE; |
| 65 | CUmemAccessDesc a[NCARD + 1] = {}; |
| 66 | int n = 0; |
| 67 | for (int c = 0; c < NCARD; ++c) { |
| 68 | if (!is_host(loc) && c != loc) continue; |
| 69 | a[n].location.type = CU_MEM_LOCATION_TYPE_DEVICE; |
| 70 | a[n].location.id = c; |
| 71 | a[n].flags = prot; |
| 72 | ++n; |
| 73 | } |
| 74 | if (is_host(loc)) { |
| 75 | a[n].location = prop_of(loc).location; |
| 76 | a[n].flags = prot; |
| 77 | ++n; |
| 78 | } |
| 79 | cu(cuMemSetAccess((CUdeviceptr) va, size, a, n), "access"); |
| 80 | } |
| 81 | |
| 82 | } // namespace |
| 83 |