C++ To Cuda Conversion/String Generation And Comparison -


so in basic high school coding class. had think 1 of our semester projects. chose base mine on ideas , applications arn't used in traditional code. brought idea use of cuda. 1 of best ways know compare speed of traditional methods versus unconventional string generation , comparison. 1 demonstrate generation , matching speed of traditional cpu generation timers , output. , show increase(or decrease) in speed , output of gpu processing.

i wrote c++ code generate random characters input character array , match array predetermined string. cpu programming incredibly slow comparatively gpu programming. i've looked on cuda api , not find possibly lead me in right direction i'm looking do.

below code have written in c++, if point me in direction of such things random number generator can convert chars using ascii codes, excellent.

#include <iostream> #include <string> #include <cstdlib>  using namespace std;  int slength = 0; int count = 0; int stop = 0; int maxvalue = 0; string instring = "ab1@"; static const char alphanum[] = "0123456789" "!@#$%^&*" "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz";  int stringlength = sizeof(alphanum) - 1;  char genrandom() {     return alphanum[rand() % stringlength]; }  int main() {     cout << "length of string match?" << endl;     cin >> slength;     string smatch(slength, ' ');     while(true)     {         (int x = 0; x < slength; x++)         {             smatch[x] = genrandom();             //cout << smatch[x];             count++;             if (count == 2147000000)             {                 count == 0;                 maxvalue++;             }         }         if (smatch == instring)         {             cout << "it took " << count + (maxvalue*2147000000) << " randomly generated characters match strings." << endl;             cin >> stop;         }         //cout << endl;     }  } 

if want implement pseudorandom number generator using cuda, have over here. if want generate chars predetermined set of characters, can put possible chars array , create random index (just doing right now).

but think might more valuable comparison might 1 uses brute force. therefore, adapt program try not random strings, try 1 string after in meaningful order.

then, on other hand, implement brute-force stuff on gpu using cuda. can tricky since might want stop all cuda threads one of them finds solution. imagine brute force process using cuda following way: 1 thread tries aa first 2 letters , brute-forces following digits, next thread tries ab first 2 letters , brute-forces following digits, next thread tries ac first 2 letters , brute-forces following digits, , on. these threads run in parallel. of course, vary number of predetermined chars such e.g. first thread tries aaaa, second aaab. then, compare different input values.

any way, if have never dealt cuda, recommend vector addition sample, basic cuda example, serves getting basic understanding of what's going on cuda. moreover, should read cuda programming guide make familiar cudas concept of grid of thread-blocks containing grid of threads. once understand this, think becomes clearer how cuda organizes stuff. short, in cuda, should replace loops kernel, executed multiple times @ once.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -