Skip to content

Commit 7cb5d4e

Browse files
committed
Fix .NET 8 Build
- Disabled Nullable on FuncInstanceMethodInfos - Updated web request to use HTTPClient - Resolved some "WindowsOnly" issues. - Remove .NET Standard only related things
1 parent 0735dea commit 7cb5d4e

File tree

27 files changed

+84
-939
lines changed

27 files changed

+84
-939
lines changed

src/Microsoft.ML.Core/Utilities/FuncInstanceMethodInfo1`2.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable enable
6-
75
using System;
86
using System.Linq.Expressions;
97
using System.Reflection;

src/Microsoft.ML.Core/Utilities/FuncInstanceMethodInfo1`3.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable enable
6-
75
using System;
86
using System.Linq.Expressions;
97
using System.Reflection;

src/Microsoft.ML.Core/Utilities/FuncInstanceMethodInfo1`4.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable enable
6-
75
using System;
86
using System.Linq.Expressions;
97
using System.Reflection;

src/Microsoft.ML.Core/Utilities/FuncInstanceMethodInfo2`4.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable enable
6-
75
using System;
86
using System.Linq.Expressions;
97
using System.Reflection;

src/Microsoft.ML.Core/Utilities/FuncInstanceMethodInfo3`3.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable enable
6-
75
using System;
86
using System.Linq.Expressions;
97
using System.Reflection;

src/Microsoft.ML.Core/Utilities/FuncInstanceMethodInfo3`4.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable enable
6-
75
using System;
86
using System.Linq.Expressions;
97
using System.Reflection;

src/Microsoft.ML.Core/Utilities/Random.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private static uint GetSeed(Random rng)
162162
}
163163
}
164164

165-
public float NextSingle()
165+
public override float NextSingle()
166166
{
167167
NextState();
168168
return GetSingle();

src/Microsoft.ML.Core/Utilities/ResourceManagerUtils.cs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ private async Task<Exception> DownloadResource(IHostEnvironment env, IChannel ch
272272
response.EnsureSuccessStatusCode();
273273
IEnumerable<string> headers;
274274
var hasHeader = response.Headers.TryGetValues("content-length", out headers);
275-
if (uri.Host == "aka.ms" && IsRedirectToDefaultPage(uri.AbsoluteUri))
275+
if (uri.Host == "aka.ms" && await IsRedirectToDefaultPage(uri.AbsoluteUri))
276276
throw new NotSupportedException($"The provided url ({uri}) redirects to the default url ({DefaultUrl})");
277277
if (!hasHeader || !long.TryParse(headers.First(), out var size))
278278
size = 10000000;
@@ -306,31 +306,19 @@ private async Task<Exception> DownloadResource(IHostEnvironment env, IChannel ch
306306
/// <summary>This method checks whether or not the provided aka.ms url redirects to
307307
/// Microsoft's homepage, as the default faulty aka.ms URLs redirect to https://www.microsoft.com/?ref=aka .</summary>
308308
/// <param name="url"> The provided url to check </param>
309-
public bool IsRedirectToDefaultPage(string url)
309+
public async Task<bool> IsRedirectToDefaultPage(string url)
310310
{
311-
try
311+
var httpClient = new HttpClient(new HttpClientHandler { AllowAutoRedirect = false });
312+
var response = await httpClient.GetAsync(url);
313+
314+
if (response.StatusCode == HttpStatusCode.Redirect && response.Headers.Location.AbsolutePath == "https://www.microsoft.com/?ref=aka")
312315
{
313-
var request = WebRequest.Create(url);
314-
// FileWebRequests cannot be redirected to default aka.ms webpage
315-
if (request.GetType() == typeof(FileWebRequest))
316-
return false;
317-
HttpWebRequest httpWebRequest = (HttpWebRequest)request;
318-
httpWebRequest.AllowAutoRedirect = false;
319-
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
316+
return true;
320317
}
321-
catch (WebException e)
318+
else
322319
{
323-
HttpWebResponse webResponse = (HttpWebResponse)e.Response;
324-
// Redirects to default url
325-
if (webResponse.StatusCode == HttpStatusCode.Redirect && webResponse.Headers["Location"] == "https://www.microsoft.com/?ref=aka")
326-
return true;
327-
// Redirects to another url
328-
else if (webResponse.StatusCode == HttpStatusCode.MovedPermanently)
329-
return false;
330-
else
331-
return false;
320+
return false;
332321
}
333-
return false;
334322
}
335323

336324
public static ResourceDownloadResults GetErrorMessage(out string errorMessage, params ResourceDownloadResults[] result)

src/Microsoft.ML.CpuMath/AvxIntrinsics.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
using System.Runtime.Intrinsics;
1616
using System.Runtime.Intrinsics.X86;
1717
using Microsoft.ML.Internal.CpuMath.Core;
18-
using nuint = System.UInt64;
18+
using nUInt = System.UInt64;
1919

2020
namespace Microsoft.ML.Internal.CpuMath
2121
{
@@ -202,8 +202,8 @@ public static unsafe void MatMul(AlignedArray mat, AlignedArray src, AlignedArra
202202
while (pSrcCurrent < pSrcEnd)
203203
{
204204
float* pMatTemp = pMatCurrent;
205-
Contracts.Assert(((nuint)(pMatTemp) % 32) == 0);
206-
Contracts.Assert(((nuint)(pSrcCurrent) % 32) == 0);
205+
Contracts.Assert(((nUInt)(pMatTemp) % 32) == 0);
206+
Contracts.Assert(((nUInt)(pSrcCurrent) % 32) == 0);
207207

208208
// The JIT will only fold away unaligned loads due to the semantics behind
209209
// the VEX-encoding of the memory operand for `ins xmm, xmm, [mem]`. Since
@@ -333,7 +333,7 @@ public static unsafe void MatMulTran(AlignedArray mat, AlignedArray src, Aligned
333333
while (pDstCurrent < pDstEnd)
334334
{
335335
float* pMatTemp = pMatCurrent;
336-
Contracts.Assert(((nuint)(pMatTemp) % 32) == 0);
336+
Contracts.Assert(((nUInt)(pMatTemp) % 32) == 0);
337337

338338
// The JIT will only fold away unaligned loads due to the semantics behind
339339
// the VEX-encoding of the memory operand for `ins xmm, xmm, [mem]`. Since
@@ -380,8 +380,8 @@ public static unsafe void MatMulTran(AlignedArray mat, AlignedArray src, Aligned
380380
{
381381
float* pMatTemp = pMatCurrent;
382382

383-
Contracts.Assert(((nuint)(pMatTemp) % 32) == 0);
384-
Contracts.Assert(((nuint)(pDstCurrent) % 32) == 0);
383+
Contracts.Assert(((nUInt)(pMatTemp) % 32) == 0);
384+
Contracts.Assert(((nUInt)(pDstCurrent) % 32) == 0);
385385

386386
// The JIT will only fold away unaligned loads due to the semantics behind
387387
// the VEX-encoding of the memory operand for `ins xmm, xmm, [mem]`. Since
@@ -466,7 +466,7 @@ public static unsafe void Scale(float scale, Span<float> dst)
466466
int length = dst.Length;
467467
Vector256<float> scaleVector256 = Vector256.Create(scale);
468468

469-
nuint address = (nuint)(pd);
469+
nUInt address = (nUInt)(pd);
470470
int misalignment = (int)(address % 32);
471471
int remainder = 0;
472472

@@ -524,7 +524,7 @@ public static unsafe void Scale(float scale, Span<float> dst)
524524
// when it doesn't cross a cache-line/page boundary, we will just assert
525525
// that the alignment is correct and allow for the more-efficient codegen.
526526

527-
Contracts.Assert(((nuint)(pDstCurrent) % 32) == 0);
527+
Contracts.Assert(((nUInt)(pDstCurrent) % 32) == 0);
528528
Vector256<float> temp = Avx.LoadVector256(pDstCurrent);
529529
temp = Avx.Multiply(scaleVector256, temp);
530530
Avx.Store(pDstCurrent, temp);
@@ -979,7 +979,7 @@ public static unsafe float Sum(ReadOnlySpan<float> src)
979979
int length = src.Length;
980980
Vector256<float> result = Vector256<float>.Zero;
981981

982-
nuint address = (nuint)(pValues);
982+
nUInt address = (nUInt)(pValues);
983983
int misalignment = (int)(address % 32);
984984
int remainder = 0;
985985

@@ -1026,7 +1026,7 @@ public static unsafe float Sum(ReadOnlySpan<float> src)
10261026
// when it doesn't cross a cache-line/page boundary, we will just assert
10271027
// that the alignment is correct and allow for the more-efficient codegen.
10281028

1029-
Contracts.Assert(((nuint)(pValues) % 32) == 0);
1029+
Contracts.Assert(((nUInt)(pValues) % 32) == 0);
10301030
result = Avx.Add(result, Avx.LoadVector256(pValues));
10311031
}
10321032
}

0 commit comments

Comments
 (0)