SHARE
TWEET

cudadump

a guest Apr 27th, 2010 640 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*! \file cudadump.c
  2.   \author Travis Goodspeed
  3.   \brief Ugly hack of a CUDA PTX Dumper
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8.  
  9. //Large buffer
  10. #define BUFLEN 0x400000
  11.  
  12. //! Dumps CUDA scripts from a file.
  13. int main(int argc, char **argv){
  14.   char buf[BUFLEN];
  15.   char c;
  16.   const char *ptx;
  17.   long count=0;
  18.   long found=0;
  19.  
  20.   fprintf(stderr,"USAGE:\n\t./cudadump <tests/gpuspy >app.ptx\n");
  21.  
  22.   //Look for PTX strings.
  23.   while(!feof(stdin)){
  24.     buf[count++]=c=fgetc(stdin);
  25.     buf[count+1]=0;
  26.     if(!c){ //End of C string
  27.       count=0;
  28.       ptx=strstr(buf,".version");
  29.       if(ptx){
  30.         printf("%s\n",ptx);
  31.         found++;
  32.       }
  33.       buf[0]=0;
  34.     }
  35.     //Reset if nothing promising after half buffer.
  36.     if(count>(BUFLEN>>1) && !strstr(buf,".version"))
  37.       count=0;
  38.     //Warn if buffer blown.
  39.     if(count>BUFLEN-1){
  40.       count=0;
  41.       printf("// Buffer exceeded.  Might have lost a PTX.\n");
  42.       fprintf(stderr,
  43.               "// Buffer exceeded.  Might have lost a PTX.\n");
  44.     }
  45.   }
  46.   printf("// Found %li PTX assemblies.\n",found);
  47.   return 0;
  48. }
RAW Paste Data
Want to get better at C++?
Learn to code C++ in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top