static bool fini_streams_for_device (struct ptx_device *ptx_dev) { free (ptx_dev->async_streams.arr); bool ret = true; while (ptx_dev->active_streams != NULL) { struct ptx_stream *s = ptx_dev->active_streams; ptx_dev->active_streams = ptx_dev->active_streams->next; ret &= map_fini (s); CUresult r = cuStreamDestroy (s->stream); if (r != CUDA_SUCCESS) { GOMP_PLUGIN_error ("cuStreamDestroy error: %s", cuda_error (r)); ret = false; } free (s); } ret &= map_fini (ptx_dev->null_stream); free (ptx_dev->null_stream); return ret; }
int map_load(track_proc_t *proc) { map_t *map = &proc->map; map_t new_map; map_entry_t *old_entry; int i; if (!map->loaded) { if (map_read(proc->pid, map) != 0) { return (-1); } return (0); } if (map_read(proc->pid, &new_map) != 0) { return (-1); } for (i = 0; i < new_map.nentry_cur; i++) { if ((old_entry = map_entry_find(proc, new_map.arr[i].start_addr, new_map.arr[i].end_addr - new_map.arr[i].start_addr)) == NULL) { new_map.arr[i].need_resolve = B_TRUE; } else { new_map.arr[i].need_resolve = old_entry->need_resolve; } } map_fini(&proc->map); memcpy(&proc->map, &new_map, sizeof (map_t)); return (0); }
static void fini_streams_for_device (struct ptx_device *ptx_dev) { free (ptx_dev->async_streams.arr); while (ptx_dev->active_streams != NULL) { struct ptx_stream *s = ptx_dev->active_streams; ptx_dev->active_streams = ptx_dev->active_streams->next; map_fini (s); cuStreamDestroy (s->stream); free (s); } map_fini (ptx_dev->null_stream); free (ptx_dev->null_stream); }
void vmm_mdestroy(PROCESS *prp) { ADDRESS *adp; if((prp == NULL) || (prp->pid == SYSMGR_PID)) { crash(); } adp = prp->memory; if(adp != NULL) { pathmgr_object_done(adp->anon); cpu_vmm_mdestroy(prp); (void)map_fini(&adp->map); prp->memory = NULL; } }
static int nvptx_set_cuda_stream (int async, void *stream) { struct ptx_stream *oldstream; pthread_t self = pthread_self (); struct nvptx_thread *nvthd = nvptx_thread (); if (async < 0) GOMP_PLUGIN_fatal ("bad async %d", async); pthread_mutex_lock (&nvthd->ptx_dev->stream_lock); /* We have a list of active streams and an array mapping async values to entries of that list. We need to take "ownership" of the passed-in stream, and add it to our list, removing the previous entry also (if there was one) in order to prevent resource leaks. Note the potential for surprise here: maybe we should keep track of passed-in streams and leave it up to the user to tidy those up, but that doesn't work for stream handles returned from acc_get_cuda_stream above... */ oldstream = select_stream_for_async (async, self, false, NULL); if (oldstream) { if (nvthd->ptx_dev->active_streams == oldstream) nvthd->ptx_dev->active_streams = nvthd->ptx_dev->active_streams->next; else { struct ptx_stream *s = nvthd->ptx_dev->active_streams; while (s->next != oldstream) s = s->next; s->next = s->next->next; } CUDA_CALL_ASSERT (cuStreamDestroy, oldstream->stream); if (!map_fini (oldstream)) GOMP_PLUGIN_fatal ("error when freeing host memory"); free (oldstream); } pthread_mutex_unlock (&nvthd->ptx_dev->stream_lock); (void) select_stream_for_async (async, self, true, (CUstream) stream); return 1; }
static int map_read(pid_t pid, map_t *map) { char path[PATH_MAX]; char line[MAPFILE_LINE_SIZE]; char addr_str[128], attr_str[128], off_str[128]; char fd_str[128], inode_str[128], path_str[PATH_MAX]; char s1[64], s2[64]; uint64_t start_addr, end_addr; unsigned int attr; int nargs, nadded = 0, ret = -1; FILE *fp; memset(map, 0, sizeof (map_t)); snprintf(path, sizeof (path), "/proc/%d/maps", pid); if ((fp = fopen(path, "r")) == NULL) { return (-1); } while (1) { if (fgets(line, sizeof (line), fp) == NULL) { break; } /* * e.g. 00400000-00405000 r-xp 00000000 fd:00 678793 /usr/bin/vmstat */ if ((nargs = sscanf(line, "%127[^ ] %127[^ ] %127[^ ] %127[^ ] %127[^ ] %4095[^\n]", addr_str, attr_str, off_str, fd_str, inode_str, path_str)) < 0) { goto L_EXIT; } /* * split to start_addr and end_addr. * e.g. 00400000-00405000 -> start_addr = 00400000, end_addr = 00405000. */ if (sscanf(addr_str, "%63[^-]", s1) <= 0) { goto L_EXIT; } if (sscanf(addr_str, "%*[^-]-%63s", s2) <= 0) { goto L_EXIT; } start_addr = strtoull(s1, NULL, 16); end_addr = strtoull(s2, NULL, 16); /* * Convert to the attribute bitmap */ attr = attr_bitmap(attr_str); /* * Path could be null, need to check here. */ if (nargs != 6) { path_str[0] = 0; } if (map_entry_add(map, start_addr, end_addr, attr, path_str) != 0) { goto L_EXIT; } nadded++; } if (nadded > 0) { map->loaded = B_TRUE; ret = 0; } L_EXIT: fclose(fp); if ((ret != 0) && (nadded > 0)) { map_fini(map); } return (ret); }