merge from giga
This commit is contained in:
+7
-15
@@ -1,21 +1,13 @@
|
|||||||
|
|
||||||
/build
|
/build
|
||||||
/.cr
|
/.cr
|
||||||
/.idea
|
/.idea
|
||||||
/.vs
|
/.vs
|
||||||
/.vscode
|
/.vscode
|
||||||
/StgSharp.Common/obj
|
*/obj
|
||||||
/StgSharp.Common/bin
|
*/bin
|
||||||
/StgSharp.Model/obj
|
*/build
|
||||||
/StgSharp.Model/bin
|
*/Debug
|
||||||
/StgSharp.Script/obj
|
*/Release
|
||||||
/StgSharp.Script/bin
|
|
||||||
/StgSharp.TerminalDialogue/obj
|
|
||||||
/StgSharp.TerminalDialogue/build
|
|
||||||
/StgSharpDebug/obj
|
|
||||||
/StgSharpDebug/bin
|
|
||||||
/STgSharpTest/obj
|
|
||||||
/STgSharpTest/bin
|
|
||||||
/TestResults
|
/TestResults
|
||||||
/StgSharp.Native/x64
|
*/x64
|
||||||
/StgSharp.Native/x64
|
*/.vs
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
System.Exception: Driver Verification Log needs to be created on a 'Release' configuration. The current selected configuration is ''.
|
|
||||||
在 Microsoft.SdvMenuCommand.DriverVerificationLicense..ctor()
|
|
||||||
在 Microsoft.SdvMenuCommand.SdvMenuCommandPackage.StaticToolsLogoMenuItemCallback(Object sender, EventArgs e)
|
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 Nitload StgSharp Team
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
StgSharp program uses the following open source projects,
|
||||||
|
I'd like to refer to them here and show my sincere appreciation,
|
||||||
|
while the names are sorted in no particular order
|
||||||
|
|
||||||
|
1. GLFW
|
||||||
|
|
||||||
|
Remote repository on: https://www.glfw.org/
|
||||||
|
|
||||||
|
License of GLFW:
|
||||||
|
|
||||||
|
Copyright (c) 2002-2006 Marcus Geelnard
|
||||||
|
|
||||||
|
Copyright (c) 2006-2019 Camilla Löwy
|
||||||
|
|
||||||
|
This software is provided 'as-is',
|
||||||
|
without any express or implied warranty.
|
||||||
|
In no event will the authors be held liable for
|
||||||
|
any damages arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it freely,
|
||||||
|
subject to the following restrictions:
|
||||||
|
|
||||||
|
The origin of this software must not be misrepresented;
|
||||||
|
you must not claim that you wrote the original software.
|
||||||
|
If you use this software in a product, an acknowledgment
|
||||||
|
in the product documentation would be appreciated but is not required.
|
||||||
|
|
||||||
|
Altered source versions must be plainly marked as such,
|
||||||
|
and must not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
2. GLAD, Khronos Specifications and other Specification headers
|
||||||
|
|
||||||
|
Web service available on https://gen.glad.sh/
|
||||||
|
|
||||||
|
The glad source code:
|
||||||
|
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2013-2022 David Herberth
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
The Khronos Specifications:
|
||||||
|
|
||||||
|
Copyright (c) 2013-2020 The Khronos Group Inc.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
3. docs.gl
|
||||||
|
|
||||||
|
4. Terminal.GUI
|
||||||
|
|
||||||
|
Remote repository on: https://github.com/gui-cs/Terminal.Gui
|
||||||
|
|
||||||
|
License of Terminal.GUI:
|
||||||
|
|
||||||
|
Copyright 2007-2011 Novell Inc
|
||||||
|
Copyright 2017 Microsoft Corp
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
5. IxMilia.Step
|
||||||
|
|
||||||
|
License of IxMilia.Step:
|
||||||
|
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) IxMilia.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -1,11 +1,222 @@
|
|||||||
# Stg# #
|
# StgSharp
|
||||||
|
|
||||||
Stg# is the new generation STG game engine. STG# is written in C# and runs on .NET platform.
|

|
||||||
|
|
||||||
The Stg# engine contains three parts:
|
StgSharp is a modern C# framework that combines game engine capabilities with high-performance computing features. Originally designed as a next-generation STG (Shoot 'em Up) game engine, it has evolved to include advanced mathematical libraries, parallel computing capabilities, and comprehensive graphics APIs.
|
||||||
|
|
||||||
1. A high efficiency math library
|
## Overview
|
||||||
2. A timeline manager
|
|
||||||
3. A game resource manager
|
|
||||||
|
|
||||||
Timeline of Stg# is controlled by a new type of scipt language called SGSL(Shooting Game Script Language). SGSL allows developers to manage files and debug in an reletively easy mod. Developers edit games in different "Organizations", which can be devided into "Generatings" and "Processings", which defines how bollet creats and move.
|
StgSharp provides both low-level and high-level bindings to OpenGL, multimedia control, and device management, offering everything needed to create STG games and high-performance applications. The framework is built on .NET 8 and supports Windows and Linux platforms.
|
||||||
|
|
||||||
|
## Core Modules
|
||||||
|
|
||||||
|
### StgSharp.Common
|
||||||
|
The main library containing core functionality:
|
||||||
|
|
||||||
|
- **Mathematics**: High-performance linear algebra, matrix operations, and mathematical utilities
|
||||||
|
- **Graphics**: OpenGL bindings, rendering pipeline, and graphics framework
|
||||||
|
- **High Performance**: SIMD operations, memory management, and parallel computing
|
||||||
|
- **Collections**: Specialized data structures and containers
|
||||||
|
- **MVVM**: Model-View-ViewModel framework for UI applications
|
||||||
|
- **Entities**: Game entity system and behavior management
|
||||||
|
- **Environment**: Platform abstraction and system integration
|
||||||
|
|
||||||
|
### StgSharp.Script
|
||||||
|
General-purpose syntax analysis framework:
|
||||||
|
|
||||||
|
- **Syntax Analysis Framework**: Provides a flexible framework for parsing and analyzing various programming languages
|
||||||
|
- **EXPRESS Language Support**: Specialized support for ISO 10303-11 EXPRESS language syntax parsing
|
||||||
|
- **Abstract Syntax Trees**: Language parsing and analysis infrastructure
|
||||||
|
- **Token Processing**: Lexical analysis and token management
|
||||||
|
- **Grammar Parsing**: Extensible grammar parsing and validation system
|
||||||
|
|
||||||
|
### StgSharp.Model
|
||||||
|
Geometric model loading and interpretation:
|
||||||
|
|
||||||
|
- **Geometric Model Loading**: Responsible for loading and interpreting geometric models from various formats
|
||||||
|
- **STEP Format Support**: Limited support for ISO 10303 STEP file format processing
|
||||||
|
- **Entity Management**: Model entity parsing and geometric data interpretation
|
||||||
|
- **Data Pipeline**: Efficient geometric data processing and transformation
|
||||||
|
- **Schema Validation**: Model structure validation and verification
|
||||||
|
|
||||||
|
### StgSharp.Native
|
||||||
|
Native library integration:
|
||||||
|
|
||||||
|
- **GLFW Integration**: Cross-platform window and input management
|
||||||
|
- **SIMD Operations**: Hardware-accelerated vector operations
|
||||||
|
- **Matrix Kernels**: Optimized matrix computation routines
|
||||||
|
- **Context Management**: Graphics context and resource management
|
||||||
|
|
||||||
|
### StgSharp.TerminalDialogue
|
||||||
|
Terminal-based user interface:
|
||||||
|
|
||||||
|
- **Interactive Terminal**: Command-line interface components
|
||||||
|
- **Dialogue System**: User interaction and input handling
|
||||||
|
- **Terminal Graphics**: Text-based UI rendering
|
||||||
|
|
||||||
|
## Key Features
|
||||||
|
|
||||||
|
### High-Performance Computing
|
||||||
|
- **Parallel Matrix Operations**: Multi-threaded matrix computations with optimized scheduling
|
||||||
|
- **SIMD Acceleration**: Hardware-optimized vector operations
|
||||||
|
- **Memory Management**: Custom allocators including HLSF (Hybrid Layer Segregated Fit)
|
||||||
|
- **Thread Pool Management**: Efficient task scheduling and execution
|
||||||
|
|
||||||
|
### Graphics and Rendering
|
||||||
|
- **OpenGL Integration**: Complete OpenGL API coverage
|
||||||
|
- **Cross-Platform Support**: Windows and Linux compatibility
|
||||||
|
- **Rendering Pipeline**: Flexible and extensible graphics framework
|
||||||
|
- **Shader Management**: Dynamic shader compilation and management
|
||||||
|
|
||||||
|
### Game Engine Capabilities
|
||||||
|
- **Entity System**: Flexible game object management
|
||||||
|
- **State Machine**: Game state and behavior management
|
||||||
|
- **Input Handling**: Comprehensive input and control systems
|
||||||
|
- **Resource Management**: Efficient asset loading and management
|
||||||
|
|
||||||
|
### Data Processing
|
||||||
|
- **STEP File Support**: Industrial data format processing
|
||||||
|
- **EXPRESS Language**: Domain-specific language compilation
|
||||||
|
- **Pipeline Processing**: Efficient data transformation workflows
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
### Technical Documentation
|
||||||
|
- [HLSF Allocator](StgSharp.Common/HighPerformance/Memory/InroductionToHLSF.md) - High-performance memory allocator documentation
|
||||||
|
- [Native Library Naming](StgSharp.Native/naming.md) - Native library file naming conventions
|
||||||
|
|
||||||
|
### Module-Specific Documentation
|
||||||
|
- **Mathematics**: Linear algebra, matrix operations, and mathematical utilities
|
||||||
|
- **Graphics**: OpenGL bindings, rendering, and graphics pipeline
|
||||||
|
- **High Performance**: SIMD operations, parallel computing, and memory management
|
||||||
|
- **Scripting**: General syntax analysis framework with EXPRESS language support
|
||||||
|
- **Modeling**: Geometric model loading and interpretation with STEP format support
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- .NET 8.0 or later
|
||||||
|
- Windows 10/11 or Linux
|
||||||
|
- x64 or ARM64 architecture
|
||||||
|
- OpenGL 3.3+ support
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
StgSharp is currently in development and requires compilation from source. **NuGet packages are not yet available** - you must build the project from source code.
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- **Windows**: Visual Studio 2022 or later with C++ development tools
|
||||||
|
- **Linux**: CMake and compatible C++ compiler (planned support)
|
||||||
|
- .NET 8.0 SDK or later
|
||||||
|
- Git for source code retrieval
|
||||||
|
|
||||||
|
### Building from Source
|
||||||
|
|
||||||
|
1. **Clone the repository**:
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/Nitload-NSI/StgSharp.git
|
||||||
|
cd StgSharp
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Windows (Recommended)**:
|
||||||
|
- Open `StgSharp.sln` in Visual Studio
|
||||||
|
- Build the solution (Debug or Release configuration)
|
||||||
|
- The native components will be automatically compiled
|
||||||
|
|
||||||
|
3. **Linux (Experimental)**:
|
||||||
|
```bash
|
||||||
|
# Build .NET components only
|
||||||
|
# Note: Native components are not yet supported on Linux
|
||||||
|
dotnet build
|
||||||
|
```
|
||||||
|
|
||||||
|
### Build Configuration
|
||||||
|
|
||||||
|
- **Debug**: Full debugging symbols, unoptimized
|
||||||
|
- **Release**: Optimized for performance
|
||||||
|
|
||||||
|
### Notes
|
||||||
|
|
||||||
|
- Windows compilation with Visual Studio is fully supported and tested
|
||||||
|
- Linux support is experimental and limited to .NET components only
|
||||||
|
- Native components (StgSharp.Native) are currently Windows-only and require MSVC
|
||||||
|
- CMake support for native components is not yet implemented
|
||||||
|
- Some features may not be available on all platforms
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
### Basic Graphics Application
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
|
||||||
|
/*To be implemented*/
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Matrix Operations
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
using StgSharp.Mathematics;
|
||||||
|
|
||||||
|
// Create matrices
|
||||||
|
var matrixA = Matrix<float>.Create(4, 4);
|
||||||
|
var matrixB = Matrix<float>.Create(4, 4);
|
||||||
|
|
||||||
|
// Perform parallel matrix multiplication
|
||||||
|
var result = matrixA * matrixB;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Memory Management
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
using StgSharp.HighPerformance.Memory;
|
||||||
|
|
||||||
|
// Create high-performance allocator
|
||||||
|
using var allocator = new HybridLayerSegregatedFitAllocator(64 * 1024 * 1024);
|
||||||
|
|
||||||
|
// Allocate memory
|
||||||
|
var handle = allocator.Alloc(1024);
|
||||||
|
// Use allocated memory
|
||||||
|
allocator.Free(handle);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
StgSharp follows a modular architecture where each component can be used independently or in combination:
|
||||||
|
|
||||||
|
- **Core Layer**: Fundamental data structures and utilities
|
||||||
|
- **Graphics Layer**: Rendering and graphics APIs
|
||||||
|
- **Performance Layer**: High-performance computing and optimization
|
||||||
|
- **Application Layer**: Game engine and application frameworks
|
||||||
|
- **Data Layer**: File processing and data modeling
|
||||||
|
|
||||||
|
## Performance Characteristics
|
||||||
|
|
||||||
|
- **Matrix Operations**: Optimized for large-scale computations
|
||||||
|
- **Memory Allocation**: O(1) allocation and deallocation with HLSF
|
||||||
|
- **Parallel Processing**: Multi-threaded execution with intelligent scheduling
|
||||||
|
- **SIMD Utilization**: Hardware-accelerated vector operations
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
StgSharp is developed by Nitload Space. Contributions are welcome, particularly in:
|
||||||
|
|
||||||
|
- Performance optimizations
|
||||||
|
- Cross-platform compatibility
|
||||||
|
- Documentation improvements
|
||||||
|
- New feature implementations
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
StgSharp is licensed under the MIT License. See [LICENSE](LICENSE) for details.
|
||||||
|
|
||||||
|
## Future Plans
|
||||||
|
|
||||||
|
- **Vulkan Support**: Planned for version 2.0
|
||||||
|
- **Enhanced Cross-Platform**: Improved Linux and mobile support
|
||||||
|
- **Performance Optimizations**: Further SIMD and parallel processing improvements
|
||||||
|
- **Extended Language Support**: Additional domain-specific languages
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
For questions, issues, or contributions, please refer to the project repository or contact the development team.
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<package>
|
|
||||||
<metadata>
|
|
||||||
<id>StgSharp</id>
|
|
||||||
<version>1.0.0</version>
|
|
||||||
<authors>Nitload</authors>
|
|
||||||
<owners>Nitload</owners>
|
|
||||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
|
||||||
<description></description>
|
|
||||||
<tags></tags>
|
|
||||||
</metadata>
|
|
||||||
<files>
|
|
||||||
<file src="netstandard2.1\StgSharp.dll" target="lib\netstandard2.1\StgSharp.dll" />
|
|
||||||
<file src="netstandard2.1\StgSharp.xml" target="lib\netstandard2.1\StgSharp.xml" />
|
|
||||||
<file src="netstandard2.1\StgSharpC.dll" target="lib\netstandard2.1\StgSharpC.dll" />
|
|
||||||
</files>
|
|
||||||
</package>
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"Version": 1,
|
|
||||||
"WorkspaceRootPath": "D:\\NitloadIndustry\\\u7814\u7A76\u9879\u76EE\\1-Flagship\\TH2020\\ProjectFile\\\u5185\u6838\u6E90\u4EE3\u7801\\StgSharp\\",
|
|
||||||
"Documents": [],
|
|
||||||
"DocumentGroupContainers": [
|
|
||||||
{
|
|
||||||
"Orientation": 0,
|
|
||||||
"VerticalTabListWidth": 256,
|
|
||||||
"DocumentGroups": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"Version": 1,
|
|
||||||
"WorkspaceRootPath": "D:\\NitloadIndustry\\\u7814\u7A76\u9879\u76EE\\1-Flagship\\TH2020\\ProjectFile\\\u5185\u6838\u6E90\u4EE3\u7801\\StgSharp\\",
|
|
||||||
"Documents": [],
|
|
||||||
"DocumentGroupContainers": [
|
|
||||||
{
|
|
||||||
"Orientation": 0,
|
|
||||||
"VerticalTabListWidth": 256,
|
|
||||||
"DocumentGroups": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
using StgSharp.Mathematics;
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
@@ -87,6 +88,7 @@ namespace StgSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
InternalIO.InitIntrinsicContext();
|
InternalIO.InitIntrinsicContext();
|
||||||
|
MatrixParallel.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LogError(Exception ex)
|
public static void LogError(Exception ex)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ using System.Threading.Tasks;
|
|||||||
namespace StgSharp.HighPerformance
|
namespace StgSharp.HighPerformance
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Explicit, Size = 64)]
|
[StructLayout(LayoutKind.Explicit, Size = 64)]
|
||||||
public unsafe struct MatrixKernel
|
public unsafe struct MatrixKernel<T> where T: unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
[FieldOffset(0)] internal fixed byte Buffer[64];
|
[FieldOffset(0)] internal fixed byte Buffer[64];
|
||||||
@@ -68,11 +68,11 @@ namespace StgSharp.HighPerformance
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MatrixKernel Fp32Unit
|
public static MatrixKernel<T> Unit
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
MatrixKernel kernel = new(true);
|
MatrixKernel<T> kernel = new(true);
|
||||||
kernel.FP32Buffer[0] = 1f;
|
kernel.FP32Buffer[0] = 1f;
|
||||||
kernel.FP32Buffer[3] = 1f;
|
kernel.FP32Buffer[3] = 1f;
|
||||||
kernel.FP32Buffer[8] = 1f;
|
kernel.FP32Buffer[8] = 1f;
|
||||||
@@ -81,7 +81,7 @@ namespace StgSharp.HighPerformance
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ref T UnsafeIndex<T>(int column, int row) where T: unmanaged, INumber<T>
|
public ref T UnsafeIndex(int column, int row)
|
||||||
{
|
{
|
||||||
ref M128 col = ref Unsafe.As<byte, M128>(ref Buffer[0]);
|
ref M128 col = ref Unsafe.As<byte, M128>(ref Buffer[0]);
|
||||||
col = ref Unsafe.Add(ref col, column);
|
col = ref Unsafe.Add(ref col, column);
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
//-----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// file="KernelParallel.cs"
|
|
||||||
// Project: StgSharp
|
|
||||||
// AuthorGroup: Nitload Space
|
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person
|
|
||||||
// obtaining a copy of this software and associated documentation
|
|
||||||
// files (the “Software”), to deal in the Software without restriction,
|
|
||||||
// including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
|
||||||
// and to permit persons to whom the Software is furnished to do so,
|
|
||||||
// subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and
|
|
||||||
// this permission notice shall be included in all copies
|
|
||||||
// or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
|
||||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
||||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
||||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
|
||||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
//
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
|
||||||
{
|
|
||||||
internal class KernelParallel { }
|
|
||||||
}
|
|
||||||
@@ -49,7 +49,30 @@ namespace StgSharp.Mathematics
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Matrix<float> result = GCMatrix<float>.FromDefault(left.ColumnLength, left.RowLength);
|
Matrix<float> result = GCMatrix<float>.FromDefault(left.ColumnLength, left.RowLength);
|
||||||
MatrixParallel.PublishTask();
|
unsafe
|
||||||
|
{
|
||||||
|
MatrixParallelTaskPackage* handle = MatrixParallelFactory.CreateBaseTask();
|
||||||
|
handle->Left = left.Buffer;
|
||||||
|
handle->Right = right.Buffer;
|
||||||
|
handle->Result = result.Buffer;
|
||||||
|
handle->ComputeHandle = (IntPtr)InternalIO.Intrinsic.kernel_add;
|
||||||
|
handle->LeftPrimOffset = 0;
|
||||||
|
handle->RightPrimOffset = 0;
|
||||||
|
handle->LeftPrimStride = left.KernelColumnLength;
|
||||||
|
handle->LeftSecOffset = 1;
|
||||||
|
handle->LeftPrimOffset = 0;
|
||||||
|
handle->RightPrimOffset = 0;
|
||||||
|
handle->RightPrimStride = right.KernelColumnLength;
|
||||||
|
handle->RightSecOffset = 1;
|
||||||
|
handle->RightPrimOffset = 0;
|
||||||
|
handle->ResultPrimOffset = 0;
|
||||||
|
handle->ResultPrimStride = result.KernelColumnLength;
|
||||||
|
handle->ResultSecOffset = 1;
|
||||||
|
handle->ResultPrimOffset = 0;
|
||||||
|
handle->PrimCount = left.KernelRowLength;
|
||||||
|
handle->SecCount = left.KernelColumnLength;
|
||||||
|
}
|
||||||
|
|
||||||
MatrixParallel.LaunchParallel(SleepMode.DeepSleep);
|
MatrixParallel.LaunchParallel(SleepMode.DeepSleep);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,12 @@ namespace StgSharp.Mathematics
|
|||||||
set => throw new NotImplementedException();
|
set => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal override unsafe MatrixKernel* Buffer
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get => _buffer;
|
||||||
|
}
|
||||||
|
|
||||||
public override unsafe ref MatrixKernel GetMatrixKernel(int column, int row)
|
public override unsafe ref MatrixKernel GetMatrixKernel(int column, int row)
|
||||||
{
|
{
|
||||||
AssertIndex(column, row);
|
AssertIndex(column, row);
|
||||||
|
|||||||
@@ -75,6 +75,12 @@ namespace StgSharp.Mathematics
|
|||||||
set => throw new NotImplementedException();
|
set => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal override unsafe MatrixKernel* Buffer
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get => k_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
public override unsafe ref MatrixKernel GetMatrixKernel(int column, int row)
|
public override unsafe ref MatrixKernel GetMatrixKernel(int column, int row)
|
||||||
{
|
{
|
||||||
AssertIndex(column, row);
|
AssertIndex(column, row);
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ using StgSharp.HighPerformance;
|
|||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
|
||||||
using hlsfAllocator = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
|
using hlsfAllocator = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
|
||||||
using hlsfHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
|
|
||||||
|
// using hlsfHandle = global::StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocationHandle;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
@@ -68,15 +68,23 @@ namespace StgSharp.Mathematics
|
|||||||
set;
|
set;
|
||||||
} = null;
|
} = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Length of the matrix in columns.
|
||||||
|
/// </summary>
|
||||||
public int ColumnLength { get; init; }
|
public int ColumnLength { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Length of the matrix in rows.
|
||||||
|
/// </summary>
|
||||||
public int RowLength { get; init; }
|
public int RowLength { get; init; }
|
||||||
|
|
||||||
public static MatrixAllocation DefaultAllocation { get; set; } = MatrixAllocation.GC;
|
public static MatrixAllocation DefaultAllocation { get; set; } = MatrixAllocation.GC;
|
||||||
|
|
||||||
protected int KernelColumnLength { get; init; }
|
internal abstract MatrixKernel<T>* Buffer { get; }
|
||||||
|
|
||||||
protected int KernelRowLength { get; init; }
|
protected internal int KernelColumnLength { get; init; }
|
||||||
|
|
||||||
|
protected internal int KernelRowLength { get; init; }
|
||||||
|
|
||||||
public static Matrix<T> FromDefault(int columnLength, int rowLength)
|
public static Matrix<T> FromDefault(int columnLength, int rowLength)
|
||||||
{
|
{
|
||||||
@@ -100,14 +108,14 @@ namespace StgSharp.Mathematics
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public abstract MatrixSegmentEnumeration GetColumnEnumeration();
|
public abstract MatrixSegmentEnumeration<T> GetColumnEnumeration();
|
||||||
|
|
||||||
public abstract ref MatrixKernel GetMatrixKernel(int column, int row);
|
public abstract ref MatrixKernel<T> GetMatrixKernel(int column, int row);
|
||||||
|
|
||||||
public abstract MatrixSegmentEnumeration GetRowEnumeration();
|
public abstract MatrixSegmentEnumeration<T> GetRowEnumeration();
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public abstract MatrixSegmentEnumeration GetSequentialEnumeration();
|
public abstract MatrixSegmentEnumeration<T> GetSequentialEnumeration();
|
||||||
|
|
||||||
[Obsolete("This method does not contain boarder check, so be careful on size or use indexer instead.", false)]
|
[Obsolete("This method does not contain boarder check, so be careful on size or use indexer instead.", false)]
|
||||||
public abstract ref T UnsafeIndex(int column, int row);
|
public abstract ref T UnsafeIndex(int column, int row);
|
||||||
@@ -125,38 +133,39 @@ namespace StgSharp.Mathematics
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly unsafe ref struct MatrixSegmentEnumeration(
|
public readonly unsafe ref struct MatrixSegmentEnumeration<T>(
|
||||||
MatrixKernel* source,
|
MatrixKernel<T>* source,
|
||||||
int stride,
|
int stride,
|
||||||
int size,
|
int size,
|
||||||
int secondaryStride,
|
int secondaryStride,
|
||||||
int secondarySize)
|
int secondarySize)
|
||||||
|
where T: unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly MatrixKernel* _source = source;
|
private readonly MatrixKernel<T>* _source = source;
|
||||||
private readonly int _secondarySize = secondarySize;
|
private readonly int _secondarySize = secondarySize;
|
||||||
private readonly int _secondaryStride = secondaryStride;
|
private readonly int _secondaryStride = secondaryStride;
|
||||||
|
|
||||||
private readonly int _size = size;
|
private readonly int _size = size;
|
||||||
private readonly int _stride = stride;
|
private readonly int _stride = stride;
|
||||||
|
|
||||||
public Enumerator GetEnumerator()
|
public Enumerator<T> GetEnumerator()
|
||||||
{
|
{
|
||||||
return new Enumerator(in this);
|
return new Enumerator<T>(in this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ref struct Enumerator(in MatrixSegmentEnumeration enumeration)
|
public ref struct Enumerator<T>(in MatrixSegmentEnumeration<T> enumeration) where T: unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
private MatrixKernel* _current = enumeration._source - enumeration._stride;
|
private MatrixKernel<T>* _current = enumeration._source - enumeration._stride;
|
||||||
private readonly MatrixKernel* _end = enumeration._source + enumeration._size;
|
private readonly MatrixKernel<T>* _end = enumeration._source + enumeration._size;
|
||||||
private readonly int _secondarySize = enumeration._secondarySize;
|
private readonly int _secondarySize = enumeration._secondarySize;
|
||||||
private readonly int _secondaryStride = enumeration._secondaryStride;
|
private readonly int _secondaryStride = enumeration._secondaryStride;
|
||||||
private readonly int _stride = enumeration._stride;
|
private readonly int _stride = enumeration._stride;
|
||||||
|
|
||||||
public readonly Segment Current
|
public readonly MatrixSegment<T> Current
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => new(_current, _secondarySize, _secondaryStride);
|
get => new(_current, _secondarySize, _secondaryStride);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,14 +179,15 @@ namespace StgSharp.Mathematics
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly unsafe ref struct Segment(MatrixKernel* source, int size, int stride)
|
public readonly unsafe ref struct MatrixSegment<T>(MatrixKernel<T>* source, int size, int stride)
|
||||||
|
where T: unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly MatrixKernel* _source = source;
|
private readonly MatrixKernel<T>* _source = source;
|
||||||
private readonly int _size = size;
|
private readonly int _size = size;
|
||||||
private readonly int _stride = stride;
|
private readonly int _stride = stride;
|
||||||
|
|
||||||
public ref MatrixKernel this[int index]
|
public ref MatrixKernel<T> this[int index]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -188,22 +198,22 @@ namespace StgSharp.Mathematics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Enumerator GetEnumerator()
|
public Enumerator<T> GetEnumerator()
|
||||||
{
|
{
|
||||||
return new Enumerator(_source, _size, _stride);
|
return new Enumerator<T>(_source, _size, _stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ref struct Enumerator(MatrixKernel* source, int count, int stride)
|
public ref struct Enumerator<T>(MatrixKernel<T>* source, int count, int stride) where T: unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly MatrixKernel* _end = source + (count * stride);
|
private readonly MatrixKernel<T>* _end = source + (count * stride);
|
||||||
private readonly int _stride = stride;
|
private readonly int _stride = stride;
|
||||||
|
|
||||||
public MatrixKernel* Current
|
public MatrixKernel<T>* Current
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get;
|
get;
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private set;
|
private set;
|
||||||
} = source - stride;
|
} = source - stride;
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ namespace StgSharp.Mathematics
|
|||||||
internal unsafe struct MatrixParallelTaskPackage
|
internal unsafe struct MatrixParallelTaskPackage
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static unsafe void Copy(MatrixParallelTaskPackage* source, MatrixParallelTaskPackage* target)
|
||||||
|
{
|
||||||
|
Buffer.MemoryCopy(source, target, sizeof(MatrixParallelTaskPackage), sizeof(MatrixParallelTaskPackage));
|
||||||
|
}
|
||||||
|
|
||||||
#region source
|
#region source
|
||||||
|
|
||||||
// Group 1: Left/Right matrix kernel base address
|
// Group 1: Left/Right matrix kernel base address
|
||||||
@@ -126,6 +131,6 @@ namespace StgSharp.Mathematics
|
|||||||
public long ReservedLong0; // 8
|
public long ReservedLong0; // 8
|
||||||
public long ReservedLong1; // 8
|
public long ReservedLong1; // 8
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-3
@@ -28,28 +28,54 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
using StgSharp.HighPerformance;
|
||||||
using StgSharp.HighPerformance.Memory;
|
using StgSharp.HighPerformance.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using hlsfAllocator = StgSharp.HighPerformance.Memory.HybridLayerSegregatedFitAllocator;
|
||||||
|
|
||||||
namespace StgSharp.Mathematics
|
namespace StgSharp.Mathematics
|
||||||
{
|
{
|
||||||
internal static unsafe class MatrixParallelFactory
|
internal static unsafe class MatrixParallelFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
private static readonly SlabAllocator<ScalarPacket> _scalarAllocator = SlabAllocator<ScalarPacket>.Create(64, SlabBufferLayout.Chunked, true);
|
private static hlsfAllocator _intermediateResult;
|
||||||
|
|
||||||
private static readonly SlabAllocator<MatrixParallelTaskPackage> _wrapAllocator = SlabAllocator<MatrixParallelTaskPackage>.Create(64, SlabBufferLayout.Chunked, true);
|
private static
|
||||||
|
#if NET9_0_OR_GREATER
|
||||||
|
Lock
|
||||||
|
#else
|
||||||
|
object
|
||||||
|
#endif
|
||||||
|
_hlsfLock = new();
|
||||||
|
|
||||||
|
private static SlabAllocator<ScalarPacket> _scalarAllocator ;
|
||||||
|
|
||||||
|
private static SlabAllocator<MatrixParallelTaskPackage> _wrapAllocator ;
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static MatrixParallelTaskPackage* CreateBaseTask()
|
||||||
|
{
|
||||||
|
MatrixParallelTaskPackage* p = (MatrixParallelTaskPackage*)_wrapAllocator.Allocate();
|
||||||
|
Span<byte> s = new Span<byte>((byte*)p, sizeof(MatrixParallelTaskPackage));
|
||||||
|
s.Fill(0);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static ScalarPacket* CreateScalarPacket()
|
public static ScalarPacket* CreateScalarPacket()
|
||||||
{
|
{
|
||||||
ScalarPacket* p = (ScalarPacket*)_scalarAllocator.Allocate();
|
ScalarPacket* p = (ScalarPacket*)_scalarAllocator.Allocate();
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD:StgSharp.Common/Mathematics/Linear/MatrixParallel.TaskWrapFactory.cs
|
||||||
public static MatrixParallelTaskPackage* FromTaskWrap(MatrixParallelTaskPackage* source, int offset)
|
public static MatrixParallelTaskPackage* FromTaskWrap(MatrixParallelTaskPackage* source, int offset)
|
||||||
{
|
{
|
||||||
MatrixParallelTaskPackage* p = (MatrixParallelTaskPackage*)_wrapAllocator.Allocate();
|
MatrixParallelTaskPackage* p = (MatrixParallelTaskPackage*)_wrapAllocator.Allocate();
|
||||||
@@ -62,11 +88,15 @@ namespace StgSharp.Mathematics
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=======
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
>>>>>>> 8007eee8461498a85a9515e8fd076f03cb552b64:StgSharp.Common/Mathematics/Linear/MatrixParallel.TaskFactory.cs
|
||||||
public static void Release(ScalarPacket* source)
|
public static void Release(ScalarPacket* source)
|
||||||
{
|
{
|
||||||
_scalarAllocator.Free((nuint)source);
|
_scalarAllocator.Free((nuint)source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Release(MatrixParallelTaskPackage* source)
|
public static void Release(MatrixParallelTaskPackage* source)
|
||||||
{
|
{
|
||||||
if (source->Scalar != null) {
|
if (source->Scalar != null) {
|
||||||
@@ -75,8 +105,10 @@ namespace StgSharp.Mathematics
|
|||||||
_wrapAllocator.Free((nuint)source);
|
_wrapAllocator.Free((nuint)source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SliceTask(MatrixParallelTaskPackage* source, Span<IntPtr> group)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
internal static void Init()
|
||||||
{
|
{
|
||||||
|
<<<<<<< HEAD:StgSharp.Common/Mathematics/Linear/MatrixParallel.TaskWrapFactory.cs
|
||||||
int count = group.Length;
|
int count = group.Length;
|
||||||
group[0] = (nint)source;
|
group[0] = (nint)source;
|
||||||
int l = source->LeftPrimStride, r = source->RightPrimStride, res = source->ResultPrimStride, c = source->PrimCount / count;
|
int l = source->LeftPrimStride, r = source->RightPrimStride, res = source->ResultPrimStride, c = source->PrimCount / count;
|
||||||
@@ -105,6 +137,11 @@ namespace StgSharp.Mathematics
|
|||||||
((MatrixParallelTaskPackage*)group[targetIndex])->PrimCount++;
|
((MatrixParallelTaskPackage*)group[targetIndex])->PrimCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
_scalarAllocator = SlabAllocator<ScalarPacket>.Create(64, SlabBufferLayout.Chunked, true);
|
||||||
|
_wrapAllocator = SlabAllocator<MatrixParallelTaskPackage>.Create(64, SlabBufferLayout.Chunked, true);
|
||||||
|
_intermediateResult = new hlsfAllocator((nuint)(sizeof(MatrixKernel) * 64));
|
||||||
|
>>>>>>> 8007eee8461498a85a9515e8fd076f03cb552b64:StgSharp.Common/Mathematics/Linear/MatrixParallel.TaskFactory.cs
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -33,6 +33,7 @@ using StgSharp.HighPerformance.Memory;
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO.Pipes;
|
using System.IO.Pipes;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -68,10 +69,7 @@ namespace StgSharp.Mathematics
|
|||||||
|
|
||||||
private static Thread[] _threads;
|
private static Thread[] _threads;
|
||||||
private static MatrixParallelWrap[] _wraps;
|
private static MatrixParallelWrap[] _wraps;
|
||||||
private static readonly (int a, int b)[] LookupTable =
|
private static readonly (int a, int b)[] LookupTable = [ (1, 1), (0, 2), (3, 0), (2, 1), (1, 2), (0, 3), (3, 1), (2, 2), (1, 3), (0, 4), (3, 2), (2, 3), (1, 4), (0, 5), ];
|
||||||
[(1, 1), (0, 2), (3, 0), (2, 1),
|
|
||||||
(1, 2), (0, 3), (3, 1), (2, 2), (1, 3),
|
|
||||||
(0, 4), (3, 2), (2, 3), (1, 4), (0, 5),];
|
|
||||||
private static volatile int RemainThreadCount = 0;
|
private static volatile int RemainThreadCount = 0;
|
||||||
|
|
||||||
private static readonly object _lock = new();
|
private static readonly object _lock = new();
|
||||||
@@ -79,9 +77,13 @@ namespace StgSharp.Mathematics
|
|||||||
|
|
||||||
public static bool SupportParallel { get; } = Environment.ProcessorCount > 6;
|
public static bool SupportParallel { get; } = Environment.ProcessorCount > 6;
|
||||||
|
|
||||||
public static bool IsParallelMeaningful { get; } = Environment.ProcessorCount > 6;
|
public static bool IsParallelMeaningful { get; } = Environment.ProcessorCount > 6 && IsInitialized;
|
||||||
|
|
||||||
internal static MatrixParallelWrap.Handle LeaderHandle { get; private set; }
|
public static MatrixParallelWrap.Handle LeaderHandle { get; private/**/ set; }
|
||||||
|
|
||||||
|
private static bool IsInitialized { get; set; } = false;
|
||||||
|
|
||||||
|
private static Queue<IntPtr> LeaderTask { get; set; }
|
||||||
|
|
||||||
public static void EndParallel()
|
public static void EndParallel()
|
||||||
{
|
{
|
||||||
@@ -105,18 +107,41 @@ namespace StgSharp.Mathematics
|
|||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
if (IsInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MatrixParallelFactory.Init();
|
||||||
int count = Environment.ProcessorCount - 4;
|
int count = Environment.ProcessorCount - 4;
|
||||||
count = count == 5 ? 4 : count;
|
count = count == 5 ? 4 : count;
|
||||||
int _3wrap = 0, _4wrap = 0;
|
|
||||||
_threads = new Thread[count];
|
_threads = new Thread[count];
|
||||||
if (count < 6) { } else if (count == 6) { } else { }
|
if (count < 6)
|
||||||
|
{
|
||||||
|
_wraps = [ new MatrixParallelWrap(0, count, true) ];
|
||||||
|
} else if (count == 6)
|
||||||
|
{
|
||||||
|
_wraps = [ new MatrixParallelWrap(0, 3, true), new MatrixParallelWrap(3, 3, false) ];
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
(int _3wrap, int _4wrap) = FastDecompose(count);
|
||||||
|
_wraps = new MatrixParallelWrap[_3wrap + _4wrap];
|
||||||
|
int id = 0, idx = 0;
|
||||||
|
for (; idx < _3wrap; idx++, id += 3) {
|
||||||
|
_wraps[idx] = new MatrixParallelWrap(idx, 3, id == 0);
|
||||||
|
}
|
||||||
|
for (; idx < _3wrap + _4wrap; idx++, id += 4) {
|
||||||
|
_wraps[idx] = new MatrixParallelWrap(id, 4, id == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
LeaderHandle = new MatrixParallelWrap.Handle(0, _wraps[0]);
|
LeaderHandle = new MatrixParallelWrap.Handle(0, _wraps[0]);
|
||||||
|
LeaderTask = LeaderHandle.Wrap.GetWorkerTaskQueue(0);
|
||||||
|
IsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LaunchParallel(SleepMode afterWork)
|
public static void LaunchParallel(SleepMode afterWork)
|
||||||
{
|
{
|
||||||
RemainThreadCount = _threads.Length;
|
RemainThreadCount = _threads.Length;
|
||||||
_AfterWork = (ThreadPriority)afterWork;
|
_AfterWork = (ThreadPriority)afterWork;
|
||||||
|
SetAllWrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@@ -125,10 +150,22 @@ namespace StgSharp.Mathematics
|
|||||||
Monitor.Enter(_lock);
|
Monitor.Enter(_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PublishTask() { }
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static unsafe void MatrixParallelLeaderWork()
|
||||||
|
{
|
||||||
|
MatrixParallelWrap.ExecuteTaskPackage(LeaderTask);
|
||||||
|
_ = Interlocked.Decrement(ref RemainThreadCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void ResetThreadCount()
|
||||||
|
{
|
||||||
|
RemainThreadCount = _threads.Length;
|
||||||
|
}
|
||||||
|
|
||||||
public static void SetAllWrap()
|
public static void SetAllWrap()
|
||||||
{
|
{
|
||||||
|
ResetThreadCount();
|
||||||
foreach (MatrixParallelWrap item in _wraps) {
|
foreach (MatrixParallelWrap item in _wraps) {
|
||||||
_ = item.SchedulerReset.Set();
|
_ = item.SchedulerReset.Set();
|
||||||
}
|
}
|
||||||
@@ -243,12 +280,13 @@ namespace StgSharp.Mathematics
|
|||||||
// TODO task publication to worker in wrap
|
// TODO task publication to worker in wrap
|
||||||
wrap.SetAllWorker();
|
wrap.SetAllWorker();
|
||||||
ExecuteTaskPackage(taskQueue);
|
ExecuteTaskPackage(taskQueue);
|
||||||
|
_ = Interlocked.Decrement(ref RemainThreadCount);
|
||||||
self.Priority = _AfterWork;
|
self.Priority = _AfterWork;
|
||||||
} while (true);
|
} while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static unsafe void ExecuteTaskPackage(Queue<IntPtr> taskQueue)
|
public static unsafe void ExecuteTaskPackage(Queue<IntPtr> taskQueue)
|
||||||
{
|
{
|
||||||
while (taskQueue.TryDequeue(out nint handle))
|
while (taskQueue.TryDequeue(out nint handle))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -179,6 +179,7 @@
|
|||||||
<ClInclude Include="sn-head\khrplatform.h" />
|
<ClInclude Include="sn-head\khrplatform.h" />
|
||||||
<ClInclude Include="sn-head\sn_internal.h" />
|
<ClInclude Include="sn-head\sn_internal.h" />
|
||||||
<ClInclude Include="sn-head\sn_intrinsic.h" />
|
<ClInclude Include="sn-head\sn_intrinsic.h" />
|
||||||
|
<ClInclude Include="sn-head\sn_matkernel.h" />
|
||||||
<ClInclude Include="sn-head\stb_image.h" />
|
<ClInclude Include="sn-head\stb_image.h" />
|
||||||
<ClInclude Include="sn-head\StgSharpNative.h" />
|
<ClInclude Include="sn-head\StgSharpNative.h" />
|
||||||
<ClInclude Include="sn-head\wgl.h" />
|
<ClInclude Include="sn-head\wgl.h" />
|
||||||
|
|||||||
@@ -83,6 +83,9 @@
|
|||||||
<ClInclude Include="glfw\glfw3.h">
|
<ClInclude Include="glfw\glfw3.h">
|
||||||
<Filter>头文件</Filter>
|
<Filter>头文件</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="sn-head\sn_matkernel.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Library Include="glfw\glfw3.lib">
|
<Library Include="glfw\glfw3.lib">
|
||||||
|
|||||||
@@ -5,7 +5,10 @@
|
|||||||
#ifndef SSC_INTRIN
|
#ifndef SSC_INTRIN
|
||||||
#define SSC_INTRIN
|
#define SSC_INTRIN
|
||||||
|
|
||||||
|
#define SSC_INTRIN_HEAD
|
||||||
|
|
||||||
#include "StgSharpNative.h"
|
#include "StgSharpNative.h"
|
||||||
|
#include "sn_matkernel.h"
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#include <smmintrin.h>
|
#include <smmintrin.h>
|
||||||
|
|
||||||
@@ -39,25 +42,6 @@ typedef union mat_kernel {
|
|||||||
float m[4][4];
|
float m[4][4];
|
||||||
} mat_kernel;
|
} mat_kernel;
|
||||||
|
|
||||||
typedef union column_2 {
|
|
||||||
__m256 stream;
|
|
||||||
__m128 column[2];
|
|
||||||
float m[4][2];
|
|
||||||
} __2_columnset;
|
|
||||||
|
|
||||||
typedef union column_3 {
|
|
||||||
__m256 part;
|
|
||||||
__m128 column[3];
|
|
||||||
float m[4][3];
|
|
||||||
} __3_columnset;
|
|
||||||
|
|
||||||
typedef union column_4 {
|
|
||||||
__m512 stream;
|
|
||||||
__m256 half[2];
|
|
||||||
__m128 column[4];
|
|
||||||
float m[4][4];
|
|
||||||
} __4_columnset;
|
|
||||||
|
|
||||||
typedef union scalar_pack {
|
typedef union scalar_pack {
|
||||||
uint64_t data[8];
|
uint64_t data[8];
|
||||||
} scalar_pack;
|
} scalar_pack;
|
||||||
@@ -77,34 +61,38 @@ typedef uint64_t(SN_DECL *FACTORIALROC)(int n);
|
|||||||
|
|
||||||
INTERNAL void normalize(__m128 *source, __m128 *target);
|
INTERNAL void normalize(__m128 *source, __m128 *target);
|
||||||
|
|
||||||
INTERNAL void SN_DECL kernel_add_sse(mat_kernel const *left, mat_kernel const *right,
|
INTERNAL void SN_DECL f32_add_sse(MAT_KERNEL(float) const *left, MAT_KERNEL(float) const *right,
|
||||||
mat_kernel *ans);
|
MAT_KERNEL(float) * ans);
|
||||||
INTERNAL void SN_DECL kernel_add_avx(mat_kernel const *left, mat_kernel const *right,
|
INTERNAL void SN_DECL f32_add_avx(MAT_KERNEL(float) const *left, MAT_KERNEL(float) const *right,
|
||||||
mat_kernel *ans);
|
MAT_KERNEL(float) * ans);
|
||||||
INTERNAL void SN_DECL kernel_add_512(mat_kernel const *left, mat_kernel const *right,
|
INTERNAL void SN_DECL f32_add_512(MAT_KERNEL(float) const *left, MAT_KERNEL(float) const *right,
|
||||||
mat_kernel *ans);
|
MAT_KERNEL(float) * ans);
|
||||||
INTERNAL void SN_DECL kernel_sub_sse(mat_kernel const *left, mat_kernel const *right,
|
INTERNAL void SN_DECL f32_sub_sse(MAT_KERNEL(float) const *left, MAT_KERNEL(float) const *right,
|
||||||
mat_kernel *ans);
|
MAT_KERNEL(float) * ans);
|
||||||
INTERNAL void SN_DECL kernel_sub_avx(mat_kernel const *left, mat_kernel const *right,
|
INTERNAL void SN_DECL f32_sub_avx(MAT_KERNEL(float) const *left, MAT_KERNEL(float) const *right,
|
||||||
mat_kernel *ans);
|
MAT_KERNEL(float) * ans);
|
||||||
INTERNAL void SN_DECL kernel_sub_512(mat_kernel const *left, mat_kernel const *right,
|
INTERNAL void SN_DECL f32_sub_512(MAT_KERNEL(float) const *left, MAT_KERNEL(float) const *right,
|
||||||
mat_kernel *ans);
|
MAT_KERNEL(float) * ans);
|
||||||
INTERNAL void SN_DECL kernel_transpose_sse(mat_kernel const *source, mat_kernel *target);
|
INTERNAL void SN_DECL f32_transpose_sse(MAT_KERNEL(float) const *source,
|
||||||
INTERNAL void SN_DECL kernel_transpose_avx(mat_kernel const *source, mat_kernel *target);
|
MAT_KERNEL(float) * target);
|
||||||
INTERNAL void SN_DECL kernel_transpose_512(mat_kernel const *source, mat_kernel *target);
|
INTERNAL void SN_DECL f32_transpose_avx(MAT_KERNEL(float) const *source,
|
||||||
INTERNAL void SN_DECL kernel_scalar_mul_sse(mat_kernel const *matrix, float const scalar,
|
MAT_KERNEL(float) * target);
|
||||||
mat_kernel *ans);
|
INTERNAL void SN_DECL f32_transpose_512(MAT_KERNEL(float) const *source,
|
||||||
INTERNAL void SN_DECL kernel_scalar_mul_avx(mat_kernel const *matrix, float const scalar,
|
MAT_KERNEL(float) * target);
|
||||||
mat_kernel *ans);
|
INTERNAL void SN_DECL f32_scalar_mul_sse(MAT_KERNEL(float) const *matrix, float const scalar,
|
||||||
INTERNAL void SN_DECL kernel_scalar_mul_512(mat_kernel const *matrix, float const scalar,
|
MAT_KERNEL(float) * ans);
|
||||||
mat_kernel *ans);
|
INTERNAL void SN_DECL f32_scalar_mul_avx(MAT_KERNEL(float) const *matrix, float const scalar,
|
||||||
|
MAT_KERNEL(float) * ans);
|
||||||
|
INTERNAL void SN_DECL f32_scalar_mul_512(MAT_KERNEL(float) const *matrix, float const scalar,
|
||||||
|
MAT_KERNEL(float) * ans);
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region fma
|
#pragma region fma
|
||||||
|
|
||||||
INTERNAL void SN_DECL kernel_fma_sse(mat_kernel const *restrict left,
|
INTERNAL void SN_DECL kernel_fma_sse(MAT_KERNEL(float) const *restrict left,
|
||||||
mat_kernel const *restrict right, mat_kernel *restrict ans);
|
MAT_KERNEL(float) const *restrict right,
|
||||||
|
MAT_KERNEL(float) *restrict ans);
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef SN_MATKERNEL
|
||||||
|
#define SN_MATKERNEL
|
||||||
|
|
||||||
|
#include <immintrin.h>
|
||||||
|
|
||||||
|
#define ELEMENTSIZE(T) sizeof(T)
|
||||||
|
#define XMMCOUNT(T) sizeof(T) / 16
|
||||||
|
#define YMMCOUNT(T) sizeof(T) / 32
|
||||||
|
#define ZMMCOUNT(T) sizeof(T) / 64
|
||||||
|
|
||||||
|
#define MAT_KERNEL(T) \
|
||||||
|
union { \
|
||||||
|
__m128 xmm[XMMCOUNT(T)]; \
|
||||||
|
__m256 ymm[YMMCOUNT(T)]; \
|
||||||
|
__m512 zmm[ZMMCOUNT(T)]; \
|
||||||
|
T m[16]; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "sn_intrinsic.h"
|
#include "sn_intrinsic.h"
|
||||||
|
|
||||||
INTERNAL void SN_DECL kernel_add_sse(mat_kernel *left, mat_kernel *right, mat_kernel *ans)
|
INTERNAL void SN_DECL f32_add_sse(MAT_KERNEL(float) * left, MAT_KERNEL(float) * right,
|
||||||
|
MAT_KERNEL(float) * ans)
|
||||||
{
|
{
|
||||||
register __m128 c0 = _mm_add_ps(left->xmm[0], right->xmm[0]);
|
register __m128 c0 = _mm_add_ps(left->xmm[0], right->xmm[0]);
|
||||||
register __m128 c1 = _mm_add_ps(left->xmm[1], right->xmm[1]);
|
register __m128 c1 = _mm_add_ps(left->xmm[1], right->xmm[1]);
|
||||||
@@ -13,7 +14,8 @@ INTERNAL void SN_DECL kernel_add_sse(mat_kernel *left, mat_kernel *right, mat_ke
|
|||||||
ans->xmm[3] = c3;
|
ans->xmm[3] = c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void SN_DECL kernel_add_avx(mat_kernel *left, mat_kernel *right, mat_kernel *ans)
|
INTERNAL void SN_DECL f32_add_avx(MAT_KERNEL(float) * left, MAT_KERNEL(float) * right,
|
||||||
|
MAT_KERNEL(float) * ans)
|
||||||
{
|
{
|
||||||
register __m256 c0 = _mm256_add_ps(left->ymm[0], right->ymm[0]);
|
register __m256 c0 = _mm256_add_ps(left->ymm[0], right->ymm[0]);
|
||||||
register __m256 c1 = _mm256_add_ps(left->ymm[1], right->ymm[1]);
|
register __m256 c1 = _mm256_add_ps(left->ymm[1], right->ymm[1]);
|
||||||
@@ -21,13 +23,15 @@ INTERNAL void SN_DECL kernel_add_avx(mat_kernel *left, mat_kernel *right, mat_ke
|
|||||||
ans->ymm[1] = c1;
|
ans->ymm[1] = c1;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void SN_DECL kernel_add_512(mat_kernel *left, mat_kernel *right, mat_kernel *ans)
|
INTERNAL void SN_DECL f32_add_512(MAT_KERNEL(float) * left, MAT_KERNEL(float) * right,
|
||||||
|
MAT_KERNEL(float) * ans)
|
||||||
{
|
{
|
||||||
register __m512 c0 = _mm512_add_ps(left->zmm[0], right->zmm[0]);
|
register __m512 c0 = _mm512_add_ps(left->zmm[0], right->zmm[0]);
|
||||||
ans->zmm[0] = c0;
|
ans->zmm[0] = c0;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void SN_DECL kernel_sub_sse(mat_kernel *left, mat_kernel *right, mat_kernel *ans)
|
INTERNAL void SN_DECL f32_sub_sse(MAT_KERNEL(float) * left, MAT_KERNEL(float) * right,
|
||||||
|
MAT_KERNEL(float) * ans)
|
||||||
{
|
{
|
||||||
register __m128 c0 = _mm_sub_ps(left->xmm[0], right->xmm[0]);
|
register __m128 c0 = _mm_sub_ps(left->xmm[0], right->xmm[0]);
|
||||||
register __m128 c1 = _mm_sub_ps(left->xmm[1], right->xmm[1]);
|
register __m128 c1 = _mm_sub_ps(left->xmm[1], right->xmm[1]);
|
||||||
@@ -40,7 +44,8 @@ INTERNAL void SN_DECL kernel_sub_sse(mat_kernel *left, mat_kernel *right, mat_ke
|
|||||||
ans->xmm[3] = c3;
|
ans->xmm[3] = c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void SN_DECL kernel_sub_avx(mat_kernel *left, mat_kernel *right, mat_kernel *ans)
|
INTERNAL void SN_DECL f32_sub_avx(MAT_KERNEL(float) * left, MAT_KERNEL(float) * right,
|
||||||
|
MAT_KERNEL(float) * ans)
|
||||||
{
|
{
|
||||||
register __m256 c0 = _mm256_sub_ps(left->ymm[0], right->ymm[0]);
|
register __m256 c0 = _mm256_sub_ps(left->ymm[0], right->ymm[0]);
|
||||||
register __m256 c1 = _mm256_sub_ps(left->ymm[1], right->ymm[1]);
|
register __m256 c1 = _mm256_sub_ps(left->ymm[1], right->ymm[1]);
|
||||||
@@ -48,14 +53,15 @@ INTERNAL void SN_DECL kernel_sub_avx(mat_kernel *left, mat_kernel *right, mat_ke
|
|||||||
ans->ymm[1] = c1;
|
ans->ymm[1] = c1;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void SN_DECL kernel_sub_512(mat_kernel *left, mat_kernel *right, mat_kernel *ans)
|
INTERNAL void SN_DECL f32_sub_512(MAT_KERNEL(float) * left, MAT_KERNEL(float) * right,
|
||||||
|
MAT_KERNEL(float) * ans)
|
||||||
{
|
{
|
||||||
register __m512 c0 = _mm512_sub_ps(left->zmm[0], right->zmm[0]);
|
register __m512 c0 = _mm512_sub_ps(left->zmm[0], right->zmm[0]);
|
||||||
ans->zmm[0] = c0;
|
ans->zmm[0] = c0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matrix transpose implementations
|
// Matrix transpose implementations
|
||||||
INTERNAL void SN_DECL kernel_transpose_sse(mat_kernel *source, mat_kernel *target)
|
INTERNAL void SN_DECL kernel_transpose_sse(MAT_KERNEL(float) * source, MAT_KERNEL(float) * target)
|
||||||
{
|
{
|
||||||
register __m128 col0 = source->xmm[0];
|
register __m128 col0 = source->xmm[0];
|
||||||
register __m128 col1 = source->xmm[1];
|
register __m128 col1 = source->xmm[1];
|
||||||
@@ -72,7 +78,7 @@ INTERNAL void SN_DECL kernel_transpose_sse(mat_kernel *source, mat_kernel *targe
|
|||||||
target->xmm[3] = _mm_movehl_ps(tmp3, tmp1);
|
target->xmm[3] = _mm_movehl_ps(tmp3, tmp1);
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void SN_DECL kernel_transpose_avx(mat_kernel *source, mat_kernel *target)
|
INTERNAL void SN_DECL kernel_transpose_avx(MAT_KERNEL(float) * source, MAT_KERNEL(float) * target)
|
||||||
{
|
{
|
||||||
register __m256 col_low = source->ymm[0];
|
register __m256 col_low = source->ymm[0];
|
||||||
register __m256 col_high = source->ymm[1];
|
register __m256 col_high = source->ymm[1];
|
||||||
@@ -87,7 +93,7 @@ INTERNAL void SN_DECL kernel_transpose_avx(mat_kernel *source, mat_kernel *targe
|
|||||||
target->ymm[1] = _mm256_shuffle_ps(col_high, col_low, _MM_SHUFFLE(3, 1, 3, 1));
|
target->ymm[1] = _mm256_shuffle_ps(col_high, col_low, _MM_SHUFFLE(3, 1, 3, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void SN_DECL kernel_transpose_512(mat_kernel *source, mat_kernel *target)
|
INTERNAL void SN_DECL kernel_transpose_512(MAT_KERNEL(float) * source, MAT_KERNEL(float) * target)
|
||||||
{
|
{
|
||||||
register __m512 matrix = source->zmm[0];
|
register __m512 matrix = source->zmm[0];
|
||||||
|
|
||||||
@@ -97,7 +103,8 @@ INTERNAL void SN_DECL kernel_transpose_512(mat_kernel *source, mat_kernel *targe
|
|||||||
target->zmm[0] = _mm512_permutexvar_ps(transpose_indices, matrix);
|
target->zmm[0] = _mm512_permutexvar_ps(transpose_indices, matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void SN_DECL kernel_scalar_mul_sse(mat_kernel *matrix, float scalar, mat_kernel *ans)
|
INTERNAL void SN_DECL kernel_scalar_mul_sse(MAT_KERNEL(float) * matrix, float scalar,
|
||||||
|
MAT_KERNEL(float) * ans)
|
||||||
{
|
{
|
||||||
register __m128 temp = _mm_load_ss(&scalar);
|
register __m128 temp = _mm_load_ss(&scalar);
|
||||||
register __m128 scalar_vec = _mm_shuffle_ps(temp, temp, _MM_SHUFFLE(0, 0, 0, 0));
|
register __m128 scalar_vec = _mm_shuffle_ps(temp, temp, _MM_SHUFFLE(0, 0, 0, 0));
|
||||||
@@ -113,7 +120,8 @@ INTERNAL void SN_DECL kernel_scalar_mul_sse(mat_kernel *matrix, float scalar, ma
|
|||||||
ans->xmm[3] = c3;
|
ans->xmm[3] = c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void SN_DECL kernel_scalar_mul_avx(mat_kernel *matrix, float scalar, mat_kernel *ans)
|
INTERNAL void SN_DECL kernel_scalar_mul_avx(MAT_KERNEL(float) * matrix, float scalar,
|
||||||
|
MAT_KERNEL(float) * ans)
|
||||||
{
|
{
|
||||||
register __m256 scalar_vec = _mm256_broadcast_ss(&scalar);
|
register __m256 scalar_vec = _mm256_broadcast_ss(&scalar);
|
||||||
|
|
||||||
@@ -124,7 +132,8 @@ INTERNAL void SN_DECL kernel_scalar_mul_avx(mat_kernel *matrix, float scalar, ma
|
|||||||
ans->ymm[1] = c1;
|
ans->ymm[1] = c1;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void SN_DECL kernel_scalar_mul_512(mat_kernel *matrix, float scalar, mat_kernel *ans)
|
INTERNAL void SN_DECL kernel_scalar_mul_512(MAT_KERNEL(float) * matrix, float scalar,
|
||||||
|
MAT_KERNEL(float) * ans)
|
||||||
{
|
{
|
||||||
__m512 scalar_vec = _mm512_broadcastss_ps(_mm_load_ss(&scalar));
|
__m512 scalar_vec = _mm512_broadcastss_ps(_mm_load_ss(&scalar));
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "sn_intrinsic.h"
|
#include "sn_intrinsic.h"
|
||||||
|
|
||||||
// ans = left * right(T) + ans
|
// ans = left * right(T) + ans
|
||||||
INTERNAL void SN_DECL kernel_fma_sse(mat_kernel const *restrict left,
|
INTERNAL void SN_DECL f32_fma_sse(MAT_KERNEL(float) const *restrict left,
|
||||||
mat_kernel const *restrict right, mat_kernel *restrict ans)
|
mat_kernel const *restrict right, mat_kernel *restrict ans)
|
||||||
{
|
{
|
||||||
register __m128 source0 = _mm_load_ps(&left->xmm[0]);
|
register __m128 source0 = _mm_load_ps(&left->xmm[0]);
|
||||||
|
|||||||
@@ -66,10 +66,10 @@ void load_intrinsic_sse(sn_intrinsic *context)
|
|||||||
context->city_hash_simplify = city_hash_simplify_sse;
|
context->city_hash_simplify = city_hash_simplify_sse;
|
||||||
context->factorial_simd = factorial_simd_sse;
|
context->factorial_simd = factorial_simd_sse;
|
||||||
context->index_pair = index_pair_sse;
|
context->index_pair = index_pair_sse;
|
||||||
context->kernel_add = (MATARITHMETIC)kernel_add_sse;
|
context->kernel_add = (MATARITHMETIC)f32_add_sse;
|
||||||
context->kernel_fma = (void(*)(void*, void*, void*))kernel_fma_sse;
|
context->kernel_fma = (void(*)(void*, void*, void*))kernel_fma_sse;
|
||||||
context->kernel_scalar_mul = kernel_scalar_mul_sse;
|
context->kernel_scalar_mul = kernel_scalar_mul_sse;
|
||||||
context->kernel_sub = (MATARITHMETIC)kernel_sub_sse;
|
context->kernel_sub = (MATARITHMETIC)f32_sub_sse;
|
||||||
context->kernel_transpose = (MATTRANSPOSEPROC)kernel_transpose_sse;
|
context->kernel_transpose = (MATTRANSPOSEPROC)kernel_transpose_sse;
|
||||||
context->normalize_3 = normalize;
|
context->normalize_3 = normalize;
|
||||||
}
|
}
|
||||||
@@ -79,10 +79,10 @@ void load_intrinsic_avx(sn_intrinsic *context)
|
|||||||
context->city_hash_simplify = city_hash_simplify_sse;
|
context->city_hash_simplify = city_hash_simplify_sse;
|
||||||
context->factorial_simd = factorial_simd_sse;
|
context->factorial_simd = factorial_simd_sse;
|
||||||
context->index_pair = index_pair_sse;
|
context->index_pair = index_pair_sse;
|
||||||
context->kernel_add = (MATARITHMETIC)kernel_add_avx;
|
context->kernel_add = (MATARITHMETIC)f32_add_avx;
|
||||||
context->kernel_fma = (void(*)(void*, void*, void*))kernel_fma_sse;
|
context->kernel_fma = (void(*)(void*, void*, void*))kernel_fma_sse;
|
||||||
context->kernel_scalar_mul = kernel_scalar_mul_avx;
|
context->kernel_scalar_mul = kernel_scalar_mul_avx;
|
||||||
context->kernel_sub = (MATARITHMETIC)kernel_sub_avx;
|
context->kernel_sub = (MATARITHMETIC)f32_sub_avx;
|
||||||
context->kernel_transpose = (MATTRANSPOSEPROC)kernel_transpose_avx;
|
context->kernel_transpose = (MATTRANSPOSEPROC)kernel_transpose_avx;
|
||||||
context->normalize_3 = normalize;
|
context->normalize_3 = normalize;
|
||||||
}
|
}
|
||||||
@@ -92,10 +92,10 @@ void load_intrinsic_512(sn_intrinsic *context)
|
|||||||
context->city_hash_simplify = city_hash_simplify_sse;
|
context->city_hash_simplify = city_hash_simplify_sse;
|
||||||
context->factorial_simd = factorial_simd_sse;
|
context->factorial_simd = factorial_simd_sse;
|
||||||
context->index_pair = index_pair_sse;
|
context->index_pair = index_pair_sse;
|
||||||
context->kernel_add = (MATARITHMETIC)kernel_add_512;
|
context->kernel_add = (MATARITHMETIC)f32_add_512;
|
||||||
context->kernel_fma = (void(*)(void*, void*, void*))kernel_fma_sse;
|
context->kernel_fma = (void(*)(void*, void*, void*))kernel_fma_sse;
|
||||||
context->kernel_scalar_mul = kernel_scalar_mul_512;
|
context->kernel_scalar_mul = kernel_scalar_mul_512;
|
||||||
context->kernel_sub = (MATARITHMETIC)kernel_sub_512;
|
context->kernel_sub = (MATARITHMETIC)f32_sub_512;
|
||||||
context->kernel_transpose = (MATTRANSPOSEPROC)kernel_transpose_512;
|
context->kernel_transpose = (MATTRANSPOSEPROC)kernel_transpose_512;
|
||||||
context->normalize_3 = normalize;
|
context->normalize_3 = normalize;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
using StgSharp.Mathematics;
|
||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace StgSharp
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 矩阵计算并发调度器线程调度测试 修复的问题: 1. 添加了ResetThreadCount()方法,在每轮任务调度前重置线程计数 2.
|
||||||
|
/// 调度器线程不再递减RemainThreadCount,只有工作线程才递减 3. 改进了控制台输出,显示更清晰的线程活动信息 使用方法:在Program.cs的Main方法中调用
|
||||||
|
/// MatrixParallelThreadTest.TestMatrixParallelThreadScheduling(); 或者通过命令行运行程序时调用此方法
|
||||||
|
/// </summary>
|
||||||
|
public class MatrixParallelThreadTest
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 测试矩阵并行计算线程调度
|
||||||
|
/// </summary>
|
||||||
|
public static void TestMatrixParallelThreadScheduling()
|
||||||
|
{
|
||||||
|
Console.WriteLine("=== 矩阵并行计算线程调度测试开始 ===");
|
||||||
|
Console.WriteLine($"CPU核心数: {Environment.ProcessorCount}");
|
||||||
|
Console.WriteLine($"支持并行计算: {MatrixParallel.SupportParallel}");
|
||||||
|
Console.WriteLine($"并行计算有意义: {MatrixParallel.IsParallelMeaningful}");
|
||||||
|
|
||||||
|
if (!MatrixParallel.SupportParallel)
|
||||||
|
{
|
||||||
|
Console.WriteLine("当前系统不支持并行计算,跳过测试");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 初始化矩阵并行计算系统
|
||||||
|
Console.WriteLine("\n--- 初始化矩阵并行计算系统 ---");
|
||||||
|
MatrixParallel.Init();
|
||||||
|
Console.WriteLine("矩阵并行计算系统初始化完成");
|
||||||
|
|
||||||
|
// 启动并行计算
|
||||||
|
Console.WriteLine("\n--- 启动并行计算 ---");
|
||||||
|
MatrixParallel.LaunchParallel(SleepMode.QuickWakeup);
|
||||||
|
Console.WriteLine("并行计算已启动");
|
||||||
|
|
||||||
|
// 获取领导者句柄
|
||||||
|
MatrixParallel.MatrixParallelWrap.Handle leaderHandle = MatrixParallel.LeaderHandle;
|
||||||
|
Console.WriteLine($"领导者句柄获取成功: Wrap ID {leaderHandle.Wrap.ID}");
|
||||||
|
|
||||||
|
// 模拟一些任务调度
|
||||||
|
Console.WriteLine("\n--- 开始模拟任务调度 ---");
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"\n第 {i + 1} 轮任务调度:");
|
||||||
|
|
||||||
|
// 开始并行计算
|
||||||
|
MatrixParallel.LeadParallel();
|
||||||
|
Console.WriteLine("已获取并行计算锁");
|
||||||
|
|
||||||
|
// 设置所有Wrap
|
||||||
|
MatrixParallel.SetAllWrap();
|
||||||
|
Console.WriteLine("已通知所有Wrap开始工作");
|
||||||
|
|
||||||
|
// 发布任务(当前为空实现)
|
||||||
|
MatrixParallel.PublishTask();
|
||||||
|
Console.WriteLine("任务发布完成");
|
||||||
|
|
||||||
|
// 等待一段时间让线程执行
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
|
// 结束并行计算
|
||||||
|
MatrixParallel.EndParallel();
|
||||||
|
Console.WriteLine("已释放并行计算锁");
|
||||||
|
|
||||||
|
// 等待一段时间再进行下一轮
|
||||||
|
Thread.Sleep(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("\n--- 测试完成 ---");
|
||||||
|
Console.WriteLine("线程调度测试已成功完成,请观察上述输出中的线程活动信息");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"测试过程中发生异常: {ex.Message}");
|
||||||
|
Console.WriteLine($"异常详情: {ex}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,17 +59,26 @@ namespace StgSharp
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
<<<<<<< HEAD
|
||||||
World.Init();
|
World.Init();
|
||||||
|
|
||||||
TestMatrixParallel();
|
TestMatrixParallel();
|
||||||
|
|
||||||
// 原有的矩阵测试代码
|
// 原有的矩阵测试代码
|
||||||
|
=======
|
||||||
|
MatrixParallelThreadTest.TestMatrixParallelThreadScheduling();
|
||||||
|
/*
|
||||||
|
>>>>>>> 8007eee8461498a85a9515e8fd076f03cb552b64
|
||||||
HybridLayerSegregatedFitAllocator hlsf = new HybridLayerSegregatedFitAllocator(64 * 400 * 400);
|
HybridLayerSegregatedFitAllocator hlsf = new HybridLayerSegregatedFitAllocator(64 * 400 * 400);
|
||||||
|
|
||||||
Matrix<float> m = Matrix<float>.FromHlsf(400, 200, hlsf);
|
Matrix<float> m = Matrix<float>.FromHlsf(400, 200, hlsf);
|
||||||
|
|
||||||
int i = 0, ii = 0;
|
int i = 0, ii = 0;
|
||||||
|
<<<<<<< HEAD
|
||||||
foreach (Segment lines in m.GetRowEnumeration())
|
foreach (Segment lines in m.GetRowEnumeration())
|
||||||
|
=======
|
||||||
|
foreach (MatrixSegment lines in m.GetRowEnumeration())
|
||||||
|
>>>>>>> 8007eee8461498a85a9515e8fd076f03cb552b64
|
||||||
{
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
foreach (MatrixKernel* item in lines)
|
foreach (MatrixKernel* item in lines)
|
||||||
@@ -80,6 +89,7 @@ namespace StgSharp
|
|||||||
ii++;
|
ii++;
|
||||||
Console.WriteLine($"============================{ii}");
|
Console.WriteLine($"============================{ii}");
|
||||||
}
|
}
|
||||||
|
/**/
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
-58
@@ -1,58 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
clear
|
|
||||||
|
|
||||||
# 设置要查找的文件类型
|
|
||||||
file_types=( "*.cs" "*.c" "*.cpp" "*.h" "*.txt" "*.csproj" "*.vs" "*.vert" "*.frag" "*.sln" "*.vcxproj" "*.json" "*.sh" )
|
|
||||||
|
|
||||||
# 循环遍历每个文件类型,并添加到git
|
|
||||||
for type in "${file_types[@]}"; do
|
|
||||||
|
|
||||||
# 执行find命令,并将输出保存到变量中
|
|
||||||
add_output=$(find . -name "$type" -exec git add '{}' + 2>&1)
|
|
||||||
add_status=$?
|
|
||||||
|
|
||||||
# 检查find命令的退出状态
|
|
||||||
if [ $add_status -ne 0 ]; then
|
|
||||||
# 如果出错,显示保存的输出
|
|
||||||
echo "$add_output"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
clear
|
|
||||||
|
|
||||||
# 提示用户输入commit信息
|
|
||||||
echo "====================== file added ======================"
|
|
||||||
echo "请输入commit信息:"
|
|
||||||
read commit_message
|
|
||||||
|
|
||||||
# 执行git commit命令,并将输出保存到变量中
|
|
||||||
commit_output=$(git commit -m "$commit_message" 2>&1)
|
|
||||||
commit_status=$?
|
|
||||||
|
|
||||||
# 检查git commit命令的退出状态
|
|
||||||
if [ $commit_status -ne 0 ]; then
|
|
||||||
# 如果出错,显示保存的输出
|
|
||||||
echo "$commit_output"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
clear
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "================ successfully committed ================="
|
|
||||||
echo ""
|
|
||||||
# 执行git push命令
|
|
||||||
git push CCD_Git local:main
|
|
||||||
git push CCD_Git local:nitload
|
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Successfully pushed, press enter to quit"
|
|
||||||
read commit_message
|
|
||||||
|
|
||||||
clear
|
|
||||||
exit
|
|
||||||
Binary file not shown.
Reference in New Issue
Block a user