From 48e507431f7082c4bb5d13da435a70fdfea813d4 Mon Sep 17 00:00:00 2001 From: Marcel Breyer Date: Tue, 15 Oct 2024 14:54:14 +0200 Subject: [PATCH 001/202] Reimplement the plssvm_target_platforms.py utility script to reduce the number of dependencies (removed dependencies for CPU as well as NVIDIA and AMD GPU discovery). --- CMakeLists.txt | 2 +- README.md | 18 +- install/python_requirements.txt | 3 - utility_scripts/plssvm_target_platforms.py | 408 ++++++--------------- 4 files changed, 120 insertions(+), 311 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0c01a9ec..8b705b2a6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -264,7 +264,7 @@ else () endif () include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_python_libs.cmake) - set(PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS cpuinfo GPUtil pyamdgpuinfo pylspci) + set(PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS pylspci) message(STATUS "Checking required Python3 libraries (${PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS}) to automatically determine the PLSSVM_TARGET_PLATFORMS.") set(PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS_ERROR_MESSAGE "or manually define PLSSVM_TARGET_PLATFORMS (e.g. -DPLSSVM_TARGET_PLATFORMS=\"cpu;nvidia:sm_70,sm_86;amd:gfx906;intel:skl\"!") check_python_libs(${PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS} ${PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS_ERROR_MESSAGE}) diff --git a/README.md b/README.md index 7125af999..fb05f3307 100644 --- a/README.md +++ b/README.md @@ -179,9 +179,7 @@ Valid targets are: At least one of the above targets must be present. If the option `PLSSVM_TARGET_PLATFORMS` is not present, the targets are automatically determined using the Python3 `utility_scripts/plssvm_target_platforms.py` script (required Python3 dependencies: -[`argparse`](https://docs.python.org/3/library/argparse.html), [`py-cpuinfo`](https://pypi.org/project/py-cpuinfo/), -[`GPUtil`](https://pypi.org/project/GPUtil/), [`pyamdgpuinfo`](https://pypi.org/project/pyamdgpuinfo/), and -[`pylspci`](https://pypi.org/project/pylspci/)). +[`argparse`](https://docs.python.org/3/library/argparse.html), and [`pylspci`](https://pypi.org/project/pylspci/)). Note that when using DPC++ only a single architectural specification for `cpu`, `nvidia` or `amd` is allowed and that automatically retrieving AMD GPU information on Windows is currently not supported due to `pyamdgpuinfo` limitations. @@ -194,8 +192,9 @@ python3 utility_scripts/plssvm_target_platforms.py --help usage: plssvm_target_platforms.py [-h] [--quiet] optional arguments: - -h, --help show this help message and exit - --quiet only output the final PLSSVM_TARGET_PLATFORMS string + -h, --help show this help message and exit + --quiet only output the final PLSSVM_TARGET_PLATFORMS string + --gpus_only only output gpu architectures to the final PLSSVM_TARGET_PLATFORMS string ``` Example invocation: @@ -204,10 +203,9 @@ Example invocation: python3 utility_scripts/plssvm_target_platforms.py ``` ``` -Intel(R) Core(TM) i9-10980XE CPU @ 3.00GHz: {'avx512': True, 'avx2': True, 'avx': True, 'sse4_2': True} +supported CPU SIMD flags: {'avx512': True, 'avx2': True, 'avx': True, 'sse4_2': True} -Found 1 NVIDIA GPU(s): - 1x NVIDIA GeForce RTX 3080: sm_86 +Found 1 NVIDIA GPU(s): [sm_86] Possible -DPLSSVM_TARGET_PLATFORMS entries: cpu:avx512;nvidia:sm_86 @@ -221,13 +219,11 @@ or with the `--quiet` flag provided: python3 utility_scripts/plssvm_target_platforms.py --quiet ``` ``` -cpu:avx512;intel:dg1 +cpu:avx512;nvidia:sm_86 ``` If the architectural information for the requested GPU could not be retrieved, one option would be to have a look at: -- for NVIDIA GPUs: [Your GPU Compute Capability](https://developer.nvidia.com/cuda-gpus) -- for AMD GPUs: [clang AMDGPU backend usage](https://llvm.org/docs/AMDGPUUsage.html) - for Intel GPUs and CPUs: [Ahead of Time Compilation](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compilation/ahead-of-time-compilation.html) and [Intel graphics processor table](https://dgpu-docs.intel.com/devices/hardware-table.html) diff --git a/install/python_requirements.txt b/install/python_requirements.txt index c058e4504..4f555c79a 100644 --- a/install/python_requirements.txt +++ b/install/python_requirements.txt @@ -20,9 +20,6 @@ matplotlib ## for the automatic PLSSVM target platform determination # argparse -py-cpuinfo -GPUtil -pyamdgpuinfo; platform_system != "Windows" pylspci diff --git a/utility_scripts/plssvm_target_platforms.py b/utility_scripts/plssvm_target_platforms.py index 28c9f7541..be171b222 100644 --- a/utility_scripts/plssvm_target_platforms.py +++ b/utility_scripts/plssvm_target_platforms.py @@ -10,15 +10,17 @@ import argparse import re +import ctypes +from pathlib import Path +import subprocess -import cpuinfo # get CPU SIMD information -import GPUtil # get NVIDIA GPU information -import pyamdgpuinfo # get AMD GPU information import pylspci # get Intel GPU information # parse command line arguments parser = argparse.ArgumentParser() parser.add_argument("--quiet", help="only output the final PLSSVM_TARGET_PLATFORMS string", action="store_true") +parser.add_argument("--gpus_only", help="only output gpu architectures to the final PLSSVM_TARGET_PLATFORMS string", + action="store_true") args = parser.parse_args() @@ -27,327 +29,141 @@ def cond_print(msg=""): print(msg) -# mapping of NVIDIA compute capabilities given the GPU name -# only GPUs with compute capability greater or equal than 6.0 are support -# https://developer.nvidia.com/cuda-gpus -nvidia_compute_capability_mapping = { - # Datacenter Products - "NVIDIA H100": "sm_90", - "NVIDIA L4": "sm_89", - "NVIDIA L40": "sm_89", - "NVIDIA A100": "sm_80", - "NVIDIA A40": "sm_86", - "NVIDIA A30": "sm_80", - "NVIDIA A10": "sm_86", - "NVIDIA A16": "sm_86", - "NVIDIA T4": "sm_75", - "NVIDIA V100": "sm_70", - "Tesla P100": "sm_60", - "Tesla P40": "sm_61", - "Tesla P4": "sm_61", - # NVIDIA Quadro and NVIDIA RTX - "RTX 6000": "sm_89", - "RTX A6000": "sm_86", - "RTX A5000": "sm_86", - "RTX A4000": "sm_86", - "T1000": "sm_75", - "T600": "sm_75", - "T400": "sm_75", - "Quadro RTX 8000": "sm_75", - "Quadro RTX 6000": "sm_75", - "Quadro RTX 5000": "sm_75", - "Quadro RTX 4000": "sm_75", - "Quadro GV100": "sm_70", - "Quadro GP100": "sm_60", - "Quadro P6000": "sm_61", - "Quadro P5000": "sm_61", - "Quadro P4000": "sm_61", - "Quadro P2200": "sm_61", - "Quadro P2000": "sm_61", - "Quadro P1000": "sm_61", - "Quadro P620": "sm_61", - "Quadro P600": "sm_61", - "Quadro P400": "sm_61", - "RTX A3000": "sm_86", - "RTX A2000": "sm_86", - "RTX 5000": "sm_75", - "RTX 4000": "sm_75", - "RTX 3000": "sm_75", - "T2000": "sm_75", - "T1200": "sm_75", - "T500": "sm_75", - "P620": "sm_61", - "P520": "sm_61", - "Quadro P5200": "sm_61", - "Quadro P4200": "sm_61", - "Quadro P3200": "sm_61", - "Quadro P3000": "sm_61", - "Quadro P500": "sm_61", - # GeForce and TITAN Products - "GeForce RTX 4090": "sm_89", - "GeForce RTX 4080": "sm_89", - "GeForce RTX 4070 Ti": "sm_89", - "GeForce RTX 3060": "sm_86", - "GeForce RTX 3090": "sm_86", - "GeForce RTX 3090 Ti": "sm_86", - "GeForce RTX 3080": "sm_86", - "GeForce RTX 3080 Ti": "sm_86", - "GeForce RTX 3070": "sm_86", - "GeForce RTX 3070 Ti": "sm_86", - "GeForce GTX 1650 Ti": "sm_75", - "NVIDIA TITAN RTX": "sm_75", - "GeForce RTX 2080 Ti": "sm_75", - "GeForce RTX 2080": "sm_75", - "GeForce RTX 2070": "sm_75", - "GeForce RTX 2060": "sm_75", - "NVIDIA TITAN V": "sm_70", - "NVIDIA TITAN Xp": "sm_61", - "NVIDIA TITAN X": "sm_61", - "GeForce GTX 1080 Ti": "sm_61", - "GeForce GTX 1080": "sm_61", - "GeForce GTX 1070 Ti": "sm_61", - "GeForce GTX 1070": "sm_61", - "GeForce GTX 1060": "sm_61", - "GeForce GTX 1050": "sm_61", - "GeForce RTX 3050 Ti": "sm_86", - "GeForce RTX 3050": "sm_86", - # Jetson Products - "Jetson AGX Orin": "sm_87", - "Jetson AGX Orin NX": "sm_87", - "Jetson AGX Orin Nano": "sm_87", - "Jetson AGX Xavier": "sm_72", - "Jetson AGX Xavier NX": "sm_72", -} - -# mapping of AMD architectures given the GPU name -# https://llvm.org/docs/AMDGPUUsage.html -amd_arch_mapping = { - # AMD Radeon GPUs - "AMD Instinct MI250X": "gfx90a", - "AMD Instinct MI250": "gfx90a", - "AMD Instinct MI210": "gfx90a", - "Radeon RX 7900 XTX": "gfx1101", - "Radeon RX 7900 XT": "gfx1101", - "Radeon RX 7900 GRE": "gfx1101", - "Radeon RX 7800 XT": "gfx1101", - "Radeon RX 7700 XT": "gfx1101", - "Radeon RX 7600": "gfx1101", - "Radeon RX 6700 XT": "gfx1031", - "Radeon RX 6800": "gfx1030", - "Radeon RX 6800 XT": "gfx1030", - "Radeon RX 6900 XT": "gfx1030", - "Radeon RX 5500": "gfx1012", - "Radeon RX 5500 XT": "gfx1012", - "Radeon Pro V520": "gfx1011", - "Radeon RX 5700": "gfx1010", - "Radeon RX 5700 XT": "gfx1010", - "Radeon Pro 5600 XT": "gfx1010", - "Radeon Pro 5600M": "gfx1010", - "Radeon Instinct MI100 Accelerator": "gfx908", - "Radeon Pro VII": "gfx906", - "Radeon VII": "gfx906", - "Radeon Instinct MI50": "gfx906", - "Radeon Instinct MI60": "gfx906", - "Radeon Vega Frontier Edition": "gfx900", - "Radeon RX Vega 56": "gfx900", - "Radeon RX Vega 64": "gfx900", - "Radeon RX Vega 64 Liquid": "gfx900", - "Radeon Instinct MI25": "gfx900", - "Radeon RX 460": "gfx803", - "Radeon Instinct MI6": "gfx803", - "Radeon RX 470": "gfx803", - "Radeon RX 480": "gfx803", - "Radeon Instinct MI8": "gfx803", - "Radeon R9 Nano": "gfx803", - "Radeon R9 Fury": "gfx803", - "Radeon R9 FuryX": "gfx803", - "Radeon Pro Duo": "gfx803", - "Radeon R9 285": "gfx802", - "Radeon R9 380": "gfx802", - "Radeon R9 385": "gfx802", - # AMD Ryzen iGPUs - "Ryzen 7 4700G": "gfx90c", - "Ryzen 7 4700GE": "gfx90c", - "Ryzen 5 4600G": "gfx90c", - "Ryzen 5 4600GE": "gfx90c", - "Ryzen 3 4300G": "gfx90c", - "Ryzen 3 4300GE": "gfx90c", - "Ryzen Pro 4000G": "gfx90c", - "Ryzen 7 Pro 4700G": "gfx90c", - "Ryzen 7 Pro 4750GE": "gfx90c", - "Ryzen 5 Pro 4650G": "gfx90c", - "Ryzen 5 Pro 4650GE": "gfx90c", - "Ryzen 3 Pro 4350G": "gfx90c", - "Ryzen 3 Pro 4350GE": "gfx90c", - "Ryzen 3 2200G": "gfx902", - "Ryzen 5 2400G": "gfx902", - # other AMD targets - "FirePro S7150": "gfx805", - "FirePro S7100": "gfx805", - "FirePro W7100": "gfx805", - "Mobile FirePro M7170": "gfx805", - "FirePro S9300x2": "gfx803", - "A6-8500P": "gfx801", - "Pro A6-8500B": "gfx801", - "A8-8600P": "gfx801", - "Pro A8-8600B": "gfx801", - "FX-8800P": "gfx801", - "Pro A12-8800B": "gfx801", - "A10-8700P": "gfx801", - "Pro A10-8700B": "gfx801", - "A10-8780P": "gfx801", - "A10-9600P": "gfx801", - "A12-9700P": "gfx801", - "A12-9730P": "gfx801", - "FX-9800P": "gfx801", - "FX-9830P": "gfx801", - "E2-9010": "gfx801", - "A6-9210": "gfx801", - "A9-9410": "gfx801", -} - +# TODO: maybe use "lspci -nn |grep -Ei 'VGA|DISPLAY'" ? # mapping of Intel architecture names # https://dgpu-docs.intel.com/devices/hardware-table.html # https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compilation/ahead-of-time-compilation.html intel_arch_mapping = { # Skylake - "skl": ["192A", "1932", "193B", "193A", "193D", "1923", "1926", "1927", "192B", "192D", "1912", "191B", "1913", - "1915", "1917", "191A", "1916", "1921", "191D", "191E", "1902", "1906", "190B", "190A", "190E"], + "skl": ["192A", "1932", "193B", "193A", "193D", "1923", "1926", "1927", "192B", "192D", "1912", "191B", "1913", + "1915", "1917", "191A", "1916", "1921", "191D", "191E", "1902", "1906", "190B", "190A", "190E"], # Gemini Lake - "glk": ["3185", "3184"], + "glk": ["3185", "3184"], # Apollo Lake - "Gen9": ["1A85", "5A85", "0A84", "1A84", "5A84"], + "Gen9": ["1A85", "5A85", "0A84", "1A84", "5A84"], # Kaby Lake - "kbl": ["593B", "5923", "5926", "5927", "5917", "5912", "591B", "5916", "5921", "591A", "591D", "591E", "591C", - "87C0", "5913", "5915", "5902", "5906", "590B", "590A", "5908", "590E"], + "kbl": ["593B", "5923", "5926", "5927", "5917", "5912", "591B", "5916", "5921", "591A", "591D", "591E", "591C", + "87C0", "5913", "5915", "5902", "5906", "590B", "590A", "5908", "590E"], # Coffee Lake - "cfl": ["3EA5", "3EA8", "3EA6", "3EA7", "3EA2", "3E90", "3E93", "3E99", "3E9C", "3EA1", "9BA5", "9BA8", "3EA4", - "9B21", "9BA0", "9BA2", "9BA4", "9BAA", "9BAB", "9BAC", "87CA", "3EA3", "9B41", "9BC0", "9BC2", "9BC4", - "9BCA", "9BCB", "9BCC", "3E91", "3E92", "3E98", "3E9B", "9BC5", "9BC8", "3E96", "3E9A", "3E94", "9BC6", - "9BE6", "9BF6", "3EA9", "3EA0"], + "cfl": ["3EA5", "3EA8", "3EA6", "3EA7", "3EA2", "3E90", "3E93", "3E99", "3E9C", "3EA1", "9BA5", "9BA8", "3EA4", + "9B21", "9BA0", "9BA2", "9BA4", "9BAA", "9BAB", "9BAC", "87CA", "3EA3", "9B41", "9BC0", "9BC2", "9BC4", + "9BCA", "9BCB", "9BCC", "3E91", "3E92", "3E98", "3E9B", "9BC5", "9BC8", "3E96", "3E9A", "3E94", "9BC6", + "9BE6", "9BF6", "3EA9", "3EA0"], # Ice Lake - "icllp": ["8A71", "8A56", "8A58", "8A5B", "8A5D", "8A54", "8A5A", "8A5C", "8A57", "8A59", "8A50", "8A51", "8A52", - "8A53"], + "icllp": ["8A71", "8A56", "8A58", "8A5B", "8A5D", "8A54", "8A5A", "8A5C", "8A57", "8A59", "8A50", "8A51", "8A52", + "8A53"], # Tiger Lake - "tgllp": ["9A60", "9A68", "9A70", "9A40", "9A49", "9A78", "9AC0", "9AC9", "9AD9", "9AF8"], + "tgllp": ["9A60", "9A68", "9A70", "9A40", "9A49", "9A78", "9AC0", "9AC9", "9AD9", "9AF8"], # Xe MAX - "dg1": ["4905"], + "dg1": ["4905"], # Rocket Lake - "Gen11": ["4C8A", "4C8B", "4C90", "4C9A", "4C8C"], + "Gen11": ["4C8A", "4C8B", "4C90", "4C9A", "4C8C"], # "Gen12LP": [], # Alder Lake - "adls": ["4680", "4682", "4688", "468A", "4690", "4692", "4693"], + "adls": ["4680", "4682", "4688", "468A", "4690", "4692", "4693"], # Alder Lake - "aldp": ["4626", "4628", "462A", "46A0", "46A1", "46A2", "46A3", "46A6", "46A8", "46AA", "46B0", "46B1", "46B2", - "46B3", "46C0", "46C1", "46C2", "46C3", "46D0", "46D1", "46D2"], + "aldp": ["4626", "4628", "462A", "46A0", "46A1", "46A2", "46A3", "46A6", "46A8", "46AA", "46B0", "46B1", "46B2", + "46B3", "46C0", "46C1", "46C2", "46C3", "46D0", "46D1", "46D2"], # # Alchemist # "": ["5690", "56A0", "5691", "56A1", "5692", "56A5" ,"5693", "5694", "56A6"], # # Flex Series # "": ["56C1", "56C0"], } intel_arch_to_name_mapping = { - "skl": "Skylake with Intel Processor Graphics Gen9", - "kbl": "Kaby Lake with Intel Processor Graphics Gen9", - "cfl": "Coffee Lake with Intel Processor Graphics Gen9", - "glk": "Gemini Lake with Intel Processor Graphics Gen9", - "icllp": "Ice Lake with Intel Processor Graphics Gen11", - "tgllp": "Tiger Lake with Intel Processor Graphics Gen12", - "dg1": "Intel Iris Xe MAX graphics", - "Gen9": "Intel Processor Graphics Gen9", - "Gen11": "Rocket Lake with Intel Processor Graphics Gen11", + "skl": "Skylake with Intel Processor Graphics Gen9", + "kbl": "Kaby Lake with Intel Processor Graphics Gen9", + "cfl": "Coffee Lake with Intel Processor Graphics Gen9", + "glk": "Gemini Lake with Intel Processor Graphics Gen9", + "icllp": "Ice Lake with Intel Processor Graphics Gen11", + "tgllp": "Tiger Lake with Intel Processor Graphics Gen12", + "dg1": "Intel Iris Xe MAX graphics", + "Gen9": "Intel Processor Graphics Gen9", + "Gen11": "Rocket Lake with Intel Processor Graphics Gen11", "Gen12LP": "Intel Processor Graphics Gen12 (Lower Power)", - "adls": "Alder Lake S with Intel Processor Graphics Gen12.2", - "aldp": "Alder Lake P with Intel Processor Graphics Gen12.2", + "adls": "Alder Lake S with Intel Processor Graphics Gen12.2", + "aldp": "Alder Lake P with Intel Processor Graphics Gen12.2", } # construct PLSSVM_TARGET_PLATFORMS string -plssvm_target_platforms = "" - -# CPU SIMD information for cpu target -simd_version_support = { - "avx512": False, - "avx2": False, - "avx": False, - "sse4_2": False, -} - -cpu_info = cpuinfo.get_cpu_info() - -for flag in cpu_info["flags"]: +plssvm_target_platforms = [] +if not args.gpus_only: + # CPU SIMD information for cpu target + simd_version_support = { + "avx512": False, + "avx2": False, + "avx": False, + "sse4_2": False, + } + + proc = subprocess.Popen(["lscpu"], stdout=subprocess.PIPE, shell=True) + (out, err) = proc.communicate() + for simd_version in simd_version_support.keys(): + if simd_version in str(out): + simd_version_support[simd_version] = True + + cond_print("supported CPU SIMD flags: {}\n".format(simd_version_support)) + + newest_simd_version = "" for key in simd_version_support: - if flag == key: - simd_version_support[key] = True - if flag.startswith("avx512"): - simd_version_support["avx512"] = True - -cond_print("{}: {}\n".format(cpu_info["brand_raw"], simd_version_support)) + if simd_version_support[key]: + newest_simd_version = key + break -newest_simd_version = "" -for key in simd_version_support: - if simd_version_support[key]: - newest_simd_version = key - break -plssvm_target_platforms += "cpu" + ("" if "".__eq__(newest_simd_version) else ":") + newest_simd_version + newest_simd_version = newest_simd_version.replace("_", ".") + plssvm_target_platforms.append("cpu" + ("" if "".__eq__(newest_simd_version) else ":") + newest_simd_version) # NVIDIA GPU information -nvidia_gpu_names = [gpu.name for gpu in GPUtil.getGPUs()] -nvidia_num_gpus = len(nvidia_gpu_names) - -if nvidia_num_gpus > 0: - nvidia_gpus = {x: nvidia_gpu_names.count(x) for x in nvidia_gpu_names} - nvidia_gpu_sm = {} - # get NVIDIA SM from GPU name - for name in nvidia_gpus: - found_name = False - for key in nvidia_compute_capability_mapping: - if re.search(key, name, re.IGNORECASE): - nvidia_gpu_sm[name] = nvidia_compute_capability_mapping[key] - found_name = True - break - - if not found_name: - raise RuntimeError("Unrecognized GPU name '{}'".format(name)) - - cond_print("Found {} NVIDIA GPU(s):".format(nvidia_num_gpus)) - for name in nvidia_gpus: - cond_print(" {}x {}: {}".format(nvidia_gpus[name], name, nvidia_gpu_sm[name])) - cond_print() - - plssvm_target_platforms += ";nvidia:" + ",".join({str(sm) for sm in nvidia_gpu_sm.values()}) +nvidia_gpus = [] +try: + cuda_driver = ctypes.cdll.LoadLibrary("libcuda.so") + cuda_flags = ctypes.c_int(0) + + cuda_driver.cuInit(cuda_flags) + cuda_count = ctypes.c_int(0) + cuda_driver.cuDeviceGetCount(ctypes.pointer(cuda_count)) + + for device in range(cuda_count.value): + major = ctypes.c_int(0) + minor = ctypes.c_int(0) + cuda_driver.cuDeviceComputeCapability(ctypes.pointer(major), ctypes.pointer(minor), device) + target = "sm_{}{}".format(major.value, minor.value) + nvidia_gpus.append(target) + + if len(nvidia_gpus)>0: + cond_print("Found {} NVIDIA GPU(s): [{}]\n".format(len(nvidia_gpus), ", ".join(nvidia_gpus))) + plssvm_target_platforms.append("nvidia:" + ",".join(set(nvidia_gpus))) +except: + pass # AMD GPU information -amd_gpu_names_plain = [pyamdgpuinfo.get_gpu(gpu_id).name for gpu_id in range(pyamdgpuinfo.detect_gpus())] -amd_gpu_names = list(filter(lambda gpu: gpu is not None, amd_gpu_names_plain)) -if len(amd_gpu_names_plain) > len(amd_gpu_names): - cond_print("Found {} AMD GPU(s) but pyamdgpuinfo returned 'None' for {} of them!\n".format( - len(amd_gpu_names_plain), - len(amd_gpu_names_plain) - len(amd_gpu_names))) -amd_num_gpus = len(amd_gpu_names) - -if amd_num_gpus > 0: - amd_gpus = {x: amd_gpu_names.count(x) for x in amd_gpu_names} - amd_gpu_arch = {} - # get AMD gfx from GPU name - for name in amd_gpus: - found_name = False - for key in amd_arch_mapping: - name_cleaned = name.replace("AMD", "").strip() - name_cleaned = name_cleaned.replace("(TM) ", "").strip() - if re.search(key, name_cleaned, re.IGNORECASE): - amd_gpu_arch[name] = amd_arch_mapping[key] - found_name = True - break - - if not found_name: - raise RuntimeError("Unrecognized GPU name '{}'".format(name)) - - cond_print("Found {} AMD GPU(s):".format(amd_num_gpus)) - for name in amd_gpus: - cond_print(" {}x {}: {}".format(amd_gpus[name], name, amd_gpu_arch[name])) - cond_print() - - plssvm_target_platforms += ";amd:" + ",".join({str(sm) for sm in amd_gpu_arch.values()}) +amd_gpus = [] +amd_nodes = Path('/sys/class/kfd/kfd/topology/nodes') +# check if the nodes directory exists +if amd_nodes.is_dir(): + label = 'gfx_target_version ' + # iterate over all property files + for filename in amd_nodes.glob('*/properties'): + with filename.open('r') as prop: + # iterate over all lines in the property file + for line in prop: + # check if the current line is the correct one + if not line.startswith(label): + continue + # convert the version to an integer + version = int(line[len(label):]) + if not version: + break + # convert the version to a gfx string + major_version = version // 10000 + minor_version = (version // 100) % 100 + step_version = version % 100 + target = 'gfx{:d}{:x}{:x}'.format(major_version, minor_version, step_version) + amd_gpus.append(target) + +if len(amd_gpus)>0: + cond_print("Found {} AMD GPU(s): [{}]\n".format(len(amd_gpus), ", ".join(amd_gpus))) + plssvm_target_platforms.append("amd:" + ",".join(set(amd_gpus))) # Intel GPU information intel_gpu_names = [] @@ -359,9 +175,9 @@ def cond_print(msg=""): break intel_num_gpus = len(intel_gpu_names) -if intel_num_gpus > 0: - intel_gpus = {x: intel_gpu_names.count(x) for x in intel_gpu_names} - intel_gpu_arch = {} +if intel_num_gpus>0: + intel_gpus = { x: intel_gpu_names.count(x) for x in intel_gpu_names } + intel_gpu_arch = { } for name in intel_gpus: for key in intel_arch_mapping: if any(re.search(arch, name, re.IGNORECASE) for arch in intel_arch_mapping[key]): @@ -375,7 +191,7 @@ def cond_print(msg=""): intel_gpu_arch[name])) cond_print() - plssvm_target_platforms += ";intel:" + ",".join({str(sm) for sm in intel_gpu_arch.values()}) + plssvm_target_platforms.append("intel:" + ",".join({ str(sm) for sm in intel_gpu_arch.values() })) cond_print("Possible -DPLSSVM_TARGET_PLATFORMS entries:") -print("{}".format(plssvm_target_platforms)) +print(";".join(plssvm_target_platforms)) From 7c02de9aea9823e26c39ea54ff3ad42887e63ef2 Mon Sep 17 00:00:00 2001 From: Marcel Breyer Date: Thu, 28 Nov 2024 13:46:22 +0100 Subject: [PATCH 002/202] Further reduce Python dependencies. --- CMakeLists.txt | 6 -- README.md | 6 +- install/python_requirements.txt | 13 +-- utility_scripts/plssvm_target_platforms.py | 100 ++++----------------- 4 files changed, 19 insertions(+), 106 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b705b2a6..ded6f9956 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,12 +263,6 @@ else () message(FATAL_ERROR "Can't find Python3. Please manually specify PLSSVM_TARGET_PLATFORMS (e.g. -DPLSSVM_TARGET_PLATFORMS=\"cpu;nvidia:sm_70,sm_86;amd:gfx906;intel:skl\"!") endif () - include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_python_libs.cmake) - set(PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS pylspci) - message(STATUS "Checking required Python3 libraries (${PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS}) to automatically determine the PLSSVM_TARGET_PLATFORMS.") - set(PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS_ERROR_MESSAGE "or manually define PLSSVM_TARGET_PLATFORMS (e.g. -DPLSSVM_TARGET_PLATFORMS=\"cpu;nvidia:sm_70,sm_86;amd:gfx906;intel:skl\"!") - check_python_libs(${PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS} ${PLSSVM_TARGET_PLATFORMS_PYTHON_SCRIPT_REQUIRED_LIBS_ERROR_MESSAGE}) - # run our `plssvm_target_platforms.py` script to determine the PLSSVM_TARGET_PLATFORMS string execute_process( COMMAND ${Python3_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/utility_scripts/plssvm_target_platforms.py" "--quiet" diff --git a/README.md b/README.md index fb05f3307..c1c33e873 100644 --- a/README.md +++ b/README.md @@ -178,11 +178,9 @@ Valid targets are: - `intel`: compile for Intel GPUs; **at least one** architectural specification is necessary, e.g., `intel:skl` At least one of the above targets must be present. If the option `PLSSVM_TARGET_PLATFORMS` is not present, the targets -are automatically determined using the Python3 `utility_scripts/plssvm_target_platforms.py` script (required Python3 dependencies: -[`argparse`](https://docs.python.org/3/library/argparse.html), and [`pylspci`](https://pypi.org/project/pylspci/)). +are automatically determined using the Python3 `utility_scripts/plssvm_target_platforms.py` script. -Note that when using DPC++ only a single architectural specification for `cpu`, `nvidia` or `amd` is allowed and that -automatically retrieving AMD GPU information on Windows is currently not supported due to `pyamdgpuinfo` limitations. +Note that when using DPC++ only a single architectural specification for `cpu`, `nvidia` or `amd` is allowed. ```bash diff --git a/install/python_requirements.txt b/install/python_requirements.txt index 4f555c79a..e9a7db4a2 100644 --- a/install/python_requirements.txt +++ b/install/python_requirements.txt @@ -1,8 +1,6 @@ ### optional and required python packages -## for the data set generation -# LIBSVM -argparse +## for the data set generation (LIBSVM file format) scikit-learn humanize @@ -17,20 +15,11 @@ pandas # for plotting the generated data set (only available if #features <= 3) matplotlib - -## for the automatic PLSSVM target platform determination -# argparse -pylspci - - ## for the performance tracker parser -# argparse # matplotlib pyyaml pint - ## for the performance analysis -# argparse # scikit-learn wrapt-timeout-decorator \ No newline at end of file diff --git a/utility_scripts/plssvm_target_platforms.py b/utility_scripts/plssvm_target_platforms.py index be171b222..554e847a7 100644 --- a/utility_scripts/plssvm_target_platforms.py +++ b/utility_scripts/plssvm_target_platforms.py @@ -14,8 +14,6 @@ from pathlib import Path import subprocess -import pylspci # get Intel GPU information - # parse command line arguments parser = argparse.ArgumentParser() parser.add_argument("--quiet", help="only output the final PLSSVM_TARGET_PLATFORMS string", action="store_true") @@ -29,62 +27,6 @@ def cond_print(msg=""): print(msg) -# TODO: maybe use "lspci -nn |grep -Ei 'VGA|DISPLAY'" ? -# mapping of Intel architecture names -# https://dgpu-docs.intel.com/devices/hardware-table.html -# https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compilation/ahead-of-time-compilation.html -intel_arch_mapping = { - # Skylake - "skl": ["192A", "1932", "193B", "193A", "193D", "1923", "1926", "1927", "192B", "192D", "1912", "191B", "1913", - "1915", "1917", "191A", "1916", "1921", "191D", "191E", "1902", "1906", "190B", "190A", "190E"], - # Gemini Lake - "glk": ["3185", "3184"], - # Apollo Lake - "Gen9": ["1A85", "5A85", "0A84", "1A84", "5A84"], - # Kaby Lake - "kbl": ["593B", "5923", "5926", "5927", "5917", "5912", "591B", "5916", "5921", "591A", "591D", "591E", "591C", - "87C0", "5913", "5915", "5902", "5906", "590B", "590A", "5908", "590E"], - # Coffee Lake - "cfl": ["3EA5", "3EA8", "3EA6", "3EA7", "3EA2", "3E90", "3E93", "3E99", "3E9C", "3EA1", "9BA5", "9BA8", "3EA4", - "9B21", "9BA0", "9BA2", "9BA4", "9BAA", "9BAB", "9BAC", "87CA", "3EA3", "9B41", "9BC0", "9BC2", "9BC4", - "9BCA", "9BCB", "9BCC", "3E91", "3E92", "3E98", "3E9B", "9BC5", "9BC8", "3E96", "3E9A", "3E94", "9BC6", - "9BE6", "9BF6", "3EA9", "3EA0"], - # Ice Lake - "icllp": ["8A71", "8A56", "8A58", "8A5B", "8A5D", "8A54", "8A5A", "8A5C", "8A57", "8A59", "8A50", "8A51", "8A52", - "8A53"], - # Tiger Lake - "tgllp": ["9A60", "9A68", "9A70", "9A40", "9A49", "9A78", "9AC0", "9AC9", "9AD9", "9AF8"], - # Xe MAX - "dg1": ["4905"], - # Rocket Lake - "Gen11": ["4C8A", "4C8B", "4C90", "4C9A", "4C8C"], - # - "Gen12LP": [], - # Alder Lake - "adls": ["4680", "4682", "4688", "468A", "4690", "4692", "4693"], - # Alder Lake - "aldp": ["4626", "4628", "462A", "46A0", "46A1", "46A2", "46A3", "46A6", "46A8", "46AA", "46B0", "46B1", "46B2", - "46B3", "46C0", "46C1", "46C2", "46C3", "46D0", "46D1", "46D2"], - # # Alchemist - # "": ["5690", "56A0", "5691", "56A1", "5692", "56A5" ,"5693", "5694", "56A6"], - # # Flex Series - # "": ["56C1", "56C0"], -} -intel_arch_to_name_mapping = { - "skl": "Skylake with Intel Processor Graphics Gen9", - "kbl": "Kaby Lake with Intel Processor Graphics Gen9", - "cfl": "Coffee Lake with Intel Processor Graphics Gen9", - "glk": "Gemini Lake with Intel Processor Graphics Gen9", - "icllp": "Ice Lake with Intel Processor Graphics Gen11", - "tgllp": "Tiger Lake with Intel Processor Graphics Gen12", - "dg1": "Intel Iris Xe MAX graphics", - "Gen9": "Intel Processor Graphics Gen9", - "Gen11": "Rocket Lake with Intel Processor Graphics Gen11", - "Gen12LP": "Intel Processor Graphics Gen12 (Lower Power)", - "adls": "Alder Lake S with Intel Processor Graphics Gen12.2", - "aldp": "Alder Lake P with Intel Processor Graphics Gen12.2", -} - # construct PLSSVM_TARGET_PLATFORMS string plssvm_target_platforms = [] if not args.gpus_only: @@ -166,32 +108,22 @@ def cond_print(msg=""): plssvm_target_platforms.append("amd:" + ",".join(set(amd_gpus))) # Intel GPU information -intel_gpu_names = [] -for device in pylspci.parsers.SimpleParser().run(): - if re.search("VGA", str(device.cls), re.IGNORECASE): - for key in intel_arch_mapping: - if any(re.search(arch, str(device.device), re.IGNORECASE) for arch in intel_arch_mapping[key]): - intel_gpu_names.append(str(device.device)) - break -intel_num_gpus = len(intel_gpu_names) - -if intel_num_gpus>0: - intel_gpus = { x: intel_gpu_names.count(x) for x in intel_gpu_names } - intel_gpu_arch = { } - for name in intel_gpus: - for key in intel_arch_mapping: - if any(re.search(arch, name, re.IGNORECASE) for arch in intel_arch_mapping[key]): - intel_gpu_arch[name] = key - break - - cond_print("Found {} Intel (i)GPU(s):".format(intel_num_gpus)) - for name in intel_gpus: - cond_print(" {}x {} ({}): {}".format(intel_gpus[name], name, - intel_arch_to_name_mapping[intel_gpu_arch[name]], - intel_gpu_arch[name])) - cond_print() - - plssvm_target_platforms.append("intel:" + ",".join({ str(sm) for sm in intel_gpu_arch.values() })) +intel_gpus = [] +pci_entry = subprocess.Popen(["lspci -nn | grep -Ei 'VGA|DISPLAY'"], stdout=subprocess.PIPE, shell=True) +(out, err) = pci_entry.communicate() +for vga in str(out).splitlines(): + # check if the device is an Intel GPU + if "Intel" in vga: + # extract the architecture hex-value from the lspci line + regex_pattern = r"\[[0-9]+:(.*?)\]" + pci_value = re.search("\[[0-9]+:(.*?)\]", vga) + if pci_value: + value = pci_value.group(1) + intel_gpus.append("0x{}".format(value)) + +if len(intel_gpus)>0: + cond_print("Found {} Intel GPU(s): [{}]\n".format(len(intel_gpus), ", ".join(intel_gpus))) + plssvm_target_platforms.append("intel:" + ",".join(set(intel_gpus))) cond_print("Possible -DPLSSVM_TARGET_PLATFORMS entries:") print(";".join(plssvm_target_platforms)) From bef258bd75f35abf00366f6e478b1ef83f863517 Mon Sep 17 00:00:00 2001 From: Marcel Breyer Date: Thu, 12 Dec 2024 15:13:12 +0100 Subject: [PATCH 003/202] Add new command line switch and enum value for two different SVM types: C-SVC and C-SVR. --- CMakeLists.txt | 1 + include/plssvm/detail/cmd/parser_train.hpp | 3 + include/plssvm/svm_types.hpp | 65 ++++++++++++++++++++++ src/plssvm/detail/cmd/parser_train.cpp | 6 ++ src/plssvm/svm_types.cpp | 59 ++++++++++++++++++++ 5 files changed, 134 insertions(+) create mode 100644 include/plssvm/svm_types.hpp create mode 100644 src/plssvm/svm_types.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a03058e0..8bc132b6b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,7 @@ set(PLSSVM_BASE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/shape.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/solver_types.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/target_platforms.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/svm_types.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/verbosity_levels.cpp ) diff --git a/include/plssvm/detail/cmd/parser_train.hpp b/include/plssvm/detail/cmd/parser_train.hpp index 73897249a..9ccb46448 100644 --- a/include/plssvm/detail/cmd/parser_train.hpp +++ b/include/plssvm/detail/cmd/parser_train.hpp @@ -21,6 +21,7 @@ #include "plssvm/constants.hpp" // plssvm::real_type #include "plssvm/parameter.hpp" // plssvm::parameter #include "plssvm/solver_types.hpp" // plssvm::solving_type +#include "plssvm/svm_types.hpp" // plssvm::svm_type #include "plssvm/target_platforms.hpp" // plssvm::target_platform #include "fmt/base.h" // fmt::formatter @@ -54,6 +55,8 @@ struct parser_train { /// The multi-class classification strategy used. classification_type classification{ classification_type::oaa }; + /// The used SVM: C-SVC or C-SVR. + svm_type svm{ svm_type::csvc }; /// The used backend: automatic (depending on the specified target_platforms), OpenMP, HPX, stdpar, CUDA, HIP, OpenCL, SYCL, or Kokkos. backend_type backend{ backend_type::automatic }; /// The target platform: automatic (depending on the used backend), CPUs or GPUs from NVIDIA, AMD, or Intel. diff --git a/include/plssvm/svm_types.hpp b/include/plssvm/svm_types.hpp new file mode 100644 index 000000000..f8044cb9e --- /dev/null +++ b/include/plssvm/svm_types.hpp @@ -0,0 +1,65 @@ +/** + * @file + * @author Alexander Van Craen + * @author Marcel Breyer + * @copyright 2018-today The PLSSVM project - All Rights Reserved + * @license This file is part of the PLSSVM project which is released under the MIT license. + * See the LICENSE.md file in the project root for full license information. + * + * @brief Defines an enumeration holding all implemented SVM types. + */ + +#ifndef PLSSVM_SVM_TYPES_HPP_ +#define PLSSVM_SVM_TYPES_HPP_ +#pragma once + +#include "fmt/base.h" // fmt::formatter +#include "fmt/ostream.h" // fmt::ostream_formatter + +#include // forward declare std::ostream and std::istream +#include // std::vector + +namespace plssvm { + +/** + * @brief Enum class for all implemented SVM types. + */ +enum class svm_type { + /** Use a C-SVM for classification. */ + csvc, + /** Use a C-CVM for regression. */ + csvr +}; + +/** + * @brief Return a list of all currently implemented SVM types. + * @return a list of the implemented SVM types (`[[nodiscard]]`) + */ +[[nodiscard]] std::vector list_available_svm_types(); + +/** + * @brief Output the @p svm to the given output-stream @p out. + * @param[in,out] out the output-stream to write the SVM type to + * @param[in] svm the SVM type + * @return the output-stream + */ +std::ostream &operator<<(std::ostream &out, svm_type svm); + +/** + * @brief Use the input-stream @p in to initialize the @p svm type. + * @param[in,out] in input-stream to extract the SVM type from + * @param[in] svm the SVM type + * @return the input-stream + */ +std::istream &operator>>(std::istream &in, svm_type &svm); + +} // namespace plssvm + +/// @cond Doxygen_suppress + +template <> +struct fmt::formatter : fmt::ostream_formatter { }; + +/// @endcond + +#endif // PLSSVM_SVM_TYPES_HPP_ diff --git a/src/plssvm/detail/cmd/parser_train.cpp b/src/plssvm/detail/cmd/parser_train.cpp index 31d5b8719..953af3c25 100644 --- a/src/plssvm/detail/cmd/parser_train.cpp +++ b/src/plssvm/detail/cmd/parser_train.cpp @@ -63,6 +63,7 @@ parser_train::parser_train(int argc, char **argv) { .set_tab_expansion() // clang-format off .add_options() + ("s,svm_type", "set type of SVM\n\t 0 -- C-SVC\n\t 1 -- C-SVR", cxxopts::value()->default_value(fmt::format("{}", detail::to_underlying(svm)))) ("t,kernel_type", kernel_type_help, cxxopts::value()->default_value(fmt::format("{}", detail::to_underlying(csvm_params.kernel_type)))) ("d,degree", "set degree in kernel function", cxxopts::value()->default_value(fmt::format("{}", csvm_params.degree))) ("g,gamma", fmt::format("set gamma in kernel function (default: {})", get_gamma_string(csvm_params.gamma)), cxxopts::value()) @@ -123,6 +124,11 @@ parser_train::parser_train(int argc, char **argv) { std::exit(EXIT_FAILURE); } + // parse svm_type and cast the value to the respective enum + if (result.count("svm_type")) { + svm = result["svm_type"].as(); + } + // parse kernel_type and cast the value to the respective enum if (result.count("kernel_type")) { csvm_params.kernel_type = result["kernel_type"].as(); diff --git a/src/plssvm/svm_types.cpp b/src/plssvm/svm_types.cpp new file mode 100644 index 000000000..e05bb1ecd --- /dev/null +++ b/src/plssvm/svm_types.cpp @@ -0,0 +1,59 @@ +/** + * @author Alexander Van Craen + * @author Marcel Breyer + * @copyright 2018-today The PLSSVM project - All Rights Reserved + * @license This file is part of the PLSSVM project which is released under the MIT license. + * See the LICENSE.md file in the project root for full license information. + */ + +#include "plssvm/svm_types.hpp" + +#include "plssvm/detail/assert.hpp" // PLSSVM_ASSERT +#include "plssvm/detail/string_utility.hpp" // plssvm::detail::to_lower_case +#include "plssvm/detail/utility.hpp" // plssvm::detail::contains +#include "plssvm/exceptions/exceptions.hpp" // plssvm::unsupported_backend_exception +#include "plssvm/target_platforms.hpp" // plssvm::target_platform + +#include "fmt/format.h" // fmt::format +#include "fmt/ranges.h" // fmt::join + +#include // std::array +#include // std::ios::failbit +#include // std::istream +#include // std::ostream +#include // std::string +#include // std::pair +#include // std::vector + +namespace plssvm { + +std::vector list_available_svm_types() { + return { svm_type::csvc, svm_type::csvr }; +} + +std::ostream &operator<<(std::ostream &out, const svm_type svm) { + switch (svm) { + case svm_type::csvc: + return out << "csvc"; + case svm_type::csvr: + return out << "csvr"; + } + return out << "unknown"; +} + +std::istream &operator>>(std::istream &in, svm_type &svm) { + std::string str; + in >> str; + detail::to_lower_case(str); + + if (str == "csvc" || str == "c-svc" || str == "c_svc" || str == "0") { + svm = svm_type::csvc; + } else if (str == "csvr" || str == "c-svr" || str == "c_svr" || str == "1") { + svm = svm_type::csvr; + } else { + in.setstate(std::ios::failbit); + } + return in; +} + +} // namespace plssvm From 95e9b37e22ca04fec0ca878863111f3001e5c066 Mon Sep 17 00:00:00 2001 From: Marcel Breyer Date: Thu, 12 Dec 2024 15:31:01 +0100 Subject: [PATCH 004/202] Move data_set.hpp file to new directory. --- include/plssvm/core.hpp | 2 +- include/plssvm/csvm.hpp | 2 +- include/plssvm/{ => data_set}/data_set.hpp | 6 +++--- include/plssvm/detail/cmd/data_set_variants.hpp | 2 +- include/plssvm/detail/io/libsvm_model_parsing.hpp | 2 +- include/plssvm/model.hpp | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) rename include/plssvm/{ => data_set}/data_set.hpp (99%) diff --git a/include/plssvm/core.hpp b/include/plssvm/core.hpp index 96e56d8e1..f22a05e23 100644 --- a/include/plssvm/core.hpp +++ b/include/plssvm/core.hpp @@ -21,7 +21,7 @@ #include "plssvm/constants.hpp" // verbosity flag und compile-time constants #include "plssvm/csvm.hpp" // the base C-SVM every backend is inheriting from #include "plssvm/csvm_factory.hpp" // a factory function to instantiate a C-SVM using a runtime backend; includes the available backend C-SVMs -#include "plssvm/data_set.hpp" // a data set used for training a C-SVM +#include "plssvm/data_set/data_set.hpp" // a data set used for training a C-SVM #include "plssvm/environment.hpp" // environment management functions and classes #include "plssvm/exceptions/exceptions.hpp" // exception hierarchy #include "plssvm/file_format_types.hpp" // all supported file format types diff --git a/include/plssvm/csvm.hpp b/include/plssvm/csvm.hpp index 3e0ea2472..d9c0768c2 100644 --- a/include/plssvm/csvm.hpp +++ b/include/plssvm/csvm.hpp @@ -15,7 +15,7 @@ #include "plssvm/classification_types.hpp" // plssvm::classification_type, plssvm::classification_type_to_full_string #include "plssvm/constants.hpp" // plssvm::real_type, plssvm::PADDING_SIZE -#include "plssvm/data_set.hpp" // plssvm::data_set +#include "plssvm/data_set/data_set.hpp" // plssvm::data_set #include "plssvm/detail/assert.hpp" // PLSSVM_ASSERT #include "plssvm/detail/data_distribution.hpp" // plssvm::detail::triangular_data_distribution #include "plssvm/detail/data_distribution.hpp" // plssvm::detail::data_distribution diff --git a/include/plssvm/data_set.hpp b/include/plssvm/data_set/data_set.hpp similarity index 99% rename from include/plssvm/data_set.hpp rename to include/plssvm/data_set/data_set.hpp index f344e5bae..d4346484a 100644 --- a/include/plssvm/data_set.hpp +++ b/include/plssvm/data_set/data_set.hpp @@ -9,8 +9,8 @@ * @brief Implements a data set class encapsulating all data points, features, and potential labels. */ -#ifndef PLSSVM_DATA_SET_HPP_ -#define PLSSVM_DATA_SET_HPP_ +#ifndef PLSSVM_DATA_SET_DATA_SET_HPP_ +#define PLSSVM_DATA_SET_DATA_SET_HPP_ #pragma once #include "plssvm/constants.hpp" // plssvm::real_type, plssvm::PADDING_SIZE @@ -895,4 +895,4 @@ void data_set::read_file(const std::string &filename, file_format_type format } // namespace plssvm -#endif // PLSSVM_DATA_SET_HPP_ +#endif // PLSSVM_DATA_SET_DATA_SET_HPP_ diff --git a/include/plssvm/detail/cmd/data_set_variants.hpp b/include/plssvm/detail/cmd/data_set_variants.hpp index 239d9a007..05f9721e4 100644 --- a/include/plssvm/detail/cmd/data_set_variants.hpp +++ b/include/plssvm/detail/cmd/data_set_variants.hpp @@ -13,7 +13,7 @@ #define PLSSVM_DETAIL_CMD_DATA_SET_VARIANTS_HPP_ #pragma once -#include "plssvm/data_set.hpp" // plssvm::data_set +#include "plssvm/data_set/data_set.hpp" // plssvm::data_set #include "plssvm/detail/cmd/parser_predict.hpp" // plssvm::detail::cmd::parser_predict #include "plssvm/detail/cmd/parser_scale.hpp" // plssvm::detail::cmd::parser_scale #include "plssvm/detail/cmd/parser_train.hpp" // plssvm::detail::cmd::parser_train diff --git a/include/plssvm/detail/io/libsvm_model_parsing.hpp b/include/plssvm/detail/io/libsvm_model_parsing.hpp index c42c82e8e..67d24b106 100644 --- a/include/plssvm/detail/io/libsvm_model_parsing.hpp +++ b/include/plssvm/detail/io/libsvm_model_parsing.hpp @@ -15,7 +15,7 @@ #include "plssvm/classification_types.hpp" // plssvm::classification_type #include "plssvm/constants.hpp" // plssvm::real_type, plssvm::PADDING_SIZE -#include "plssvm/data_set.hpp" // plssvm::data_set +#include "plssvm/data_set/data_set.hpp" // plssvm::data_set #include "plssvm/detail/assert.hpp" // PLSSVM_ASSERT #include "plssvm/detail/io/file_reader.hpp" // plssvm::detail::io::file_reader #include "plssvm/detail/io/libsvm_parsing.hpp" // plssvm::detail::io::parse_libsvm_num_features diff --git a/include/plssvm/model.hpp b/include/plssvm/model.hpp index 6522526b3..301230738 100644 --- a/include/plssvm/model.hpp +++ b/include/plssvm/model.hpp @@ -15,7 +15,7 @@ #include "plssvm/classification_types.hpp" // plssvm::classification_type #include "plssvm/constants.hpp" // plssvm::real_type -#include "plssvm/data_set.hpp" // plssvm::data_set +#include "plssvm/data_set/data_set.hpp" // plssvm::data_set #include "plssvm/detail/assert.hpp" // PLSSVM_ASSERT #include "plssvm/detail/io/file_reader.hpp" // plssvm::detail::io::file_reader #include "plssvm/detail/io/libsvm_model_parsing.hpp" // plssvm::detail::io::{parse_libsvm_model_header, parse_libsvm_model_data, write_libsvm_model_data} From 1e5cd2f2f820cfa4f78fd8a82a352b6310aec2ca Mon Sep 17 00:00:00 2001 From: Marcel Breyer Date: Thu, 12 Dec 2024 16:02:21 +0100 Subject: [PATCH 005/202] Move csvm.hpp file to new directory. --- CMakeLists.txt | 2 +- include/plssvm/backends/CUDA/csvm.hpp | 2 +- include/plssvm/backends/gpu_csvm.hpp | 2 +- include/plssvm/core.hpp | 2 +- include/plssvm/csvm_factory.hpp | 2 +- include/plssvm/{ => svm}/csvm.hpp | 6 +++--- src/plssvm/{ => svm}/csvm.cpp | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) rename include/plssvm/{ => svm}/csvm.hpp (99%) rename src/plssvm/{ => svm}/csvm.cpp (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bc132b6b..ca7553cf6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,12 +88,12 @@ set(PLSSVM_BASE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/detail/string_utility.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/detail/utility.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/exceptions/exceptions.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/svm/csvm.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/version/version.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/version/git_metadata/git_metadata.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/backend_types.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/classification_report.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/classification_types.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/csvm.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/file_format_types.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/gamma.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/plssvm/kernel_function_types.cpp diff --git a/include/plssvm/backends/CUDA/csvm.hpp b/include/plssvm/backends/CUDA/csvm.hpp index 5e0eed30d..d3f249cbf 100644 --- a/include/plssvm/backends/CUDA/csvm.hpp +++ b/include/plssvm/backends/CUDA/csvm.hpp @@ -18,10 +18,10 @@ #include "plssvm/backends/execution_range.hpp" // plssvm::detail::{dim_type, execution_range} #include "plssvm/backends/gpu_csvm.hpp" // plssvm::detail::gpu_csvm #include "plssvm/constants.hpp" // plssvm::real_type -#include "plssvm/csvm.hpp" // plssvm::detail::csvm_backend_exists #include "plssvm/detail/memory_size.hpp" // plssvm::detail::memory_size #include "plssvm/detail/type_traits.hpp" // PLSSVM_REQUIRES #include "plssvm/parameter.hpp" // plssvm::parameter +#include "plssvm/svm/csvm.hpp" // plssvm::detail::csvm_backend_exists #include "plssvm/target_platforms.hpp" // plssvm::target_platform #include // std::size_t diff --git a/include/plssvm/backends/gpu_csvm.hpp b/include/plssvm/backends/gpu_csvm.hpp index cf2641b38..a0c0007bf 100644 --- a/include/plssvm/backends/gpu_csvm.hpp +++ b/include/plssvm/backends/gpu_csvm.hpp @@ -15,7 +15,6 @@ #include "plssvm/backends/execution_range.hpp" // plssvm::detail::{dim_type, execution_range} #include "plssvm/constants.hpp" // plssvm::real_type, plssvm::PADDING_SIZE -#include "plssvm/csvm.hpp" // plssvm::csvm #include "plssvm/detail/assert.hpp" // PLSSVM_ASSERT #include "plssvm/detail/data_distribution.hpp" // plssvm::detail::{data_distribution, triangular_data_distribution, rectangular_data_distribution} #include "plssvm/detail/move_only_any.hpp" // plssvm::detail::{move_only_any, move_only_any_cast} @@ -24,6 +23,7 @@ #include "plssvm/parameter.hpp" // plssvm::parameter #include "plssvm/shape.hpp" // plssvm::shape #include "plssvm/solver_types.hpp" // plssvm::solver_type +#include "plssvm/svm/csvm.hpp" // plssvm::csvm #include "fmt/format.h" // fmt::format diff --git a/include/plssvm/core.hpp b/include/plssvm/core.hpp index f22a05e23..d643e03af 100644 --- a/include/plssvm/core.hpp +++ b/include/plssvm/core.hpp @@ -19,7 +19,6 @@ #include "plssvm/classification_report.hpp" // reports different metrics (precision, recall, f1 score, and support) for the different classes after scoring #include "plssvm/classification_types.hpp" // all supported multi-class classification strategies #include "plssvm/constants.hpp" // verbosity flag und compile-time constants -#include "plssvm/csvm.hpp" // the base C-SVM every backend is inheriting from #include "plssvm/csvm_factory.hpp" // a factory function to instantiate a C-SVM using a runtime backend; includes the available backend C-SVMs #include "plssvm/data_set/data_set.hpp" // a data set used for training a C-SVM #include "plssvm/environment.hpp" // environment management functions and classes @@ -33,6 +32,7 @@ #include "plssvm/parameter.hpp" // the C-SVM parameter #include "plssvm/shape.hpp" // shape for a matrix or device pointer #include "plssvm/solver_types.hpp" // all supported solver types (e.g., Conjugate Gradients with explicit, streaming, or implicit kernel matrix generation) +#include "plssvm/svm/csvm.hpp" // the base C-SVM every backend is inheriting from #include "plssvm/target_platforms.hpp" // all supported target platforms #include "plssvm/verbosity_levels.hpp" // all supported verbosity levels #include "plssvm/version/version.hpp" // version information diff --git a/include/plssvm/csvm_factory.hpp b/include/plssvm/csvm_factory.hpp index fb7760221..86a23c9bf 100644 --- a/include/plssvm/csvm_factory.hpp +++ b/include/plssvm/csvm_factory.hpp @@ -16,10 +16,10 @@ #include "plssvm/backend_types.hpp" // plssvm::backend, plssvm::csvm_to_backend_type_v #include "plssvm/backends/SYCL/detail/constants.hpp" // plssvm::sycl::csvm alias #include "plssvm/backends/SYCL/implementation_types.hpp" // plssvm::sycl::implementation_type -#include "plssvm/csvm.hpp" // plssvm::csvm, plssvm::csvm_backend_exists_v #include "plssvm/detail/igor_utility.hpp" // plssvm::detail::get_value_from_named_parameter #include "plssvm/exceptions/exceptions.hpp" // plssvm::unsupported_backend_exception #include "plssvm/parameter.hpp" // plssvm::sycl_implementation_type +#include "plssvm/svm/csvm.hpp" // plssvm::csvm, plssvm::csvm_backend_exists_v // only include requested/available backends #if defined(PLSSVM_HAS_OPENMP_BACKEND) diff --git a/include/plssvm/csvm.hpp b/include/plssvm/svm/csvm.hpp similarity index 99% rename from include/plssvm/csvm.hpp rename to include/plssvm/svm/csvm.hpp index d9c0768c2..54f84cbb8 100644 --- a/include/plssvm/csvm.hpp +++ b/include/plssvm/svm/csvm.hpp @@ -9,8 +9,8 @@ * @brief Defines the base class for all C-SVM backends and implements the functionality shared by all of them. */ -#ifndef PLSSVM_CSVM_HPP_ -#define PLSSVM_CSVM_HPP_ +#ifndef PLSSVM_SVM_CSVM_HPP_ +#define PLSSVM_SVM_CSVM_HPP_ #pragma once #include "plssvm/classification_types.hpp" // plssvm::classification_type, plssvm::classification_type_to_full_string @@ -986,4 +986,4 @@ constexpr bool csvm_backend_exists_v = csvm_backend_exists::value; } // namespace plssvm -#endif // PLSSVM_CSVM_HPP_ +#endif // PLSSVM_SVM_CSVM_HPP_ diff --git a/src/plssvm/csvm.cpp b/src/plssvm/svm/csvm.cpp similarity index 99% rename from src/plssvm/csvm.cpp rename to src/plssvm/svm/csvm.cpp index b2e1edfda..72b127183 100644 --- a/src/plssvm/csvm.cpp +++ b/src/plssvm/svm/csvm.cpp @@ -6,7 +6,7 @@ * See the LICENSE.md file in the project root for full license information. */ -#include "plssvm/csvm.hpp" +#include "plssvm/svm/csvm.hpp" #include "plssvm/constants.hpp" // plssvm::real_type, plssvm::PADDING_SIZE #include "plssvm/detail/assert.hpp" // PLSSVM_ASSERT From 3318c43048ee03232d6cace19872e7e84475d6d1 Mon Sep 17 00:00:00 2001 From: Marcel Breyer Date: Fri, 13 Dec 2024 21:07:51 +0100 Subject: [PATCH 006/202] Improve custom csvm_to_backend_type type trait to also directly handle csvm subclasses- --- include/plssvm/backend_types.hpp | 41 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/include/plssvm/backend_types.hpp b/include/plssvm/backend_types.hpp index 90a19bd5c..c2740d4c0 100644 --- a/include/plssvm/backend_types.hpp +++ b/include/plssvm/backend_types.hpp @@ -24,6 +24,7 @@ #include // forward declare std::ostream and std::istream #include // std::vector +#include // std::enable_if_t, std::is_base_of_v namespace plssvm { @@ -104,14 +105,14 @@ namespace detail { /** * @brief No `value` member variable if anything other than a C-SVM has been provided. */ -template -struct csvm_to_backend_type { }; +template +struct csvm_to_backend_type; /** * @brief Sets the `value` to `plssvm::backend_type::openmp` for the OpenMP C-SVM. */ -template <> -struct csvm_to_backend_type { +template +struct csvm_to_backend_type>> { /// The enum value representing the OpenMP backend. constexpr static backend_type value = backend_type::openmp; }; @@ -119,8 +120,8 @@ struct csvm_to_backend_type { /** * @brief Sets the `value` to `plssvm::backend_type::stdpar` for the C++ standard library parallelism C-SVM. */ -template <> -struct csvm_to_backend_type { +template +struct csvm_to_backend_type>> { /// The enum value representing the stdpar backend. constexpr static backend_type value = backend_type::stdpar; }; @@ -128,8 +129,8 @@ struct csvm_to_backend_type { /** * @brief Sets the `value` to `plssvm::backend_type::hpx` for the HPX C-SVM. */ -template <> -struct csvm_to_backend_type { +template +struct csvm_to_backend_type>> { /// The enum value representing the hpx backend. constexpr static backend_type value = backend_type::hpx; }; @@ -137,8 +138,8 @@ struct csvm_to_backend_type { /** * @brief Sets the `value` to `plssvm::backend_type::cuda` for the CUDA C-SVM. */ -template <> -struct csvm_to_backend_type { +template +struct csvm_to_backend_type>> { /// The enum value representing the CUDA backend. constexpr static backend_type value = backend_type::cuda; }; @@ -146,8 +147,8 @@ struct csvm_to_backend_type { /** * @brief Sets the `value` to `plssvm::backend_type::hip` for the HIP C-SVM. */ -template <> -struct csvm_to_backend_type { +template +struct csvm_to_backend_type>> { /// The enum value representing the HIP backend. constexpr static backend_type value = backend_type::hip; }; @@ -155,8 +156,8 @@ struct csvm_to_backend_type { /** * @brief Sets the `value` to `plssvm::backend_type::opencl` for the OpenCL C-SVM. */ -template <> -struct csvm_to_backend_type { +template +struct csvm_to_backend_type>> { /// The enum value representing the OpenCL backend. constexpr static backend_type value = backend_type::opencl; }; @@ -165,8 +166,8 @@ struct csvm_to_backend_type { * @brief Sets the `value` to `plssvm::backend_type::sycl` for the SYCL C-SVM using AdaptiveCpp as SYCL implementation. * @details Also sets a member variable `impl` to the value `plssvm::sycl::implementation_type::adaptivecpp` (only present for SYCL backends!). */ -template <> -struct csvm_to_backend_type { +template +struct csvm_to_backend_type>> { /// The enum value representing the SYCL (AdaptiveCpp) backend. constexpr static backend_type value = backend_type::sycl; /// The enum value representing the SYCL implementation for the (AdaptiveCpp) SYCL backend. @@ -177,8 +178,8 @@ struct csvm_to_backend_type { * @brief Sets the `value` to `plssvm::backend_type::sycl` for the SYCL C-SVM using DPC++ as SYCL implementation. * @details Also sets a member variable `impl` to the value `plssvm::sycl::implementation_type::dpcpp` (only present for SYCL backends!). */ -template <> -struct csvm_to_backend_type { +template +struct csvm_to_backend_type>> { /// The enum value representing the SYCL (DPC++) backend. constexpr static backend_type value = backend_type::sycl; /// The enum value representing the SYCL implementation for the (DPC++) SYCL backend. @@ -188,8 +189,8 @@ struct csvm_to_backend_type { /** * @brief Sets the `value` to `plssvm::backend_type::kokkos` for the Kokkos C-SVM. */ -template <> -struct csvm_to_backend_type { +template +struct csvm_to_backend_type>> { /// The enum value representing the Kokkos backend. constexpr static backend_type value = backend_type::kokkos; }; From af7c903233e5f637818cb371278a5d680dd26350 Mon Sep 17 00:00:00 2001 From: Marcel Breyer Date: Fri, 13 Dec 2024 22:13:44 +0100 Subject: [PATCH 007/202] csvm_to_backend_type now works again for incomplete types. --- include/plssvm/backend_types.hpp | 43 ++++++++++++++------------- include/plssvm/detail/type_traits.hpp | 16 +++++++++- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/include/plssvm/backend_types.hpp b/include/plssvm/backend_types.hpp index c2740d4c0..e4da7a08e 100644 --- a/include/plssvm/backend_types.hpp +++ b/include/plssvm/backend_types.hpp @@ -17,14 +17,15 @@ #include "plssvm/backends/SYCL/implementation_types.hpp" // plssvm::sycl::implementation_type #include "plssvm/detail/type_traits.hpp" // plssvm::detail::remove_cvref_t +#include "plssvm/detail/type_traits.hpp" // plssvm::detail::is_one_type_of #include "plssvm/target_platforms.hpp" // plssvm::list_available_target_platforms #include "fmt/base.h" // fmt::formatter #include "fmt/ostream.h" // fmt::ostream_formatter -#include // forward declare std::ostream and std::istream -#include // std::vector -#include // std::enable_if_t, std::is_base_of_v +#include // forward declare std::ostream and std::istream +#include // std::enable_if_t +#include // std::vector namespace plssvm { @@ -88,15 +89,15 @@ std::istream &operator>>(std::istream &in, backend_type &backend); /// @cond Doxygen_suppress // clang-format off // Forward declare all possible C-SVMs. -namespace openmp { class csvm; } -namespace stdpar { class csvm; } -namespace hpx { class csvm; } -namespace cuda { class csvm; } -namespace hip { class csvm; } -namespace opencl { class csvm; } -namespace adaptivecpp { class csvm; } -namespace dpcpp { class csvm; } -namespace kokkos { class csvm; } +namespace openmp { class csvm; class csvc; class csvr; } +namespace stdpar { class csvm; class csvc; class csvr; } +namespace hpx { class csvm; class csvc; class csvr; } +namespace cuda { class csvm; class csvc; class csvr; } +namespace hip { class csvm; class csvc; class csvr; } +namespace opencl { class csvm; class csvc; class csvr; } +namespace adaptivecpp { class csvm; class csvc; class csvr; } +namespace dpcpp { class csvm; class csvc; class csvr; } +namespace kokkos { class csvm; class csvc; class csvr; } // clang-format on @@ -112,7 +113,7 @@ struct csvm_to_backend_type; * @brief Sets the `value` to `plssvm::backend_type::openmp` for the OpenMP C-SVM. */ template -struct csvm_to_backend_type>> { +struct csvm_to_backend_type>> { /// The enum value representing the OpenMP backend. constexpr static backend_type value = backend_type::openmp; }; @@ -121,7 +122,7 @@ struct csvm_to_backend_type -struct csvm_to_backend_type>> { +struct csvm_to_backend_type>> { /// The enum value representing the stdpar backend. constexpr static backend_type value = backend_type::stdpar; }; @@ -130,7 +131,7 @@ struct csvm_to_backend_type -struct csvm_to_backend_type>> { +struct csvm_to_backend_type>> { /// The enum value representing the hpx backend. constexpr static backend_type value = backend_type::hpx; }; @@ -139,7 +140,7 @@ struct csvm_to_backend_type> * @brief Sets the `value` to `plssvm::backend_type::cuda` for the CUDA C-SVM. */ template -struct csvm_to_backend_type>> { +struct csvm_to_backend_type>> { /// The enum value representing the CUDA backend. constexpr static backend_type value = backend_type::cuda; }; @@ -148,7 +149,7 @@ struct csvm_to_backend_type * @brief Sets the `value` to `plssvm::backend_type::hip` for the HIP C-SVM. */ template -struct csvm_to_backend_type>> { +struct csvm_to_backend_type>> { /// The enum value representing the HIP backend. constexpr static backend_type value = backend_type::hip; }; @@ -157,7 +158,7 @@ struct csvm_to_backend_type> * @brief Sets the `value` to `plssvm::backend_type::opencl` for the OpenCL C-SVM. */ template -struct csvm_to_backend_type>> { +struct csvm_to_backend_type>> { /// The enum value representing the OpenCL backend. constexpr static backend_type value = backend_type::opencl; }; @@ -167,7 +168,7 @@ struct csvm_to_backend_type -struct csvm_to_backend_type>> { +struct csvm_to_backend_type>> { /// The enum value representing the SYCL (AdaptiveCpp) backend. constexpr static backend_type value = backend_type::sycl; /// The enum value representing the SYCL implementation for the (AdaptiveCpp) SYCL backend. @@ -179,7 +180,7 @@ struct csvm_to_backend_type -struct csvm_to_backend_type>> { +struct csvm_to_backend_type>> { /// The enum value representing the SYCL (DPC++) backend. constexpr static backend_type value = backend_type::sycl; /// The enum value representing the SYCL implementation for the (DPC++) SYCL backend. @@ -190,7 +191,7 @@ struct csvm_to_backend_type -struct csvm_to_backend_type>> { +struct csvm_to_backend_type>> { /// The enum value representing the Kokkos backend. constexpr static backend_type value = backend_type::kokkos; }; diff --git a/include/plssvm/detail/type_traits.hpp b/include/plssvm/detail/type_traits.hpp index 0ad95542d..35e32ca8b 100644 --- a/include/plssvm/detail/type_traits.hpp +++ b/include/plssvm/detail/type_traits.hpp @@ -21,7 +21,7 @@ #include // std::map, std::multimap #include // std::set, std::multiset #include // std::basic_string -#include // std::enable_if_t, std::remove_cv_t, std::remove_reference_t, std::false_type, std::true_type +#include // std::enable_if_t, std::remove_cv_t, std::remove_reference_t, std::is_same_v, std::false_type, std::true_type, std::is_same_v #include // std::unordered_map, std::unordered_multimap #include // std::unordered_set, std::unordered_multiset #include // std::vector @@ -342,6 +342,20 @@ constexpr bool is_unordered_associative_container_v = is_unordered_set_v || i template constexpr bool is_container_v = is_sequence_container_v || is_associative_container_v || is_unordered_associative_container_v; +/** + * @brief Check whether @p T is in the type set @p Types. + */ +template +struct is_one_type_of { + constexpr static bool value = (std::is_same_v || ...); +}; + +/** + * @copydoc plssvm::detail::is_one_type_of + */ +template +constexpr bool is_one_type_of_v = is_one_type_of::value; + } // namespace plssvm::detail #endif // PLSSVM_DETAIL_TYPE_TRAITS_HPP_ From c36ba3845cfeabd2b642e077eb0209b216bbf0ec Mon Sep 17 00:00:00 2001 From: Marcel Breyer Date: Tue, 17 Dec 2024 12:04:53 +0100 Subject: [PATCH 008/202] Setup first infrastructure for regression using C-SVR. Currently only implemented for CUDA. --- include/plssvm/backends/CUDA/csvm.hpp | 43 +++- include/plssvm/backends/gpu_csvm.hpp | 17 +- include/plssvm/core.hpp | 2 + include/plssvm/csvm_factory.hpp | 129 ++++++++--- .../data_set/classification_data_set.hpp | 208 ++++++++++++++++++ .../plssvm/data_set/regression_data_set.hpp | 44 ++++ .../plssvm/detail/cmd/data_set_variants.hpp | 33 ++- include/plssvm/svm/csvc.hpp | 84 +++++++ include/plssvm/svm/csvm.hpp | 24 +- include/plssvm/svm/csvr.hpp | 84 +++++++ src/main_predict.cpp | 9 +- src/main_train.cpp | 9 +- 12 files changed, 626 insertions(+), 60 deletions(-) create mode 100644 include/plssvm/data_set/classification_data_set.hpp create mode 100644 include/plssvm/data_set/regression_data_set.hpp create mode 100644 include/plssvm/svm/csvc.hpp create mode 100644 include/plssvm/svm/csvr.hpp diff --git a/include/plssvm/backends/CUDA/csvm.hpp b/include/plssvm/backends/CUDA/csvm.hpp index d3f249cbf..f61a5922a 100644 --- a/include/plssvm/backends/CUDA/csvm.hpp +++ b/include/plssvm/backends/CUDA/csvm.hpp @@ -19,9 +19,11 @@ #include "plssvm/backends/gpu_csvm.hpp" // plssvm::detail::gpu_csvm #include "plssvm/constants.hpp" // plssvm::real_type #include "plssvm/detail/memory_size.hpp" // plssvm::detail::memory_size -#include "plssvm/detail/type_traits.hpp" // PLSSVM_REQUIRES -#include "plssvm/parameter.hpp" // plssvm::parameter -#include "plssvm/svm/csvm.hpp" // plssvm::detail::csvm_backend_exists +#include "plssvm/detail/type_traits.hpp" // PLSSVM_REQUIRES, plssvm::detail::is_one_type_of +#include "plssvm/parameter.hpp" // plssvm::parameter, plssvm::detail::has_only_parameter_named_args_v +#include "plssvm/svm/csvc.hpp" // plssvm::csvc +#include "plssvm/svm/csvm.hpp" // PLSSVM_CREATE_CSVC_CSVR_TO_BACKEND_CSVC_CSVR_MAP, plssvm::detail::csvm_backend_exists +#include "plssvm/svm/csvr.hpp" // plssvm::csvr #include "plssvm/target_platforms.hpp" // plssvm::target_platform #include // std::size_t @@ -117,7 +119,7 @@ class csvm : public ::plssvm::detail::gpu_csvm plssvm::cuda::csvc +// plssvm::csvr -> plssvm::cuda::csvr +PLSSVM_CREATE_CSVC_CSVR_TO_BACKEND_CSVC_CSVR_MAP(cuda) + } // namespace cuda namespace detail { /** - * @brief Sets the `value` to `true` since C-SVMs using the CUDA backend are available. + * @brief Sets the `value` to `true` since C-SVMs (C-SVCs, C-SVRs) using the CUDA backend are available. */ -template <> -struct csvm_backend_exists : std::true_type { }; +template +struct csvm_backend_exists>> : std::true_type { }; } // namespace detail diff --git a/include/plssvm/backends/gpu_csvm.hpp b/include/plssvm/backends/gpu_csvm.hpp index a0c0007bf..2931b619f 100644 --- a/include/plssvm/backends/gpu_csvm.hpp +++ b/include/plssvm/backends/gpu_csvm.hpp @@ -44,7 +44,7 @@ namespace plssvm::detail { * @tparam pinned_memory_t the type of the pinned memory wrapper (dependent on the used backend) */ template