0

簡単な nvml テスト コードを作成します。

Linux では、gcc を使用して問題なくコンパイルおよび実行できます。

gcc test.c -I /usr/local/cuda-11.5/include -l:libnvidia-ml.so -o テスト

しかし、Visual Studio cl.exe を使用して Windows で同じことを行うにはどうすればよいですか?

私は次のことを試しましたが、うまくいきませんでした。

cl.exe test.c /EHsc /I "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include" /link /LIBPATH:"c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11 .5\lib\x64"

cl.exe には、gcc の「-l:libnvidia-ml.so」に相当するものはないようです。

#include <stdio.h>
#include <nvml.h>

void list_device()
{
    nvmlInit();

    unsigned int count;
    nvmlDeviceGetCount(&count);
    printf("Found %u device \n", count);

    nvmlDevice_t device;
    nvmlPciInfo_t pci;
    char name[NVML_DEVICE_NAME_BUFFER_SIZE];
    unsigned int speed;
    unsigned int temp;
    nvmlTemperatureSensors_t sensorType = NVML_TEMPERATURE_GPU;
    nvmlMemory_t memory;
    unsigned int power;
    unsigned int limit;
    nvmlUtilization_t utilization;
    int i = 0;
    for (i = 0; i < count; i++)
    {
        nvmlDeviceGetHandleByIndex(i, &device);
        nvmlDeviceGetName(device, name, NVML_DEVICE_NAME_BUFFER_SIZE);
        nvmlDeviceGetPciInfo(device, &pci);
        nvmlDeviceGetFanSpeed(device, &speed);
        nvmlDeviceGetTemperature(device, sensorType, &temp);
        nvmlDeviceGetMemoryInfo(device, &memory);
        nvmlDeviceGetPowerUsage(device, &power);
        nvmlDeviceGetEnforcedPowerLimit(device, &limit);
        nvmlDeviceGetUtilizationRates(device, &utilization);

        printf("%d. %s [%s] \n \
        fan speed: %d%% temp: %dC \n \
        memory.used: %lluMiB memory.free: %lluMiB memory.total: %lluMiB \n \
        power: %uW/%uW \n \
        gpu: %u memory: %u \n", \
        i, name, pci.busId, \
        speed, temp, \
        memory.used/1024/1024, memory.free/1024/1024, memory.total/1024/1024, \
        power/1000, limit/1000, \
        utilization.gpu, utilization.memory);
    }

    nvmlShutdown();
}

int main(void)
{
    list_device();
}
4

0 に答える 0