Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit e25fa0f

Browse files
authored
libomp workaround for Linux, Mac (#897)
* Workaround for libomp on Linux, Mac * Try renaming file * Add special case copy for local dev dependencies
1 parent b7668ca commit e25fa0f

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

src/Simulation/Common/Simulators.Dev.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<QSimDll Condition="$([MSBuild]::IsOsPlatform('OSX'))">$(QsimDllMac)</QSimDll>
1717
<QSimDll Condition="$([MSBuild]::IsOsPlatform('Linux'))">$(QsimDllLinux)</QSimDll>
1818
<QSimDll Condition="$([MSBuild]::IsOsPlatform('Windows'))">$(QsimDllWindows)</QSimDll>
19+
<QSimDependencies Condition="$([MSBuild]::IsOsPlatform('OSX'))">$([MSBuild]::NormalizePath($(NativeBuildPath)/../../osx))</QSimDependencies>
20+
<QSimDependencies Condition="$([MSBuild]::IsOsPlatform('Linux'))">$([MSBuild]::NormalizePath($(NativeBuildPath)/../../linux))</QSimDependencies>
21+
<QSimDependencies Condition="$([MSBuild]::IsOsPlatform('Windows'))">$([MSBuild]::NormalizePath($(NativeBuildPath)/../../win10))</QSimDependencies>
1922
</PropertyGroup>
2023

2124
<ItemGroup>
@@ -29,6 +32,11 @@
2932
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3033
<Visible>false</Visible>
3134
</None>
35+
<None Include="$(QSimDependencies)/**/*" >
36+
<Link>%(Filename)%(Extension)</Link>
37+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
38+
<Visible>false</Visible>
39+
</None>
3240
</ItemGroup>
3341

3442
<!-- Copy the experimental simulators from xplat/qdk_sim_rs build to where we can see and use it. -->
File renamed without changes.

src/Simulation/Simulators/QuantumSimulator/NativeImports.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public partial class QuantumSimulator
1414
// Preparation\Arbitrary.cs(23,41): error CS0117: 'QuantumSimulator' does not contain a definition for
1515
// 'QSIM_DLL_NAME' [D:\a\1\s\submodules\QuantumLibraries\Standard\src\Standard.csproj]
1616

17+
[DllImport("libomp", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "omp_get_num_threads")]
18+
private static extern int OmpGetNumberOfThreadsNative();
19+
1720
private delegate void IdsCallback(uint id);
1821
[DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DumpIds")]
1922
private static extern void sim_QubitsIdsNative(uint id, IdsCallback callback);

src/Simulation/Simulators/QuantumSimulator/QuantumSimulator.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ public QuantumSimulator(
2828
randomNumberGeneratorSeed,
2929
disableBorrowing)
3030
{
31+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
32+
{
33+
// We don't need this value, but explicitly calling an OMP function should trigger the load of libomp
34+
// by .NET from the runtimes folder for the current platform, such that the later library load by the
35+
// simulator does not need to know where to search for it.
36+
var threadCount = OmpGetNumberOfThreadsNative();
37+
}
38+
3139
Id = InitNative();
3240
// Make sure that the same seed used by the built-in System.Random
3341
// instance is also used by the native simulator itself.

0 commit comments

Comments
 (0)