Skip to content

Commit

Permalink
PR #1033 and #1038.
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rs-mt committed Aug 25, 2023
1 parent c1723ff commit f5742fc
Show file tree
Hide file tree
Showing 12 changed files with 499 additions and 127 deletions.
46 changes: 0 additions & 46 deletions .github/workflows/Scripts/FixNugetSymbolPackages.ps1

This file was deleted.

28 changes: 1 addition & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,36 +153,13 @@ jobs:
matrix:
os: ${{ fromJson(needs.setup-os-matrix.outputs.os) }}
library: [ILGPU, ILGPU.Algorithms]
framework: [netcoreapp3.1, net5.0, net6.0, net7.0]
include:
- os: windows-latest
library: ILGPU
framework: net471
- os: windows-latest
library: ILGPU.Algorithms
framework: net471
framework: [net6.0, net7.0]
fail-fast: false
runs-on: ${{ contains(matrix.os, 'cuda') && format('{0}-{1}-{2}', matrix.os, matrix.library, matrix.framework) || matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup the latest .NET Core 3.1 SDK
if: matrix.framework == 'netcoreapp3.1'
uses: actions/[email protected]
env:
DOTNET_INSTALL_DIR: ${{ matrix.framework == 'cuda' && '~/.' }}
with:
dotnet-version: 3.1.x

- name: Setup the latest .NET 5 SDK
if: matrix.framework == 'net5.0'
uses: actions/[email protected]
env:
DOTNET_INSTALL_DIR: ${{ matrix.framework == 'cuda' && '~/.' }}
with:
dotnet-version: 5.0.x

- name: Setup the latest .NET 6 SDK
if: matrix.framework == 'net6.0'
uses: actions/[email protected]
Expand Down Expand Up @@ -270,9 +247,6 @@ jobs:
dotnet pack Src --configuration=Release @params
- name: Fix NuGet Symbols Packages
run: .github/workflows/Scripts/FixNugetSymbolPackages.ps1 -version "${{ needs.check-version.outputs.version }}"

- name: Upload NuGet package artifacts
uses: actions/upload-artifact@v3
with:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
fail-fast: false
matrix:
solution: [Src/ILGPU.sln, Samples/ILGPU.Samples.sln]
framework: [net471, netcoreapp3.1, net5.0, net6.0, net7.0]
framework: [net6.0, net7.0]

steps:
- name: Checkout repository
Expand Down Expand Up @@ -64,8 +64,6 @@ jobs:
$LibraryTargetFrameworks=$LibraryUnitTestTargetFrameworks=$LibrarySamplesTargetFrameworks=$LibrarySamplesTargetFrameworksWindows="${{ matrix.framework }}"
Switch($LibrarySamplesTargetFrameworks)
{
"netcoreapp3.1" { $LibraryTargetFrameworks="netstandard2.1" }
"net5.0" { $LibrarySamplesTargetFrameworksWindows="net5.0-windows" }
"net6.0" { $LibrarySamplesTargetFrameworksWindows="net6.0-windows" }
"net7.0" { $LibrarySamplesTargetFrameworksWindows="net7.0-windows" }
}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ Src/ILGPU.Algorithms/IL/ILContext.Generated.cs
Src/ILGPU.Algorithms/PTX/PTXContext.Generated.cs
Src/ILGPU.Algorithms/RadixSortOperations.cs
Src/ILGPU.Algorithms/Vectors/VectorTypes.cs
Src/ILGPU.Algorithms/Random/RandomRanges.cs
Src/ILGPU.Algorithms/Runtime/Cuda/API/CuBlasNativeMethods.cs
Src/ILGPU.Algorithms/Runtime/Cuda/API/CuFFTAPI.Generated.cs
Src/ILGPU.Algorithms/Runtime/Cuda/API/CuFFTNativeMethods.cs
Expand Down
16 changes: 2 additions & 14 deletions Samples/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,9 @@
<LibrarySamplesTargetFrameworks>net6.0</LibrarySamplesTargetFrameworks>
<LibrarySamplesTargetFrameworksWindows>net6.0-windows</LibrarySamplesTargetFrameworksWindows>
</PropertyGroup>
<PropertyGroup Condition="'$(MSBuildVersion)' &gt;= '16.8' AND '$(MSBuildVersion)' &lt; '17.0'">
<LibrarySamplesTargetFrameworks>net5.0</LibrarySamplesTargetFrameworks>
<LibrarySamplesTargetFrameworksWindows>net5.0-windows</LibrarySamplesTargetFrameworksWindows>
</PropertyGroup>
<PropertyGroup Condition="'$(MSBuildVersion)' &lt; '16.8' AND '$(MSBuildRuntimeType)' == 'Core'">
<LibrarySamplesTargetFrameworks>netcoreapp3.1</LibrarySamplesTargetFrameworks>
<LibrarySamplesTargetFrameworksWindows>netcoreapp3.1</LibrarySamplesTargetFrameworksWindows>
</PropertyGroup>
<PropertyGroup Condition="'$(MSBuildVersion)' &lt; '16.8' AND '$(MSBuildRuntimeType)' != 'Core'">
<LibrarySamplesTargetFrameworks>net471</LibrarySamplesTargetFrameworks>
<LibrarySamplesTargetFrameworksWindows>net471</LibrarySamplesTargetFrameworksWindows>
</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<LibrarySamplesTargetFrameworks>net471;netcoreapp3.1;net5.0;net6.0;net7.0</LibrarySamplesTargetFrameworks>
<LibrarySamplesTargetFrameworksWindows>net471;netcoreapp3.1;net5.0-windows;net6.0-windows;net7.0-windows</LibrarySamplesTargetFrameworksWindows>
<LibrarySamplesTargetFrameworks>net6.0;net7.0</LibrarySamplesTargetFrameworks>
<LibrarySamplesTargetFrameworksWindows>net6.0-windows;net7.0-windows</LibrarySamplesTargetFrameworksWindows>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions Src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LibraryLatestTargetFramework>$(LibraryTargetFrameworks)</LibraryLatestTargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<LibraryTargetFrameworks>$(LibraryTargetFrameworks);net471;netstandard2.1;net5.0;net6.0</LibraryTargetFrameworks>
<LibraryTargetFrameworks>$(LibraryTargetFrameworks);net6.0</LibraryTargetFrameworks>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>

Expand All @@ -22,7 +22,7 @@
<LibraryLatestUnitTestTargetFramework>$(LibraryUnitTestTargetFrameworks)</LibraryLatestUnitTestTargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<LibraryUnitTestTargetFrameworks>$(LibraryUnitTestTargetFrameworks);net471;netcoreapp3.1;net5.0;net6.0</LibraryUnitTestTargetFrameworks>
<LibraryUnitTestTargetFrameworks>$(LibraryUnitTestTargetFrameworks);net6.0</LibraryUnitTestTargetFrameworks>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>

Expand Down
17 changes: 11 additions & 6 deletions Src/ILGPU.Algorithms/ILGPU.Algorithms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NeutralLanguage>en-US</NeutralLanguage>
<!-- CAUTION: ILGPU supports a limited subset only - due to the .Net 4.7 backwards compatibility -->
<LangVersion>11.0</LangVersion>
</PropertyGroup>

Expand All @@ -31,10 +30,6 @@
<Configurations>Debug;Release</Configurations>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\ILGPU\Util\NullableAttributes.cs" Link="Util\NullableAttributes.cs" />
</ItemGroup>

<ItemGroup>
<None Include="AlgorithmContextMappings.cs">
<DesignTime>True</DesignTime>
Expand Down Expand Up @@ -69,7 +64,8 @@
</PropertyGroup>

<PropertyGroup>
<EnablePackageValidation>true</EnablePackageValidation>
<!-- Turn off package validation for now to avoid checks against non-supported frameworks -->
<EnablePackageValidation>false</EnablePackageValidation>
<PackageValidationBaselineVersion>$(LibraryPackageValidationBaselineVersion)</PackageValidationBaselineVersion>
</PropertyGroup>

Expand Down Expand Up @@ -118,6 +114,10 @@
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>RadixSortOperations.cs</LastGenOutput>
</None>
<None Update="Random\RandomRanges.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>RandomRanges.cs</LastGenOutput>
</None>
<None Update="Runtime\Cuda\API\CuFFTAPI.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>CuFFTAPI.Generated.cs</LastGenOutput>
Expand Down Expand Up @@ -256,6 +256,11 @@
<AutoGen>True</AutoGen>
<DependentUpon>RadixSortOperations.tt</DependentUpon>
</Compile>
<Compile Update="Random\RandomRanges.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>RandomRanges.tt</DependentUpon>
</Compile>
<Compile Update="Resources\ErrorMessages.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand Down
90 changes: 80 additions & 10 deletions Src/ILGPU.Algorithms/Random/RandomExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
// ---------------------------------------------------------------------------------------

using ILGPU.Runtime;
using ILGPU.Util;
using System;
using System.Diagnostics;
using System.Numerics;
using System.Runtime.CompilerServices;

namespace ILGPU.Algorithms.Random
Expand Down Expand Up @@ -49,7 +51,7 @@ internal static uint MergeULong(ulong nextULong) =>
/// <summary>
/// Separates the given unsigned int into an unsigned long.
/// </summary>
internal static ulong SeperateUInt(uint nextUInt) =>
internal static ulong SeparateUInt(uint nextUInt) =>
((ulong)nextUInt << 32) | nextUInt;

/// <summary>
Expand Down Expand Up @@ -91,8 +93,8 @@ internal static ulong ShiftState(ulong state, int laneShift)
/// Generates a random int in [minValue..maxValue).
/// </summary>
/// <param name="randomProvider">The random provider.</param>
/// <param name="minValue">The minimum value (inclusive)</param>
/// <param name="maxValue">The maximum values (exclusive)</param>
/// <param name="minValue">The minimum value (inclusive).</param>
/// <param name="maxValue">The maximum values (exclusive).</param>
/// <returns>A random int in [minValue..maxValue).</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Next<TRandomProvider>(
Expand All @@ -112,8 +114,8 @@ public static float Next<TRandomProvider>(
/// Generates a random int in [minValue..maxValue).
/// </summary>
/// <param name="randomProvider">The random provider.</param>
/// <param name="minValue">The minimum value (inclusive)</param>
/// <param name="maxValue">The maximum values (exclusive)</param>
/// <param name="minValue">The minimum value (inclusive).</param>
/// <param name="maxValue">The maximum values (exclusive).</param>
/// <returns>A random int in [minValue..maxValue).</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static double Next<TRandomProvider>(
Expand All @@ -133,8 +135,8 @@ public static double Next<TRandomProvider>(
/// Generates a random int in [minValue..maxValue).
/// </summary>
/// <param name="randomProvider">The random provider.</param>
/// <param name="minValue">The minimum value (inclusive)</param>
/// <param name="maxValue">The maximum values (exclusive)</param>
/// <param name="minValue">The minimum value (inclusive).</param>
/// <param name="maxValue">The maximum values (exclusive).</param>
/// <returns>A random int in [minValue..maxValue).</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Next<TRandomProvider>(
Expand All @@ -154,8 +156,8 @@ public static int Next<TRandomProvider>(
/// Generates a random long in [minValue..maxValue).
/// </summary>
/// <param name="randomProvider">The random provider.</param>
/// <param name="minValue">The minimum value (inclusive)</param>
/// <param name="maxValue">The maximum values (exclusive)</param>
/// <param name="minValue">The minimum value (inclusive).</param>
/// <param name="maxValue">The maximum values (exclusive).</param>
/// <returns>A random long in [minValue..maxValue).</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Next<TRandomProvider>(
Expand All @@ -174,6 +176,74 @@ public static long Next<TRandomProvider>(
return Math.Min(intermediate + minValue, maxValue - 1);
}

#if NET7_0_OR_GREATER
/// <summary>
/// Generates a new random vector containing provided RNG-based values.
/// </summary>
/// <typeparam name="T">The vector element type.</typeparam>
/// <typeparam name="TRandomProvider">The RNG provider type.</typeparam>
/// <typeparam name="TRange">The generic RNG value range.</typeparam>
/// <param name="randomProvider">The random provider instance to use.</param>
/// <param name="range">The generic range instance to use.</param>
/// <returns>The created random vector.</returns>
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Vector<T> NextVector<T, TRandomProvider, TRange>(
ref TRandomProvider randomProvider,
TRange range)
where T : unmanaged
where TRandomProvider : struct, IRandomProvider
where TRange : struct, IRandomRange<T>
{
int vectorLength = Vector<T>.Count;
int length = Interop.SizeOf<T>() * vectorLength;

// Allocate temporary buffers
var source = stackalloc byte[length + vectorLength];
var span = new Span<T>(
(void*)Interop.Align((long)source, length, vectorLength),
vectorLength);

// Generated random numbers
for (int i = 0; i < vectorLength; ++i)
span[i] = range.Next(ref randomProvider);

// Load aligned vector
return span.LoadAlignedVectorUnsafe();
}

/// <summary>
/// Generates a new random vector containing provided RNG-based values.
/// </summary>
/// <typeparam name="T">The vector element type.</typeparam>
/// <typeparam name="TRangeProvider">The RNG range provider.</typeparam>
/// <param name="rangeProvider">The range provider instance to use.</param>
/// <returns>The created random vector.</returns>
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Vector<T> NextVector<T, TRangeProvider>(
ref TRangeProvider rangeProvider)
where T : unmanaged
where TRangeProvider : struct, IRandomRangeProvider<TRangeProvider, T>
{
int vectorLength = Vector<T>.Count;
int length = Interop.SizeOf<T>() * vectorLength;

// Allocate temporary buffers
var source = stackalloc byte[length + vectorLength];
var span = new Span<T>(
(void*)Interop.Align((long)source, length, vectorLength),
vectorLength);

// Generated random numbers
for (int i = 0; i < vectorLength; ++i)
span[i] = rangeProvider.Next();

// Load aligned vector
return span.LoadAlignedVectorUnsafe();
}
#endif

/// <summary>
/// Constructs an RNG using the given provider instance.
/// </summary>
Expand Down Expand Up @@ -220,7 +290,7 @@ internal static void InitializeRNGKernel<TRandomProvider>(
{
randomProvider[i] = default(TRandomProvider).CreateProvider(ref provider);
}

// Update provider state for future iterations
sourceProviders[index] = provider;
}
Expand Down
Loading

0 comments on commit f5742fc

Please sign in to comment.