/[escript]/trunk/cusplibrary/performance/spmv/utility.h
ViewVC logotype

Contents of /trunk/cusplibrary/performance/spmv/utility.h

Parent Directory Parent Directory | Revision Log Revision Log


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

1 #pragma once
2
3 #include <cuda.h>
4 #include <iostream>
5
6 void set_device(int device_id)
7 {
8 cudaSetDevice(device_id);
9 }
10
11
12 void list_devices(void)
13 {
14 int deviceCount;
15 CUDA_SAFE_CALL(cudaGetDeviceCount(&deviceCount));
16 if (deviceCount == 0)
17 std::cout << "There is no device supporting CUDA" << std::endl;
18
19 for (int dev = 0; dev < deviceCount; ++dev) {
20 cudaDeviceProp deviceProp;
21 CUDA_SAFE_CALL(cudaGetDeviceProperties(&deviceProp, dev));
22
23 if (dev == 0) {
24 if (deviceProp.major == 9999 && deviceProp.minor == 9999)
25 std::cout << "There is no device supporting CUDA." << std::endl;
26 else if (deviceCount == 1)
27 std::cout << "There is 1 device supporting CUDA" << std:: endl;
28 else
29 std::cout << "There are " << deviceCount << " devices supporting CUDA" << std:: endl;
30 }
31
32 std::cout << "\nDevice " << dev << ": \"" << deviceProp.name << "\"" << std::endl;
33 std::cout << " Major revision number: " << deviceProp.major << std::endl;
34 std::cout << " Minor revision number: " << deviceProp.minor << std::endl;
35 std::cout << " Total amount of global memory: " << deviceProp.totalGlobalMem << " bytes" << std::endl;
36 }
37 std::cout << std::endl;
38 }
39
40
41 template <typename T>
42 T l2_error(size_t N, const T * a, const T * b)
43 {
44 T numerator = 0;
45 T denominator = 0;
46 for(size_t i = 0; i < N; i++)
47 {
48 numerator += (a[i] - b[i]) * (a[i] - b[i]);
49 denominator += (b[i] * b[i]);
50 }
51
52 return numerator/denominator;
53 }
54
55
56

  ViewVC Help
Powered by ViewVC 1.1.26