problème cuPrintf

J’essaye de copier un tableau de struct sur device.Je travaille avec un atm de GPU et j’ai un problème avec la fonction cuPrintf que j’utilise pour déboguer mon code

Ma définition de struct est comme ci-dessous:

struct Node { char Key[25]; char ConsAlterKey[25]; char MasterKey[3]; int VowelDeletion; char Data[6]; char MasterData[6]; int Children[35]; int ChildCount; }; 

et à des fins de test, je remplis le tableau struct comme ceci:

 void FillArray(Node *NodeArray) { for(int i=0;i<TotalNodeCount;i++) { strcpy(NodeArray[i].Key,"Key"); strcpy(NodeArray[i].ConsAlterKey,"ConsAlterKey"); strcpy(NodeArray[i].MasterKey,"Mk"); NodeArray[i].VowelDeletion=0; strcpy(NodeArray[i].Data,"Data"); strcpy(NodeArray[i].MasterData,"Mdata"); NodeArray[i].ChildCount=5; for(int j =0;j<NodeArray[i].ChildCount;j++) { NodeArray[i].Children[j]=i+j; } } } 

ma fonction principale ressemble à ceci:

 int main() { Node *NodeArray; Node *GpuTree; int tokenCount=0; int *tokenCountGPU; NodeArray =(Node *)malloc(sizeof(Node)*(TotalNodeCount)); FillArray(NodeArray); printf("Filling test : %s\n", NodeArray[13].Key); gpuAssert(cudaMalloc( (void**)&GpuTree, sizeof(Node)*(TotalNodeCount))); gpuAssert(cudaMemcpy(GpuTree, NodeArray,sizeof(Node)*(TotalNodeCount), cudaMemcpyHostToDevice)); //test value tokenCount=35; gpuAssert( cudaMalloc((void **)&tokenCountGPU, sizeof(int)) ); gpuAssert( cudaMemcpy(tokenCountGPU, &tokenCount, sizeof(int), cudaMemcpyHostToDevice) ); cudaPrintfInit(); Test <<>> (GpuTree,tokenCountGPU); cudaPrintfDisplay(stdout, true); cudaPrintfEnd(); gpuAssert( cudaGetLastError() ); //TODO:free pointers return(0); } 

et si j’écris test fonction comme ci-dessous:

 __global__ void Test(Node *Trie,int *tokenCount) { if (threadIdx.x < *tokenCount) { cuPrintf("%s\n",Trie[threadIdx.x].Key); } return; } 

Je reçois une sortie comme ceci:

 Filling test : Key [0, 0]: < [0, 1]: ¶☺! [0, 2]: ì☺! [0, 3]: Ä☻! [0, 4]: o♥! [0, 5]: t♦! [0, 6]: L♣! [0, 7]: $♠! [0, 8]: ü♠! [0, 9]: Ô! [0, 10]: ! [0, 11]: " [0, 12]: \ ! [0, 13]: 4♂! [0, 14]: ♀♀! [0, 15]: ä♀! !0, 16]: ¼ [0, 17]: "♫! [0, 18]: l☼! [0, 19]: D►! [0, 20]: ∟◄! [0, 21]: ô◄! [0, 22]: Ì↕! [0, 23]: ¤‼! [0, 24]: |¶! [0, 25]: T§! [0, 26]: ,▬! [0, 27]: ♦↨! [0, 28]: Ü↨! [0, 29]: ´↑! [0, 30]: O↓! [0, 31]: d→! [0, 32]: <←! [0, 33]: ¶∟! [0, 34]: ì∟! 

mais si je change ma méthode de test à ceci:

 __global__ void Test(Node *Trie,int *tokenCount) { if (threadIdx.x < *tokenCount) { cuPrintf("%c%c%c\n", Trie[threadIdx.x].Key[0], Trie[threadIdx.x].Key[1], Trie[threadIdx.x].Key[2]); } return; } 

alors j’obtiens la sortie correcte:

 Filling test : Key [0, 0]: Key [0, 1]: Key [0, 2]: Key [0, 3]: Key [0, 4]: Key [0, 5]: Key [0, 6]: Key [0, 7]: Key [0, 8]: Key [0, 9]: Key [0, 10]: Key [0, 11]: Key [0, 12]: Key [0, 13]: Key [0, 14]: Key [0, 15]: Key [0, 16]: Key [0, 17]: Key [0, 18]: Key [0, 19]: Key [0, 20]: Key [0, 21]: Key [0, 22]: Key [0, 23]: Key [0, 24]: Key [0, 25]: Key [0, 26]: Key [0, 27]: Key [0, 28]: Key [0, 29]: Key [0, 30]: Key [0, 31]: Key [0, 32]: Key [0, 33]: Key [0, 34]: Key 

La question est donc de savoir pourquoi la sortie est corrompue lorsque j’essaie d’imprimer des chaînes en utilisant “% s”.


Le problème est donc résolu. On dirait que c’est à cause des limitations de cuPrintf. Et en fait, je n’étais pas au courant. Merci.

Voici un petit test:

 __global__ void Test(Node *Trie,int *tokenCount) { const char *Key="Key"; char *KeyPointer="Key"; char KeyArray[4]="Key"; cuPrintf("Constant : %s - Array :%s - Pointer : %s - Casting Pointer : %s - Casting Array : %s\n",Key, KeyArray,KeyPointer,(const char *)KeyPointer,(const char *)KeyArray); //cuPrintf("%s\n",Trie[threadIdx.x].Key); //cuPrintf("%d\n",*tokenCount); } 

Donne la sortie:

  [0, 0]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 1]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 2]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 3]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 4]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 5]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 6]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 7]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 8]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 9]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 10]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 11]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 12]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 13]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 14]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 15]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 16]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 17]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 18]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 19]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 20]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 21]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 22]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 23]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 24]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 25]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 26]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 27]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 28]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 29]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 30]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 31]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 32]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 33]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key [0, 34]: Constant : Key - Array : - Pointer : ♀ - Casting Pointer : Key - Casting Array : Key 

cuPrintf documentation de cuPrintf (un fichier lisez- cuPrintf se trouve dans C / src / simplePrintf / doc / cuPrintf_readme.htm à partir du répertoire de base où vous avez installé le SDK):

Il existe des limitations / problèmes connus sur l’utilisation de cuPrintf , le numéro 2 répond à votre question:

Limitations / problèmes connus

Actuellement, les limitations et ressortingctions suivantes s’appliquent à cuPrintf:

  1. La taille de la mémoire tampon est arrondie au facteur 256 le plus proche.
  2. Les arguments associés aux spécificateurs de format de chaîne «% s» doivent être de type (const char *).
  3. Pour imprimer la valeur d’un pointeur (const char *), vous devez d’abord le convertir en (char *). Tous les arguments (const char *) sont interprétés comme des chaînes
  4. Le code de retour différent de zéro ne correspond pas à la norme C printf ()
  5. Impossible de générer de manière asynchrone le tampon printf (c’est-à-dire lorsque le kernel est en cours d’exécution)
  6. L’appel de cudaPrintfDisplay émet implicitement un cudaDeviceSynchronize ()
  7. Les ressortingctions appliquées par cuPrintfRessortingct persistent entre les lancements. Pour les effacer du côté de l’hôte, vous devez appeler cudaPrintfEnd () puis cudaPrintfInit () à nouveau.
  8. La sortie cuPrintf n’est pas définie si plusieurs modules sont chargés dans un seul contexte
  9. Comstackz avec «-arch = sm_11» ou mieux si possible. L’utilisation de la mémoire tampon est beaucoup plus efficace et l’utilisation du registre est plus faible
  10. Les spécificateurs de format pris en charge sont: “cdiouxXeEfgGaAs”
  11. Le comportement des spécificateurs de format, en particulier des spécificateurs de justification / taille, dépend de l’implémentation de printf par la machine hôte.
  12. cuPrintf nécessite la création d’applications à l’aide de l’API d’exécution CUDA

Dans votre cas, vous n’utilisez pas d’arguments const char* .

Un des membres de votre structure est

  char MasterKey[3]; 

et quand vous initialisez les objects que vous faites

  //strcpy(NodeArray[i].MasterKey,"MasterKey"); strcpy(NodeArray[i].MasterKey,"Msk"); /* still too large */ 

ce qui est un peu (!) trop pour l’espace disponible.

Lors de votre dernière mise à jour, vous devez définir plusieurs slenz par sizeof(char) <- lorsque vous copiez. Donc ça devrait être:

 gpuAssert( cudaMemcpy(strGPU, str, slenz*sizeof(char), cudaMemcpyHostToDevice));