OpenCL module

This commit is contained in:
Linus Dierheimer
2022-06-05 00:18:40 +02:00
parent 3daede53eb
commit 008cf3b83d
14 changed files with 166 additions and 20 deletions
+6
View File
@@ -193,6 +193,8 @@ static void defaultConfig(FFinstance* instance)
ffStrbufInitA(&instance->config.vulkanFormat, 0);
ffStrbufInitA(&instance->config.openGLKey, 0);
ffStrbufInitA(&instance->config.openGLFormat, 0);
ffStrbufInitA(&instance->config.openCLKey, 0);
ffStrbufInitA(&instance->config.openCLFormat, 0);
ffStrbufInitA(&instance->config.libPCI, 0);
ffStrbufInitA(&instance->config.libVulkan, 0);
@@ -213,6 +215,7 @@ static void defaultConfig(FFinstance* instance)
ffStrbufInitA(&instance->config.libEGL, 0);
ffStrbufInitA(&instance->config.libGLX, 0);
ffStrbufInitA(&instance->config.libOSMesa, 0);
ffStrbufInitA(&instance->config.libOpenCL, 0);
ffStrbufInitA(&instance->config.diskFolders, 0);
@@ -353,6 +356,9 @@ void ffListFeatures()
#ifdef FF_HAVE_OSMESA
"osmesa\n"
#endif
#ifdef FF_HAVE_OPENCL
"opencl\n"
#endif
""
, stdout);
}
+3
View File
@@ -197,6 +197,7 @@
#--datetime-key Date Time
#--vulkan-key Vulkan
#--opengl-key OpenGL
#--opencl-key OpenCL
# Format options:
# Sets the format string for module values.
@@ -234,6 +235,7 @@
#--datetime-format
#--vulkan-format
#--opengl-format
#--opencl-format
# Library options:
# Sets an user specific path to a library to load.
@@ -257,3 +259,4 @@
#--lib-egl /usr/lib/libEGL.so
#--lib-glx /usr/lib/libGLX.so
#--lib-osmesa /usr/lib/libOSMesa.so
#--lib-opencl /usr/lib/libOpenCL.so
+3
View File
@@ -79,6 +79,7 @@ Format options: Provide the format string for custom output. Use fastfetch --hel
--date-format <format>
--vulkan-format <format>
--opengl-format <format>
--opencl-format <format>
Key options: Provide a custom key for an output
--os-key <key>
@@ -114,6 +115,7 @@ Key options: Provide a custom key for an output
--date-key <key>
--vulkan-key <key>
--opengl-key <key>
--opencl-key <key>
Library options: Set the path of a library to load
--lib-PCI <path>
@@ -135,6 +137,7 @@ Library options: Set the path of a library to load
--lib-egl <path>
--lib-glx <path>
--lib-osmesa <path>
--lib-opencl <path>
Module specific options:
--separator-string <str>: Set the string printed by the separator module
+1
View File
@@ -17,6 +17,7 @@ Locale
LocalIP
Memory
OS
OpenCL
OpenGL
Packages
Player
+16
View File
@@ -362,6 +362,14 @@ static inline void printCommandHelp(const char* command)
"shading language version"
);
}
else if(strcasecmp(command, "opencl-format") == 0)
{
constructAndPrintCommandHelpFormat("opencl", "{}", 3,
"version",
"device",
"vendor"
);
}
else
fprintf(stderr, "No specific help for command %s provided\n", command);
}
@@ -993,6 +1001,10 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
optionParseString(key, value, &instance->config.openGLKey);
else if(strcasecmp(key, "--opengl-format") == 0)
optionParseString(key, value, &instance->config.openGLFormat);
else if(strcasecmp(key, "--opencl-key") == 0)
optionParseString(key, value, &instance->config.openCLKey);
else if(strcasecmp(key, "--opencl-format") == 0)
optionParseString(key, value, &instance->config.openCLFormat);
///////////////////
//Library options//
@@ -1036,6 +1048,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
optionParseString(key, value, &instance->config.libGLX);
else if(strcasecmp(key, "--lib-osmesa") == 0)
optionParseString(key, value, &instance->config.libOSMesa);
else if(strcasecmp(key, "--lib-opencl") == 0)
optionParseString(key, value, &instance->config.libOpenCL);
//////////////////
//Module options//
@@ -1226,6 +1240,8 @@ static void parseStructureCommand(FFinstance* instance, FFdata* data, const char
ffPrintVulkan(instance);
else if(strcasecmp(line, "opengl") == 0)
ffPrintOpenGL(instance);
else if(strcasecmp(line, "opencl") == 0)
ffPrintOpenCL(instance);
else
ffPrintError(instance, line, 0, NULL, NULL, 0, "<no implementation provided>");
}
+4
View File
@@ -139,6 +139,8 @@ typedef struct FFconfig
FFstrbuf vulkanFormat;
FFstrbuf openGLKey;
FFstrbuf openGLFormat;
FFstrbuf openCLKey;
FFstrbuf openCLFormat;
FFstrbuf libPCI;
FFstrbuf libVulkan;
@@ -159,6 +161,7 @@ typedef struct FFconfig
FFstrbuf libEGL;
FFstrbuf libGLX;
FFstrbuf libOSMesa;
FFstrbuf libOpenCL;
FFstrbuf diskFolders;
@@ -612,5 +615,6 @@ void ffPrintPublicIp(FFinstance* instance);
void ffPrintColors(FFinstance* instance);
void ffPrintVulkan(FFinstance* instance);
void ffPrintOpenGL(FFinstance* instance);
void ffPrintOpenCL(FFinstance* instance);
#endif
+91
View File
@@ -0,0 +1,91 @@
#include "fastfetch.h"
#define FF_OPENCL_MODULE_NAME "OpenCL"
#define FF_OPENCL_NUM_FORMAT_ARGS 3
#ifdef FF_HAVE_OPENCL
#define CL_TARGET_OPENCL_VERSION 100
#include <CL/cl.h>
typedef struct OpenCLData
{
FF_LIBRARY_SYMBOL(clGetPlatformIDs);
FF_LIBRARY_SYMBOL(clGetDeviceIDs);
FF_LIBRARY_SYMBOL(clGetDeviceInfo);
} OpenCLData;
static const char* openCLHandelData(FFinstance* instance, OpenCLData* data)
{
cl_platform_id platformID;
cl_uint numPlatforms;
data->ffclGetPlatformIDs(1, &platformID, &numPlatforms);
if(numPlatforms == 0)
return "clGetPlatformIDs returned 0 platforms";
cl_device_id deviceID;
cl_uint numDevices;
data->ffclGetDeviceIDs(platformID, CL_DEVICE_TYPE_GPU, 1, &deviceID, &numDevices);
if(numDevices == 0)
data->ffclGetDeviceIDs(platformID, CL_DEVICE_TYPE_ALL, 1, &deviceID, &numDevices);
if(numDevices == 0)
return "clGetDeviceIDs returned 0 devices";
char version[64];
data->ffclGetDeviceInfo(deviceID, CL_DEVICE_VERSION, sizeof(version), version, NULL);
if(!ffStrSet(version))
return "clGetDeviceInfo returned NULL or empty string";
char device[128];
data->ffclGetDeviceInfo(deviceID, CL_DEVICE_NAME, sizeof(device), device, NULL);
char vendor[32];
data->ffclGetDeviceInfo(deviceID, CL_DEVICE_VENDOR, sizeof(vendor), vendor, NULL);
if(instance->config.openCLFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCLKey);
puts(version);
}
else
{
ffPrintFormatString(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCLKey, &instance->config.openCLFormat, NULL, FF_OPENCL_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRING, version},
{FF_FORMAT_ARG_TYPE_STRING, device},
{FF_FORMAT_ARG_TYPE_STRING, vendor}
});
}
return NULL;
}
static const char* printOpenCL(FFinstance* instance)
{
OpenCLData data;
FF_LIBRARY_LOAD(opencl, instance->config.libOpenCL, "dlopen libOpenCL.so failed", "libOpenCL.so", 1);
FF_LIBRARY_LOAD_SYMBOL_ADRESS(opencl, data.ffclGetPlatformIDs, clGetPlatformIDs, "dlsym clGetPlatformIDs failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(opencl, data.ffclGetDeviceIDs, clGetDeviceIDs, "dlsym clGetDeviceIDs failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(opencl, data.ffclGetDeviceInfo, clGetDeviceInfo, "dlsym clGetDeviceInfo failed");
const char* error = openCLHandelData(instance, &data);
dlclose(opencl);
return error;
}
#endif
void ffPrintOpenCL(FFinstance* instance)
{
const char* error;
#ifdef FF_HAVE_OPENCL
error = printOpenCL(instance);
#else
error = "Fastfetch was build without OpenCL support";
#endif
if(error != NULL)
ffPrintError(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCLKey, &instance->config.openCLFormat, FF_OPENCL_NUM_FORMAT_ARGS, error);
}