diff --git a/src/ComputeSharp.SourceGenerators/Helpers/MemoryMarshal.cs b/src/ComputeSharp.SourceGenerators/Helpers/MemoryMarshal.cs
new file mode 100644
index 00000000..4c92387c
--- /dev/null
+++ b/src/ComputeSharp.SourceGenerators/Helpers/MemoryMarshal.cs
@@ -0,0 +1,25 @@
+using System;
+
+namespace ComputeSharp.SourceGenerators.Helpers
+{
+ ///
+ /// A polyfill type that mirrors some methods from on .NET 5.
+ ///
+ internal static class MemoryMarshal
+ {
+ ///
+ public static ref T GetReference(Span span)
+ {
+ return ref System.Runtime.InteropServices.MemoryMarshal.GetReference(span);
+ }
+
+ ///
+ /// Creates a new from a given reference.
+ ///
+ /// The type of reference to wrap.
+ /// The target reference.
+ /// The length of the to create.
+ /// A new wrapping .
+ public static Span CreateSpan(ref T value, int length) => default;
+ }
+}
diff --git a/src/ComputeSharp.SourceGenerators/Helpers/RuntimeHelpers.cs b/src/ComputeSharp.SourceGenerators/Helpers/RuntimeHelpers.cs
new file mode 100644
index 00000000..adcb0187
--- /dev/null
+++ b/src/ComputeSharp.SourceGenerators/Helpers/RuntimeHelpers.cs
@@ -0,0 +1,18 @@
+using System;
+
+namespace ComputeSharp.SourceGenerators.Helpers
+{
+ ///
+ /// A polyfill type that mirrors some methods from on .NET 5.
+ ///
+ internal static class RuntimeHelpers
+ {
+ ///
+ /// Allocates some memory tied to the lifetime of a specific type.
+ ///
+ /// The type to associate the memory to.
+ /// The size in byte of the memory to allocate.
+ /// A pointer to the allocated memory.
+ public static IntPtr AllocateTypeAssociatedMemory(Type type, int size) => default;
+ }
+}
diff --git a/src/ComputeSharp/Core/Primitives/Bool/Bool2.g.cs b/src/ComputeSharp/Core/Primitives/Bool/Bool2.g.cs
index 0ba2052f..fc5ecb87 100644
--- a/src/ComputeSharp/Core/Primitives/Bool/Bool2.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Bool/Bool2.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Bool/Bool3.g.cs b/src/ComputeSharp/Core/Primitives/Bool/Bool3.g.cs
index 776b3ca6..81ee2efc 100644
--- a/src/ComputeSharp/Core/Primitives/Bool/Bool3.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Bool/Bool3.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Bool/Bool4.g.cs b/src/ComputeSharp/Core/Primitives/Bool/Bool4.g.cs
index e42aacf9..7b755bb9 100644
--- a/src/ComputeSharp/Core/Primitives/Bool/Bool4.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Bool/Bool4.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Bool/BoolMxN.g.cs b/src/ComputeSharp/Core/Primitives/Bool/BoolMxN.g.cs
index 8492d73a..ab957957 100644
--- a/src/ComputeSharp/Core/Primitives/Bool/BoolMxN.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Bool/BoolMxN.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Double/Double2.g.cs b/src/ComputeSharp/Core/Primitives/Double/Double2.g.cs
index c08acedc..c89db8db 100644
--- a/src/ComputeSharp/Core/Primitives/Double/Double2.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Double/Double2.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Double/Double3.g.cs b/src/ComputeSharp/Core/Primitives/Double/Double3.g.cs
index 17c78f99..fcaf1279 100644
--- a/src/ComputeSharp/Core/Primitives/Double/Double3.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Double/Double3.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Double/Double4.g.cs b/src/ComputeSharp/Core/Primitives/Double/Double4.g.cs
index 5360ca0e..558ac8f2 100644
--- a/src/ComputeSharp/Core/Primitives/Double/Double4.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Double/Double4.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Double/DoubleMxN.g.cs b/src/ComputeSharp/Core/Primitives/Double/DoubleMxN.g.cs
index f5f465d8..5d22bf30 100644
--- a/src/ComputeSharp/Core/Primitives/Double/DoubleMxN.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Double/DoubleMxN.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Float/Float2.g.cs b/src/ComputeSharp/Core/Primitives/Float/Float2.g.cs
index 872b9e89..c106cf64 100644
--- a/src/ComputeSharp/Core/Primitives/Float/Float2.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Float/Float2.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Float/Float3.g.cs b/src/ComputeSharp/Core/Primitives/Float/Float3.g.cs
index bf6345c3..eaf7c0c8 100644
--- a/src/ComputeSharp/Core/Primitives/Float/Float3.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Float/Float3.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Float/Float4.g.cs b/src/ComputeSharp/Core/Primitives/Float/Float4.g.cs
index c5c9842f..4566e57f 100644
--- a/src/ComputeSharp/Core/Primitives/Float/Float4.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Float/Float4.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Float/FloatMxN.g.cs b/src/ComputeSharp/Core/Primitives/Float/FloatMxN.g.cs
index 349c57e5..ffc464ce 100644
--- a/src/ComputeSharp/Core/Primitives/Float/FloatMxN.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Float/FloatMxN.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Int/Int2.g.cs b/src/ComputeSharp/Core/Primitives/Int/Int2.g.cs
index 450a95d2..5deb4e01 100644
--- a/src/ComputeSharp/Core/Primitives/Int/Int2.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Int/Int2.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Int/Int3.g.cs b/src/ComputeSharp/Core/Primitives/Int/Int3.g.cs
index 76709b41..82db52f5 100644
--- a/src/ComputeSharp/Core/Primitives/Int/Int3.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Int/Int3.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Int/Int4.g.cs b/src/ComputeSharp/Core/Primitives/Int/Int4.g.cs
index 671e68ee..98b9d1d1 100644
--- a/src/ComputeSharp/Core/Primitives/Int/Int4.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Int/Int4.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/Int/IntMxN.g.cs b/src/ComputeSharp/Core/Primitives/Int/IntMxN.g.cs
index 5fceb214..466288e3 100644
--- a/src/ComputeSharp/Core/Primitives/Int/IntMxN.g.cs
+++ b/src/ComputeSharp/Core/Primitives/Int/IntMxN.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude b/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude
index 8bbddd7f..46506b1b 100644
--- a/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude
+++ b/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude
@@ -10,8 +10,13 @@
void GenerateAllMatrixProperties(string typeName, int elementSize)
{
#>
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/UInt/UInt2.g.cs b/src/ComputeSharp/Core/Primitives/UInt/UInt2.g.cs
index d9e493b7..0bcfbdb2 100644
--- a/src/ComputeSharp/Core/Primitives/UInt/UInt2.g.cs
+++ b/src/ComputeSharp/Core/Primitives/UInt/UInt2.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/UInt/UInt3.g.cs b/src/ComputeSharp/Core/Primitives/UInt/UInt3.g.cs
index c10c488b..3ee94533 100644
--- a/src/ComputeSharp/Core/Primitives/UInt/UInt3.g.cs
+++ b/src/ComputeSharp/Core/Primitives/UInt/UInt3.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/UInt/UInt4.g.cs b/src/ComputeSharp/Core/Primitives/UInt/UInt4.g.cs
index 92583ce9..58f1d90c 100644
--- a/src/ComputeSharp/Core/Primitives/UInt/UInt4.g.cs
+++ b/src/ComputeSharp/Core/Primitives/UInt/UInt4.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/UInt/UIntMxN.g.cs b/src/ComputeSharp/Core/Primitives/UInt/UIntMxN.g.cs
index 79dfc564..d8bcd330 100644
--- a/src/ComputeSharp/Core/Primitives/UInt/UIntMxN.g.cs
+++ b/src/ComputeSharp/Core/Primitives/UInt/UIntMxN.g.cs
@@ -1,5 +1,10 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{
diff --git a/src/ComputeSharp/Core/Primitives/VectorType.ttinclude b/src/ComputeSharp/Core/Primitives/VectorType.ttinclude
index 45bab9c2..bbeec676 100644
--- a/src/ComputeSharp/Core/Primitives/VectorType.ttinclude
+++ b/src/ComputeSharp/Core/Primitives/VectorType.ttinclude
@@ -66,8 +66,13 @@ void GenerateVectorProperties(string typeName, int elementSize)
string hlslElementTypeName = elementTypeName.ToLower();
int i = int.Parse(Regex.Match(typeName, @"\d+$").Value);
#>
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+#if NET5_0
+using System.Runtime.CompilerServices;
+#else
+using RuntimeHelpers = ComputeSharp.SourceGenerators.Helpers.RuntimeHelpers;
+using MemoryMarshal = ComputeSharp.SourceGenerators.Helpers.MemoryMarshal;
+#endif
namespace ComputeSharp
{