English 中文(简体)
2. 哺乳期: CUDA
原标题:Timing woes with clock_gettime() CUDA

我想写一部《世界人权宣言》,其中我可以亲眼看到《世界人权宣言》为加快申请而提供的好处。

http://code.google.com/p/thrust/“rel=“nofollow”http://code.google.com/p/thrust/。 iii

简言之,《守则》确实创造了两个2^23长的气管病媒,一个在东道方,另一个在装置上,彼此相同,并且加以分类。 它还(试图)衡量每个目标的时间。

关于东道病媒一的使用<代码>std:sort。 关于装置矢量I的使用thrust:sort

所使用的汇编一

iii - 侵权行为

终端方案的产出是:

桌面:

所用时间为:19 224622882秒

所用装置时间为:19,321644143秒

桌面:

The first std::cout statement is produced after 19.224 seconds as stated. Yet the second std::cout statement (even though it says 19.32 seconds) is produced immediately after the first std::cout statement. Note that I have used different time_stamps for measurements in clock_gettime() viz ts_host and ts_device

I am using Cuda 4.0 and NVIDIA GTX 570 compute capability 2.0

  #include<iostream>
    #include<vector>
    #include<algorithm>
    #include<stdlib.h>

    //For timings
    #include<time.h>
    //Necessary thrust headers
    #include<thrust/sort.h>
    #include<thrust/host_vector.h>
    #include<thrust/device_vector.h>
    #include<thrust/copy.h>


    int main(int argc, char *argv[])
    {
      int N=23;
      thrust::host_vector<int>H(1<<N);//create a vector of 2^N elements on host
      thrust::device_vector<int>D(1<<N);//The same on the device.
      thrust::host_vector<int>dummy(1<<N);//Copy the D to dummy from GPU after sorting 

       //Set the host_vector elements. 
      for (int i = 0; i < H.size(); ++i)    {
          H[i]=rand();//Set the host vector element to pseudo-random number.
        }

      //Sort the host_vector. Measure time
      // Reset the clock
        timespec ts_host;
        ts_host.tv_sec = 0;
        ts_host.tv_nsec = 0;
        clock_settime(CLOCK_PROCESS_CPUTIME_ID, &ts_host);//Start clock

             thrust::sort(H.begin(),H.end());

        clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts_host);//Stop clock
        std::cout << "
Host Time taken is: " << ts_host.tv_sec<<" . "<< ts_host.tv_nsec <<" seconds" << std::endl;


        D=H; //Set the device vector elements equal to the host_vector
      //Sort the device vector. Measure time.
        timespec ts_device;
        ts_device.tv_sec = 0;
            ts_device.tv_nsec = 0;
        clock_settime(CLOCK_PROCESS_CPUTIME_ID, &ts_device);//Start clock

             thrust::sort(D.begin(),D.end());
             thrust::copy(D.begin(),D.end(),dummy.begin());


        clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts_device);//Stop clock
        std::cout << "
Device Time taken is: " << ts_device.tv_sec<<" . "<< ts_device.tv_nsec <<" seconds" << std::endl;

      return 0;
    }
最佳回答

您没有核对<代码>clock_settime的回报率。 我会猜测这一缺陷,可能的话是向企业社会责任部或企业社会责任部制定的<代码>errno。 阅读文件并始终检查你们的返回价值!

如果是我的权利,你不会像你所认为的那样重新lock锁,因此,第二个时间是累积的,加上你根本不打算计算的一些额外困难。

这样做的正确方式是只打上clock_gettime,首先储存结果,进行计算,然后从最后时间推倒原始时间。

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签