https://developer.nvidia.com/cuda-faq
Q: How can I get information on GPU temperature from my application? On Microsoft Windows platforms, NVIDIA's NVAPI gives access to GPU temperature and many other low-level GPU functions
Under Linux, the "nvidia-smi" utility, which is included with the standard driver install, also displays GPU temperature for all installed devices.
EDIT
While looking further about "nvidia-smi" utility which has been provided by linux based system, i found that they have provided C based API to fetch the GPU temperature.
https://developer.nvidia.com/nvidia-management-library-nvml https://developer.nvidia.com/nvidia-system-management-interface
From manual, I could see that below API can be used to find out which has been provided by "nvidia-smi":
7.9.2.8 nvmlReturn_t DECLDIR nvmlUnitGetTemperature (nvmlUnit_t unit, unsigned int type, unsigned
int temp)
Retrieves the temperature readings for the unit, in degrees C.
For S-class products.
Depending on the product, readings may be available for intake (type=0), exhaust (type=1) and board (type=2).
Parameters:
unit The identifier of the target unit
type The type of reading to take
temp Reference in which to return the intake temperature
Returns:
• NVML_SUCCESS if temp has been populated
• NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized
• NVML_ERROR_INVALID_ARGUMENT if unit or type is invalid or temp is NULL
• NVML_ERROR_NOT_SUPPORTED if this is not an S-class product
• NVML_ERROR_UNKNOWN on any unexpected error
Hope this would be useful and this way you can achieve your requirement. "nvidia-smi" internally uses the above API to find out the temperature of GPU which which user get.This is command line utility provided by NVIDIA.