Skip to content

Instantly share code, notes, and snippets.

@GitBubble
Last active March 10, 2020 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GitBubble/eccdfa25ddde3332394a8757e83af11f to your computer and use it in GitHub Desktop.
Save GitBubble/eccdfa25ddde3332394a8757e83af11f to your computer and use it in GitHub Desktop.
nvtxtoolsExt
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "nvToolsExt.h"
#include <thread>


int func(int a)
{


  static int sum = 0;

  for(int i=0; i< 100; i++) {
        sum += i ;

        if( i == 100) {
          nvtxEventAttributes_t attr = {0};
          attr.version = NVTX_VERSION;
          attr.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
          attr.messageType = NVTX_MESSAGE_TYPE_ASCII;
          attr.message.ascii = "WorkerThreadRun"":ASCII";
          nvtxMarkEx(&attr);
        }
  }

  return sum;
}


void WorkerThreadRun()
{


  do {

     nvtxRangePushA(__FUNCTION__);

     func(10000);

     nvtxRangePop();
  } while(true);

}




void LaborWorker()
{


  do {

    nvtxRangePushA(__FUNCTION__);

    func(10000);

    nvtxRangePop();
  } while(true);

}


void CoderWorker()
{
 static int count = 10;

  do {

    nvtxEventAttributes_t attr = {0};
    attr.version = NVTX_VERSION;
    attr.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
    attr.messageType = NVTX_MESSAGE_TYPE_ASCII;
    attr.message.ascii = "WorkerThreadRun"":ASCII";
    nvtxMarkEx(&attr);

  } while(count--);

}




int main(int argc, char** argv)
{
   int  idBase[] = {4,8,9,10,22,1,2,3};
   printf("hello,world");

   std::thread* worker = new std::thread( [](){ WorkerThreadRun();} );
   //std::thread* worker2 = new std::thread( [](){ LaborWorker();} );
   //std::thread* worker3 = new std::thread( [](){ CoderWorker();} );

   worker->join();

 /*
   worker2->join();
   worker3->join();

   delete worker;
   delete worker2;
   delete worker3;

   worker = NULL;
   worker2 = NULL;
   worker3 = NULL;
*/


   return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment