/[escript]/trunk/cusplibrary/performance/timer.h
ViewVC logotype

Contents of /trunk/cusplibrary/performance/timer.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5148 - (show annotations)
Mon Sep 15 01:25:23 2014 UTC (6 years, 2 months ago) by caltinay
File MIME type: text/plain
File size: 1284 byte(s)
Merging ripley diagonal storage + CUDA support into trunk.
Options file version has been incremented due to new options
'cuda' and 'nvccflags'.

1 /*
2 * Copyright 2008-2009 NVIDIA Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #pragma once
18
19 // A simple timer class
20
21 #include <cuda.h>
22
23 class timer
24 {
25 cudaEvent_t start;
26 cudaEvent_t end;
27
28 public:
29 timer()
30 {
31 cudaEventCreate(&start);
32 cudaEventCreate(&end);
33 cudaEventRecord(start,0);
34 }
35
36 ~timer()
37 {
38 cudaEventDestroy(start);
39 cudaEventDestroy(end);
40 }
41
42 float milliseconds_elapsed()
43 {
44 float elapsed_time;
45 cudaEventRecord(end, 0);
46 cudaEventSynchronize(end);
47 cudaEventElapsedTime(&elapsed_time, start, end);
48 return elapsed_time;
49 }
50 float seconds_elapsed()
51 {
52 return milliseconds_elapsed() / 1000.0;
53 }
54 };
55
56

  ViewVC Help
Powered by ViewVC 1.1.26