Class KernelLanguageSettings
- Namespace
- Orleans.GpuBridge.Backends.DotCompute.Configuration
- Assembly
- Orleans.GpuBridge.Backends.DotCompute.dll
Kernel language compilation configuration settings for the DotCompute backend.
public class KernelLanguageSettings
- Inheritance
-
KernelLanguageSettings
- Inherited Members
Examples
// CUDA-optimized configuration
var cudaSettings = new KernelLanguageSettings();
cudaSettings.PreferredLanguages.Clear();
cudaSettings.PreferredLanguages[GpuBackend.CUDA] = KernelLanguage.CUDA;
cudaSettings.PreferredLanguages[GpuBackend.OpenCL] = KernelLanguage.OpenCL;
cudaSettings.EnableLanguageTranslation = true;
// Cross-platform configuration
var crossPlatformSettings = new KernelLanguageSettings();
crossPlatformSettings.PreferredLanguages.Clear();
crossPlatformSettings.PreferredLanguages[GpuBackend.OpenCL] = KernelLanguage.OpenCL;
crossPlatformSettings.PreferredLanguages[GpuBackend.Vulkan] = KernelLanguage.SPIRV;
cudaSettings.EnableLanguageTranslation = true;
// C#-first configuration for .NET developers
var csharpSettings = new KernelLanguageSettings();
foreach (var platform in Enum.GetValues<GpuBackend>())
{
csharpSettings.PreferredLanguages[platform] = KernelLanguage.CSharp;
}
csharpSettings.EnableLanguageTranslation = true;
Remarks
This class provides comprehensive configuration for kernel programming language support, compilation preferences, and language-specific settings in the DotCompute backend. The backend supports multiple kernel languages and can automatically translate between them when needed.
Language selection affects: - Compilation performance and kernel optimization - Platform compatibility and portability - Development experience and debugging capabilities - Runtime performance characteristics - Feature availability and language-specific optimizations
The DotCompute backend provides intelligent language selection based on platform capabilities, performance characteristics, and developer preferences. When a preferred language is not available, the backend can automatically translate to a supported language or use a fallback language.
The default configuration provides optimal language selection for each platform while enabling automatic translation for maximum compatibility.
Properties
EnableLanguageTranslation
Gets or sets whether to enable automatic language translation between kernel languages.
public bool EnableLanguageTranslation { get; set; }
Property Value
- bool
trueto enable automatic language translation; otherwise,false. Default istrue.
Remarks
Automatic language translation allows the DotCompute backend to automatically convert kernel source code between different programming languages when the preferred language is not available or supported on a target platform.
Translation capabilities: - C# to platform-specific languages (CUDA, OpenCL, HLSL, MSL) - OpenCL to other C-based languages with platform adaptations - HLSL to SPIR-V for Vulkan compatibility - Basic cross-translation between similar C-based languages - Automatic API and syntax adaptation for platform differences
Translation benefits: - Improved platform compatibility and portability - Reduced need for multiple language implementations - Automatic optimization for target platform capabilities - Simplified development workflow for multi-platform deployment - Fallback support when preferred languages are unavailable
Translation limitations: - May not preserve all language-specific optimizations - Some advanced language features may not translate perfectly - Potential performance overhead from translated code - Debugging information may be less precise in translated code - Complex language constructs may require manual implementation
Translation is performed at compilation time and cached to minimize overhead. The system uses sophisticated analysis to ensure translated code maintains semantic correctness while optimizing for the target platform.
IncludeDirectories
Gets or sets the list of include directories for kernel compilation.
public List<string> IncludeDirectories { get; set; }
Property Value
- List<string>
A list of directory paths to search for header files and includes. Paths can be absolute or relative to the application working directory.
Examples
// Common kernel utilities
languageSettings.IncludeDirectories.Add("/opt/app/kernels/common");
languageSettings.IncludeDirectories.Add("./kernels/shared");
// Platform-specific libraries
languageSettings.IncludeDirectories.Add("/usr/local/cuda/include");
languageSettings.IncludeDirectories.Add("/opt/intel/opencl/include");
// Application-specific headers
languageSettings.IncludeDirectories.Add("../shared/gpu-headers");
languageSettings.IncludeDirectories.Add("./resources/kernels");
// Third-party libraries
languageSettings.IncludeDirectories.Add("/opt/nvidia/math-libs/include");
languageSettings.IncludeDirectories.Add("./third-party/thrust/include");
Remarks
Include directories specify the search paths for header files, libraries, and other resources referenced by kernel source code. This enables modular kernel development with shared code, libraries, and platform-specific headers.
Include directory use cases: - Shared kernel utilities and common functions - Platform-specific header files and extensions - Third-party GPU libraries and frameworks - Algorithm implementations and mathematical functions - Custom data structures and type definitions
Path resolution: - Absolute paths: Used directly for include searches - Relative paths: Resolved relative to application working directory - Environment variables: Expanded if supported by platform - Platform conventions: May follow platform-specific search patterns
Platform-specific behavior: - CUDA: Uses nvcc include search with standard CUDA headers - OpenCL: Uses compiler-specific include paths and OpenCL headers - HLSL: Uses HLSL compiler include search with DirectX headers - MSL: Uses Metal compiler include search with Metal framework headers - C#: May be converted to using statements in translated code
Include directories are searched in the order specified. Standard system and platform-specific include directories are automatically included by the compiler and do not need to be specified explicitly.
Security consideration: Include directories should only reference trusted locations to prevent inclusion of malicious or unintended code.
PreferredLanguages
Gets or sets the preferred kernel language for each compute platform.
public Dictionary<GpuBackend, KernelLanguage> PreferredLanguages { get; set; }
Property Value
- Dictionary<GpuBackend, KernelLanguage>
A dictionary mapping GpuBackend values to KernelLanguage preferences. Default includes optimal language selection for each platform.
Examples
// Performance-oriented configuration
languageSettings.PreferredLanguages[GpuBackend.CUDA] = KernelLanguage.CUDA;
languageSettings.PreferredLanguages[GpuBackend.OpenCL] = KernelLanguage.OpenCL;
languageSettings.PreferredLanguages[GpuBackend.Metal] = KernelLanguage.MSL;
// Developer-friendly configuration
foreach (var backend in Enum.GetValues<GpuBackend>())
{
languageSettings.PreferredLanguages[backend] = KernelLanguage.CSharp;
}
// Portability-focused configuration
languageSettings.PreferredLanguages[GpuBackend.CUDA] = KernelLanguage.OpenCL;
languageSettings.PreferredLanguages[GpuBackend.OpenCL] = KernelLanguage.OpenCL;
languageSettings.PreferredLanguages[GpuBackend.Vulkan] = KernelLanguage.SPIRV;
Remarks
This dictionary defines the preferred source language for kernel compilation on each platform. The DotCompute backend will attempt to use the specified language when compiling kernels for the corresponding platform.
Default language mappings are optimized for performance and platform capabilities: - CUDA: CUDA for native performance - OpenCL: OpenCL for compatibility - DirectCompute: HLSL for DirectX integration - Metal: MSL for Apple optimization - Vulkan: HLSL with SPIR-V compilation
Language selection considerations: - Performance: Native platform languages typically offer best performance - Portability: Cross-platform languages (OpenCL, C#) improve portability - Development experience: C# provides familiar syntax and tooling - Feature support: Some languages expose more platform-specific features - Ecosystem: Available libraries, tools, and community support
If a preferred language is not supported on a platform, the backend will: 1. Attempt automatic translation if EnableLanguageTranslation is enabled 2. Fall back to a supported language for the platform 3. Use C# as the ultimate fallback with translation
PreprocessorDefines
Gets or sets custom preprocessor definitions for kernel compilation.
public Dictionary<string, string> PreprocessorDefines { get; set; }
Property Value
- Dictionary<string, string>
A dictionary mapping preprocessor macro names to their values. Empty values represent macro definitions without values.
Examples
// Performance and debugging definitions
languageSettings.PreprocessorDefines["BLOCK_SIZE"] = "256";
languageSettings.PreprocessorDefines["ENABLE_BOUNDS_CHECK"] = ""; // Simple flag
languageSettings.PreprocessorDefines["MAX_ITERATIONS"] = "1000";
languageSettings.PreprocessorDefines["PI"] = "3.14159265359f";
// Platform-specific optimizations
languageSettings.PreprocessorDefines["USE_FAST_MATH"] = "";
languageSettings.PreprocessorDefines["UNROLL_LOOPS"] = "4";
languageSettings.PreprocessorDefines["CACHE_LINE_SIZE"] = "128";
// Feature flags
languageSettings.PreprocessorDefines["ENABLE_DOUBLE_PRECISION"] = "";
languageSettings.PreprocessorDefines["USE_TEXTURE_MEMORY"] = "";
languageSettings.PreprocessorDefines["DEBUG_VERBOSE"] = "";
Remarks
Preprocessor definitions allow you to control conditional compilation and provide compile-time constants to kernel source code. These definitions are applied during kernel compilation and can affect code generation, optimization, and feature selection.
Common use cases for preprocessor definitions: - Feature flags to enable/disable specific functionality - Platform-specific code paths and optimizations - Compile-time constants for algorithm parameters - Debug flags for development and troubleshooting - Version-specific compatibility macros
Definition formats:
- Simple macro: {"DEBUG", ""} defines #define DEBUG
- Valued macro: {"BLOCK_SIZE", "256"} defines #define BLOCK_SIZE 256
- Complex value: {"PI", "3.14159f"} defines #define PI 3.14159f
Platform considerations: - CUDA: Uses nvcc preprocessor with C++ extensions - OpenCL: Uses standard C preprocessor with OpenCL extensions - HLSL: Uses HLSL compiler preprocessor with shader-specific features - MSL: Uses Metal compiler preprocessor with C++ extensions - C#: Definitions may be converted to constants in translated code
The preprocessor definitions are applied to all kernel compilations. For platform-specific definitions, consider using conditional logic within the kernel code or platform-specific build configurations.