Permalink
Browse files

Merge remote-tracking branch 'origin/gdev-axe'

  • Loading branch information...
2 parents c022193 + 3de281a commit 8001f7231cb1e31ea1e5519644e27fa83f47b8c3 @shinpei0208 shinpei0208 committed Jul 22, 2013
Showing with 39 additions and 3 deletions.
  1. +39 −3 cuda/driver/gdev_cuda.c
View
42 cuda/driver/gdev_cuda.c
@@ -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;
}

0 comments on commit 8001f72

Please sign in to comment.