c++ - char to int conversion in host device with CUDA -


i have been having trouble converting single character integer while in host function of cuda program. after line -

token[j] = token[j] * 10 + (buf[i] - '0' ); 

i use cuda-gdb check value token[j], , different numbers not seem have pattern. have tried simple casting, not multiplying ten (which saw in thread), not subtracting '0', , seem different result. appreciated. first time posting on stack overflow, give me break if formatting awful.

-a fellow struggling coder

 __global__ void rread(unsigned int *table, char *buf, int *threadbytes, unsigned int *token) {          int = 0;          int j = 0;          *token = null;          int tid = threadidx.x;          unsigned int key;          char delim = ' ';          for(i = tid * *threadbytes; <(tid * *threadbytes) + *threadbytes ; i++)          {                  if (buf[i] != delim) { //check if not delim                          token[j] = token[j] * 10 + (buf[i] - '0' ); 

there's race condition on writing token.

if want have local array per block can use shared memory. if want local array per thread, need use local per-thread memory , declare array on stack. in first case have deal concurrency inside block well. in latter don't have to, although might potentially waste lot more memory (and reduce collaboration).


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -