Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /trunk/src/lib/cl-target/main.c
ViewVC logotype

Diff of /trunk/src/lib/cl-target/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2108, Sun Dec 9 19:54:32 2012 UTC revision 2109, Fri Dec 14 20:01:33 2012 UTC
# Line 61  Line 61 
61     cl_mem       statusMem;     cl_mem       statusMem;
62  } KernelArgs_t;  } KernelArgs_t;
63    
64  static bool InitCL (CLInfo_t *clInfo, Diderot_World_t *wrld);  static bool InitCL (CLInfo_t *clInfo, Diderot_World_t *wrld, int devID);
65  static void CheckErrorCode (cl_int sts, const char * msg);  static void CheckErrorCode (cl_int sts, const char * msg);
66  static void SetPhase1Args (cl_kernel kernel, int *argCount, KernelArgs_t *args);  static void SetPhase1Args (cl_kernel kernel, int *argCount, KernelArgs_t *args);
67  static void SetPhase2Args (cl_kernel kernel, int *argCount, KernelArgs_t *args, int blk_sz);  static void SetPhase2Args (cl_kernel kernel, int *argCount, KernelArgs_t *args, int blk_sz);
# Line 86  Line 86 
86      Diderot_InitGlobals ();      Diderot_InitGlobals ();
87    
88      Diderot_int_t nWorkersPerCU = 4;      Diderot_int_t nWorkersPerCU = 4;
89        Diderot_int_t gpuDevID = -1;
90      Diderot_Options_t *opts = Diderot_OptNew ();      Diderot_Options_t *opts = Diderot_OptNew ();
91      Diderot_OptAddInt (opts, "np", "specify number of workers/CU", &nWorkersPerCU, true);      Diderot_OptAddInt (opts, "np", "specify number of workers/CU", &nWorkersPerCU, true);
92        Diderot_OptAddInt (opts, "devno", "specify GPU device ID", &gpuDevID, true);
93      Diderot_RegisterGlobalOpts (opts);      Diderot_RegisterGlobalOpts (opts);
94      Diderot_OptProcess (opts, argc, argv);      Diderot_OptProcess (opts, argc, argv);
95      Diderot_OptFree (opts);      Diderot_OptFree (opts);
# Line 97  Line 99 
99    
100      Diderot_World_t *wrld = Diderot_Initially ();  // this may not be right for OpenCL      Diderot_World_t *wrld = Diderot_Initially ();  // this may not be right for OpenCL
101    
102      if (! InitCL(clInfo, wrld))      if (! InitCL(clInfo, wrld, gpuDevID))
103          exit (1);          exit (1);
104    
105    // set the number of work groups    // set the number of work groups
# Line 446  Line 448 
448   *  \param wrld the Diderot execution information.   *  \param wrld the Diderot execution information.
449   *  \return true if initialization is successful, otherwise false.   *  \return true if initialization is successful, otherwise false.
450   */   */
451  static bool InitCL (CLInfo_t *clInfo, Diderot_World_t *wrld)  static bool InitCL (CLInfo_t *clInfo, Diderot_World_t *wrld, int devID)
452  {  {
453      cl_int              sts;      cl_int              sts;
454      int                 pltIx = 0;  // main patform index      int                 pltIx = 0;  // main patform index
455        DeviceInfo_t        *dev = 0;
456    
457        if ((0 <= devID) && (devID < clInfo->platforms[pltIx].numDevices)) {
458          // use the user supplied device
459            if (isGPUDevice (&(clInfo->platforms[pltIx].devices[devID]))
460            &&  clInfo->platforms[pltIx].devices[devID].isAvail) {
461                dev = &(clInfo->platforms[pltIx].devices[devID]);
462            }
463            else {
464                fprintf (stderr, "specified OpenCL device %d is not a GPU or not available\n", devID);
465                return false;
466            }
467        }
468        else {
469    // find a GPU on platform[0]    // find a GPU on platform[0]
470      DeviceInfo_t *dev = 0;          for (int i = 0;  i < clInfo->platforms[pltIx].numDevices;  i++) {
     int i;  
     for (i = 0;  i < clInfo->platforms[pltIx].numDevices;  i++) {  
471          if (isGPUDevice (&(clInfo->platforms[pltIx].devices[i]))          if (isGPUDevice (&(clInfo->platforms[pltIx].devices[i]))
472          &&  clInfo->platforms[pltIx].devices[i].isAvail) {          &&  clInfo->platforms[pltIx].devices[i].isAvail) {
473                    devID = i;
474              dev = &(clInfo->platforms[pltIx].devices[i]);              dev = &(clInfo->platforms[pltIx].devices[i]);
475              break;              break;
476          }          }
477      }      }
   
478      if (dev == 0) {      if (dev == 0) {
479          fprintf (stderr, "unable to find GPU device\n");          fprintf (stderr, "unable to find GPU device\n");
480          return false;          return false;
481      }      }
482        }
483    
484      if (VerboseFlg) {      if (VerboseFlg) {
485          fprintf (stderr, "using platform %d, device %d: %s\n",          fprintf (stderr, "using platform %d, device %d: %s\n",
486              pltIx, i, clInfo->platforms[0].devices[i].name);              pltIx, devID, dev->name);
487      }      }
488    
489    // create the context    // create the context

Legend:
Removed from v.2108  
changed lines
  Added in v.2109

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0