Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/gdev-axe'
Browse files Browse the repository at this point in the history
  • Loading branch information
shinpei0208 committed Jul 22, 2013
2 parents c022193 + 3de281a commit 8001f72
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions cuda/driver/gdev_cuda.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,18 +684,54 @@ static int save_ptx(char *ptx_file, const char *image)
return 0;
}

#include <ctype.h>
#define _TARGET ".target"

static int assemble_ptx(char *cubin_file, const char *ptx_file)
{
char command[256];
char buffer[256];
int fd;
FILE *fp;
char *p;
char arch[64];

fd = mkstemp(cubin_file);
if (fd < 0)
return -ENOENT;

sprintf(command, "ptxas --gpu-name sm_20 -o %s %s", cubin_file, ptx_file);
if ((fp = fopen(ptx_file, "r")) == NULL)
return -ENOENT;

memset(arch, 0, sizeof(arch));

while (!feof(fp) && !ferror(fp)) {
fgets(buffer, sizeof(buffer), fp);
if (strncmp(buffer, _TARGET, sizeof(_TARGET) - 1) == 0) {
p = buffer + sizeof(_TARGET) - 1;
if (isspace(*p++)) {
while(isspace(*p))
p++;
strncpy(arch, p, sizeof(arch) - 1);
p = arch + strlen(arch) - 1;
while (isspace(*p)) {
*p = '\0';
if (p-- == arch)
break;
}
break;
}
}
}

fclose(fp);

if (!arch[0])
return -ENOENT;

snprintf(buffer, sizeof(buffer), "ptxas --gpu-name %s -o %s %s",
arch, cubin_file, ptx_file);

system(command);
system(buffer);

return 0;
}
Expand Down

0 comments on commit 8001f72

Please sign in to comment.