Пример #1
0
int main(int argc, char **argv)
{
    gflags::ParseCommandLineFlags(&argc, &argv, true);
    
    printf("Inter-GPU bi-directional memory exhange test\n");
    
    int ndevs = 0;
    CUDA_CHECK(cudaGetDeviceCount(&ndevs));

    if (FLAGS_from >= ndevs)
    {
        printf("Invalid --from flag. Only %d GPUs are available.\n", ndevs);
        return 1;
    }
    if (FLAGS_to >= ndevs)
    {
        printf("Invalid --to flag. Only %d GPUs are available.\n", ndevs);
        return 2;
    }
    
    printf("Enabling peer-to-peer access\n");
    
    // Enable peer-to-peer access       
    for(int i = 0; i < ndevs; ++i)
    {
        CUDA_CHECK(cudaSetDevice(i));
        for(int j = 0; j < ndevs; ++j)
            if (i != j)
                cudaDeviceEnablePeerAccess(j, 0);
    } 

    printf("GPUs: %d\n", ndevs);
    printf("Data size: %.2f MB\n", (FLAGS_size / 1024.0f / 1024.0f));
    printf("Repetitions: %d\n", (int)FLAGS_repetitions);
    printf("\n");
    
    for(int i = 0; i < ndevs; ++i)
    {
        // Skip source GPUs
        if(FLAGS_from >= 0 && i != FLAGS_from)
            continue;
        
        for(int j = i; j < ndevs; ++j)
        {
            // Skip self-copies
            if(i == j)
                continue;
            // Skip target GPUs
            if(FLAGS_to >= 0 && j != FLAGS_to)
                continue;

            printf("Exchanging between GPU %d and GPU %d: ", i, j);

            CopySegment(i, j);
        }
    }

    return 0;
}
Пример #2
0
List *
GetVirtualSegmentList(void)
{
#if 0
	List	*real_segments = GetSegmentList();
	int		real_segment_num = list_length(real_segments);
	Segment *dest;
	Segment *src;

	src = linitial(real_segments);
	dest = CopySegment(src);
	dest->id = real_segment_num;
	dest->dbid = real_segment_num + 1;

	return lappend(real_segments, dest);
#else
	return GetSegmentList();
#endif
}
Пример #3
0
/* basename_from_path() parses hostport_abs_path
 * to get name.
 * If there are no path segments in abs_path, name is the host.
 * Otherwise if the host is NOT idisk.mac.com OR abs_path is
 * only one segment, name is the last path segment.
 * Otherwise (host is idisk.mac.com AND there are multiple
 * path segements), name is the first path segment concatenated
 * with the last path segment separated with a dash character.
 * name is assumed to be char[MAXNAMLEN].
 */
static int
basename_from_path(const char *hostport_abs_path, char *name, size_t maxlength)
{
    int		error;
    char	*path;
    char	*host;
    char	*firstPathSegment;
    char	*lastPathSegment;
    int		length;
    char	*colon;
    char	*slash;
    char	*firstChar;
    char	*lastChar;
    
    error = 0;
    path = host = firstPathSegment = lastPathSegment = NULL;
    
    /* validate input parameters */
    if ( (hostport_abs_path == NULL) || (name == NULL) ) {
		error = EINVAL;
		goto exit;
    }
    
    /* no output name yet */
    *name = '\0';
	
    /* get length of input */
    length = strlen(hostport_abs_path);
    if ( length == 0 ) {
		error = EINVAL;
		goto exit;
    }
	
    /* allocate space for path */
    path = malloc(length + 2); /* one extra for slash if needed */
    if ( path == NULL ) {
		error = ENOMEM;
		goto exit;
    }
    /* and make a private copy of hostport_abs_path*/
    strlcpy(path, hostport_abs_path, length + 2);
	
    /* add a trailing slash if needed */
    if ( path[length] != '/' ) {
		strlcat(path, "/", length + 2);
    }
    
    /* find the first colon (if any) and the first slash */
    colon = strchr(path, ':');
    slash = strchr(path, '/');
    
    /* get the host name */
    if ( (colon == NULL) || (colon > slash) ) {
		/* if no colon, or the colon is after the slash,
		 * then there is no port so the host is everything
		 * up to the slash
		 */
		host = CopySegment(path, slash);
    } else {
		/* there is a port so the host is everything
		 * up to the colon
		 */
		host = CopySegment(path, colon);
    }
    
    /* find first path segment (if any) */
    lastChar = slash;
    ParsePathSegment(lastChar, &firstChar, &lastChar);
    if (firstChar != lastChar) {
		/* copy first path segment */
		firstPathSegment = CopySegment(firstChar, lastChar);
		percent_decode_in_place(firstPathSegment);
		
		/* find last path segment (if any) */
		while ( *lastChar != '\0' ) {
			ParsePathSegment(lastChar, &firstChar, &lastChar);
			if (firstChar != lastChar) {
				if  ( lastPathSegment != NULL ) {
					/* free up the previous lastPathSegment */
					free(lastPathSegment);
				}
				/* copy (new) last path segment */
				lastPathSegment = CopySegment(firstChar, lastChar);
			}
		}
		
		if ( lastPathSegment != NULL ) {
			percent_decode_in_place(lastPathSegment);
			/* name is lastPathSegment */
			if ( (strlen(lastPathSegment) + 1) > MAXNAMLEN ) {
					error = ENAMETOOLONG;
					goto exit;
			}
				
			strlcpy(name, lastPathSegment, maxlength);
		} else {
			/* no last path segment -- name is firstPathSegment*/
			if ( (strlen(firstPathSegment) + 1) > MAXNAMLEN ) {
				error = ENAMETOOLONG;
				goto exit;
			}
			
			strlcpy(name, firstPathSegment, maxlength);
		}
    } else {
		/* no path segments -- name is host */
		if ( (strlen(host) + 1) > MAXNAMLEN ) {
			error = ENAMETOOLONG;
			goto exit;
		}
		
		strlcpy(name, host, maxlength);
    }
	
exit:
    /* free up any memory and return any errors */
    if ( path != NULL ) {
		free(path);
    }
    if ( host != NULL ) {
		free(host);
    }
    if ( firstPathSegment != NULL ) {
		free(firstPathSegment);
    }
    if ( lastPathSegment != NULL ) {
		free(lastPathSegment);
    }
    return ( error );
}