diff --git a/Makefile b/Makefile index a1f8f8a..e227889 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ stlib : $(BUILD)/libinfoware$(ARCH) $(BUILD)/$(PREDLL)infoware$(DLL) : $(OBJECTS) - $(CXX) $(CXXAR) -shared $(PIC) -o$@ $^ + $(CXX) $(CXXAR) -shared $(PIC) -o$@ $^ $(LDAR) $(BUILD)/libinfoware$(ARCH) : $(OBJECTS) $(AR) crs $@ $^ @@ -39,8 +39,8 @@ $(BUILD)/libinfoware$(ARCH) : $(OBJECTS) $(BUILD)/obj/%$(OBJ) : src/%.cpp @mkdir -p $(dir $@) - $(CXX) $(CXXAR) $(PIC) -Iinclude -c -o$@ $^ + $(CXX) $(CXXAR) $(CXXAR_LIB) $(PIC) -Iinclude -c -o$@ $^ $(BUILD)/examples/%$(EXE) : examples/%.cpp $(OBJECTS) @mkdir -p $(dir $@) - $(CXX) $(CXXAR) -Iinclude -o$@ $^ + $(CXX) $(CXXAR) -Iinclude -o$@ $^ $(LDAR) diff --git a/configMakefile b/configMakefile index 23e7c71..34f3e42 100644 --- a/configMakefile +++ b/configMakefile @@ -11,26 +11,37 @@ ifeq "$(OS)" "Windows_NT" - DLL = .dll - PREDLL = - PIC = - EXE = .exe + DLL := .dll + PREDLL := + PIC := + EXE := .exe else - PREDLL = lib - PIC = -fPIC + PREDLL := lib + PIC := -fPIC ifeq "$(OS)" "Darwin" - DLL = .dylib + DLL := .dylib else - DLL = .so + DLL := .so endif - EXE = + EXE := endif ifeq "$(BUILD)" "" - BUILD = out + BUILD := out endif -OBJ = .o -ARCH = .a -AR = ar -CXXAR = -pedantic -O3 -fomit-frame-pointer -std=c++14 -Wall -Wextra -pipe +ifdef USE_OPENCL + LDAR_OPENCL := -lOpenCL + CXXAR_OPENCL := -DINFOWARE_USE_OPENCL +else + LDAR_OPENCL := + CXXAR_OPENCL := +endif + +LDAR := $(LDAR_OPENCL) +CXXAR_LIB := $(CXXAR_OPENCL) + +OBJ := .o +ARCH := .a +AR := ar +CXXAR := -pedantic -O3 -fomit-frame-pointer -std=c++14 -Wall -Wextra -pipe diff --git a/examples/gpu_device_properties_cache_size.cpp b/examples/gpu_device_properties_cache_size.cpp new file mode 100644 index 0000000..31c3b39 --- /dev/null +++ b/examples/gpu_device_properties_cache_size.cpp @@ -0,0 +1,21 @@ +// infoware - C++ System information Library +// +// Written in 2016 by nabijaczleweli and ThePhD +// +// To the extent possible under law, the author(s) have dedicated all copyright and related +// and neighboring rights to this software to the public domain worldwide. This software is +// distributed without any warranty. +// +// You should have received a copy of the CC0 Public Domain Dedication along with this software. +// If not, see + + +#include "infoware/gpu.hpp" +#include + + +int main() { + for(auto&& props : iware::gpu::device_properties()) + std::cout << props.cache_size << ' '; + std::cout << '\n'; +} diff --git a/examples/gpu_device_properties_memory_size.cpp b/examples/gpu_device_properties_memory_size.cpp new file mode 100644 index 0000000..cc9e05d --- /dev/null +++ b/examples/gpu_device_properties_memory_size.cpp @@ -0,0 +1,21 @@ +// infoware - C++ System information Library +// +// Written in 2016 by nabijaczleweli and ThePhD +// +// To the extent possible under law, the author(s) have dedicated all copyright and related +// and neighboring rights to this software to the public domain worldwide. This software is +// distributed without any warranty. +// +// You should have received a copy of the CC0 Public Domain Dedication along with this software. +// If not, see + + +#include "infoware/gpu.hpp" +#include + + +int main() { + for(auto&& props : iware::gpu::device_properties()) + std::cout << props.memory_size << ' '; + std::cout << '\n'; +} diff --git a/examples/gpu_device_properties_name.cpp b/examples/gpu_device_properties_name.cpp new file mode 100644 index 0000000..0b1b3fa --- /dev/null +++ b/examples/gpu_device_properties_name.cpp @@ -0,0 +1,21 @@ +// infoware - C++ System information Library +// +// Written in 2016 by nabijaczleweli and ThePhD +// +// To the extent possible under law, the author(s) have dedicated all copyright and related +// and neighboring rights to this software to the public domain worldwide. This software is +// distributed without any warranty. +// +// You should have received a copy of the CC0 Public Domain Dedication along with this software. +// If not, see + + +#include "infoware/gpu.hpp" +#include + + +int main() { + for(auto&& props : iware::gpu::device_properties()) + std::cout << props.name << ' '; + std::cout << '\n'; +} diff --git a/examples/gpu_device_properties_vendor.cpp b/examples/gpu_device_properties_vendor.cpp new file mode 100644 index 0000000..8b34c20 --- /dev/null +++ b/examples/gpu_device_properties_vendor.cpp @@ -0,0 +1,34 @@ +// infoware - C++ System information Library +// +// Written in 2016 by nabijaczleweli and ThePhD +// +// To the extent possible under law, the author(s) have dedicated all copyright and related +// and neighboring rights to this software to the public domain worldwide. This software is +// distributed without any warranty. +// +// You should have received a copy of the CC0 Public Domain Dedication along with this software. +// If not, see + + +#include "infoware/gpu.hpp" +#include + + +int main() { + for(auto&& props : iware::gpu::device_properties()) + switch(props.vendor) { + case iware::gpu::vendor_t::intel: + std::cout << "Intel "; + break; + case iware::gpu::vendor_t::AMD: + std::cout << "AMD "; + break; + case iware::gpu::vendor_t::NVidia: + std::cout << "NVidia "; + break; + case iware::gpu::vendor_t::unknown: + std::cout << "Unknown "; + break; + } + std::cout << '\n'; +} diff --git a/include/infoware/gpu.hpp b/include/infoware/gpu.hpp new file mode 100644 index 0000000..7851c83 --- /dev/null +++ b/include/infoware/gpu.hpp @@ -0,0 +1,41 @@ +// infoware - C++ System information Library +// +// Written in 2016 by nabijaczleweli and ThePhD +// +// To the extent possible under law, the author(s) have dedicated all copyright and related +// and neighboring rights to this software to the public domain worldwide. This software is +// distributed without any warranty. +// +// You should have received a copy of the CC0 Public Domain Dedication along with this software. +// If not, see + + +#pragma once + + +#include +#include +#include + + +namespace iware { + namespace gpu { + enum class vendor_t { + intel, + AMD, + NVidia, + unknown, + }; + + struct device_properties_t { + vendor_t vendor; + std::string name; + std::size_t memory_size; + std::size_t cache_size; + }; + + + /// Returns all GPU's properties. + std::vector device_properties(); + } +} diff --git a/include/infoware/infoware.hpp b/include/infoware/infoware.hpp index 59990ed..e36f4f1 100644 --- a/include/infoware/infoware.hpp +++ b/include/infoware/infoware.hpp @@ -14,4 +14,5 @@ #include "cpu.hpp" +#include "gpu.hpp" #include "system.hpp" diff --git a/src/gpu/memory/OpenCL.cpp b/src/gpu/memory/OpenCL.cpp new file mode 100644 index 0000000..b54213a --- /dev/null +++ b/src/gpu/memory/OpenCL.cpp @@ -0,0 +1,67 @@ +// infoware - C++ System information Library +// +// Written in 2016 by nabijaczleweli and ThePhD +// +// To the extent possible under law, the author(s) have dedicated all copyright and related +// and neighboring rights to this software to the public domain worldwide. This software is +// distributed without any warranty. +// +// You should have received a copy of the CC0 Public Domain Dedication along with this software. +// If not, see + + +#ifdef INFOWARE_USE_OPENCL + + +#include "infoware/gpu.hpp" +#include +#ifdef __APPLE__ +#include +#else +#include +#endif + + +static iware::gpu::vendor_t parse_vendor(const char* name) { + if(!strcmp(name, "Intel(R) Corporation")) + return iware::gpu::vendor_t::intel; + else if(!strcmp(name, "Advanced Micro Devices, Inc.")) + return iware::gpu::vendor_t::AMD; + else if(!strcmp(name, "NVIDIA Corporation")) + return iware::gpu::vendor_t::NVidia; + else + return iware::gpu::vendor_t::unknown; +} + + +std::vector iware::gpu::device_properties() { + cl_platform_id platforms[64]; + cl_uint platforms_used; + clGetPlatformIDs(sizeof platforms / sizeof(*platforms), platforms, &platforms_used); + + std::vector ret; + for(auto i = 0u; i < platforms_used; ++i) { + cl_device_id devices[64]; + cl_uint devices_used; + clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_GPU, sizeof devices / sizeof(*devices), devices, &devices_used); + + for(auto j = 0u; j < devices_used; ++j) { + char name[256]; + cl_ulong cache; + cl_ulong memory; + + clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, sizeof(cache), &cache, nullptr); + clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(memory), &memory, nullptr); + clGetDeviceInfo(devices[j], CL_DEVICE_VENDOR, sizeof name, &name, nullptr); + const auto vendor = parse_vendor(name); + clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof name, &name, nullptr); + + ret.push_back({vendor, name, memory, cache}); + } + } + + return ret; +} + + +#endif diff --git a/src/gpu/memory/OpenGL.cpp b/src/gpu/memory/OpenGL.cpp new file mode 100644 index 0000000..2a70564 --- /dev/null +++ b/src/gpu/memory/OpenGL.cpp @@ -0,0 +1,14 @@ +// infoware - C++ System information Library +// +// Written in 2016 by nabijaczleweli and ThePhD +// +// To the extent possible under law, the author(s) have dedicated all copyright and related +// and neighboring rights to this software to the public domain worldwide. This software is +// distributed without any warranty. +// +// You should have received a copy of the CC0 Public Domain Dedication along with this software. +// If not, see + + +// OpenGL is literaly hitler to initialise a windowless context for, so no game. +// Leave it for someone smarter than me :G diff --git a/src/gpu/memory/blank_all.cpp b/src/gpu/memory/blank_all.cpp new file mode 100644 index 0000000..c4afeac --- /dev/null +++ b/src/gpu/memory/blank_all.cpp @@ -0,0 +1,24 @@ +// infoware - C++ System information Library +// +// Written in 2016 by nabijaczleweli and ThePhD +// +// To the extent possible under law, the author(s) have dedicated all copyright and related +// and neighboring rights to this software to the public domain worldwide. This software is +// distributed without any warranty. +// +// You should have received a copy of the CC0 Public Domain Dedication along with this software. +// If not, see + + +#ifndef INFOWARE_USE_OPENCL + + +#include "infoware/gpu.hpp" + + +std::vector iware::gpu::device_properties() { + return {}; +} + + +#endif