1

私はできる構造を持っています

  struct type1{ double a,b,c;}

またはそれはすることができます

  struct type2{ double a,b,c,d,e;}

cudaコードの私のホスト関数には、次のようなものがあります

  void compute(){
      // some code
      // data on devices (up to 10) 
      type *xxx[10];   // this is where i want either type1 or type2 structures
                       // the "type" is not known at compile time but i want to 
                       // determine at runtime based on some input variable. this 
                       // part is not real code rather this is what i want to achive.

      int DevUsed;    // some code to give value to int DevUsed

      for(int idev=0;idev<DevUsed;idev++){

           // set cuda device

          if ( cudaMalloc(&xxx[iDev], sizeof(type)) != cudaSuccess )
            // print error message;
          cudaMemcpy(xxx[iDev], pIF1, sizeof(type), cudaMemcpyHostToDevice);

          function2<<<grid, block>>>(xxx[iDev]);  // where function2 is the kernel
       }
   }

私の質問は、「type *xxx[10];」のような汎用コードで type1 と type2 のデータ構造体を選択する方法は何かということです。

4

1 に答える 1