aboutsummaryrefslogtreecommitdiff
path: root/src/device_info.c
blob: ed87beef0e848010bb9e91d44da4492531572375 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//------------------------------------------------------------------------------
//
// Name:     device_info()
//
// Purpose:  Function to output key parameters about the input OpenCL device.
// License:  public domain
//
//
// RETURN:   The OCL_SUCESS or the error code from one of the OCL function
//           calls internal to this function
//
// HISTORY:  Written by Tim Mattson, June 2010
//
//------------------------------------------------------------------------------
#include <cctk.h>
#include <cctk_Arguments.h>
#include <cctk_Parameters.h>

#include <stdlib.h>
#include <string.h>

#ifdef __APPLE__
#  include <OpenCL/opencl.h>
#else
#  include <CL/cl.h>
#endif

//  define VERBOSE if you want to print info about work groups sizes
//#define  VERBOSE 1
#ifdef VERBOSE
     extern char *OpenCL_err_code(cl_int);
#endif

#define OpenCL_VWarn(...) CCTK_VWarn(opencl_error_code, __LINE__, __FILE__, CCTK_THORNSTRING, __VA_ARGS__)
#define OpenCL_VInfo(...) CCTK_VInfo(CCTK_THORNSTRING, __VA_ARGS__)

int output_device_info(cl_device_id device_id);
int output_device_info(cl_device_id device_id)
{
    int err;                            // error code returned from OpenCL calls
    cl_device_type device_type;         // Parameter defining the type of the compute device
    cl_uint comp_units;                 // the max number of compute units on a device
    cl_char vendor_name[1024] = {0};    // string to hold vendor name for compute device
    cl_char device_name[1024] = {0};    // string to hold name of compute device
#ifdef VERBOSE
    cl_uint          max_work_itm_dims;
    size_t           max_wrkgrp_size;
#endif

    CCTK_INT opencl_error_code = 0;

    err = clGetDeviceInfo(device_id, CL_DEVICE_NAME, sizeof(device_name), &device_name, NULL);
    if (err != CL_SUCCESS)
    {
        OpenCL_VWarn("Error: Failed to access device name!");
        return EXIT_FAILURE;
    }
    OpenCL_VInfo(" Device: %s", device_name);

    err = clGetDeviceInfo(device_id, CL_DEVICE_TYPE, sizeof(device_type), &device_type, NULL);
    if (err != CL_SUCCESS)
    {
        OpenCL_VWarn("Error: Failed to access device type information!");
        return EXIT_FAILURE;
    }
    if(device_type  == CL_DEVICE_TYPE_GPU)
       OpenCL_VInfo("  GPU from ");

    else if (device_type == CL_DEVICE_TYPE_CPU)
       OpenCL_VInfo("  CPU from ");

    else 
       OpenCL_VInfo("  non CPU or GPU processor from ");

    err = clGetDeviceInfo(device_id, CL_DEVICE_VENDOR, sizeof(vendor_name), &vendor_name, NULL);
    if (err != CL_SUCCESS)
    {
        OpenCL_VWarn("Error: Failed to access device vendor name!");
        return EXIT_FAILURE;
    }
    OpenCL_VInfo("   %s", vendor_name);

    err = clGetDeviceInfo(device_id, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &comp_units, NULL);
    if (err != CL_SUCCESS)
    {
        OpenCL_VWarn("Error: Failed to access device number of compute units !");
        return EXIT_FAILURE;
    }
    OpenCL_VInfo("   with a max of %d compute units",comp_units);

#ifdef VERBOSE
//
// Optionally print information about work group sizes
//
    err = clGetDeviceInfo( device_id, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(cl_uint), 
                               &max_work_itm_dims, NULL);
    if (err != CL_SUCCESS)
    {
        OpenCL_VWarn("Error: Failed to get device Info (CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS)!",
                                                                            OpenCL_err_code(err));
        return EXIT_FAILURE;
    }
    
    size_t max_loc_size[max_work_itm_dims];
    err = clGetDeviceInfo( device_id, CL_DEVICE_MAX_WORK_ITEM_SIZES, max_work_itm_dims* sizeof(size_t), 
                               max_loc_size, NULL);
    if (err != CL_SUCCESS)
    {
        OpenCL_VWarn("Error: Failed to get device Info (CL_DEVICE_MAX_WORK_ITEM_SIZES)!",OpenCL_err_code(err));
        return EXIT_FAILURE;
    }
    err = clGetDeviceInfo( device_id, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), 
                               &max_wrkgrp_size, NULL);
    if (err != CL_SUCCESS)
    {
        OpenCL_VWarn("Error: Failed to get device Info (CL_DEVICE_MAX_WORK_GROUP_SIZE)!",OpenCL_err_code(err));
        return EXIT_FAILURE;
    }
    OpenCL_VInfo("work group, work item information");
    OpenCL_VInfo("\n max loc dim ");
    for(int i=0; i< max_work_itm_dims; i++)
        OpenCL_VInfo(" %d ",(int)(*(max_loc_size+i)));
    OpenCL_VInfo("\n");
    OpenCL_VInfo(" Max work group size = %d\n",(int)max_wrkgrp_size);

#endif

    return CL_SUCCESS;

}