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

Commit

Permalink
libomp workaround for Linux, Mac (#897)
Browse files Browse the repository at this point in the history
* Workaround for libomp on Linux, Mac

* Try renaming file

* Add special case copy for local dev dependencies
  • Loading branch information
swernli committed Jan 12, 2022
1 parent b7668ca commit e25fa0f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Simulation/Common/Simulators.Dev.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<QSimDll Condition="$([MSBuild]::IsOsPlatform('OSX'))">$(QsimDllMac)</QSimDll>
<QSimDll Condition="$([MSBuild]::IsOsPlatform('Linux'))">$(QsimDllLinux)</QSimDll>
<QSimDll Condition="$([MSBuild]::IsOsPlatform('Windows'))">$(QsimDllWindows)</QSimDll>
<QSimDependencies Condition="$([MSBuild]::IsOsPlatform('OSX'))">$([MSBuild]::NormalizePath($(NativeBuildPath)/../../osx))</QSimDependencies>
<QSimDependencies Condition="$([MSBuild]::IsOsPlatform('Linux'))">$([MSBuild]::NormalizePath($(NativeBuildPath)/../../linux))</QSimDependencies>
<QSimDependencies Condition="$([MSBuild]::IsOsPlatform('Windows'))">$([MSBuild]::NormalizePath($(NativeBuildPath)/../../win10))</QSimDependencies>
</PropertyGroup>

<ItemGroup>
Expand All @@ -29,6 +32,11 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
<None Include="$(QSimDependencies)/**/*" >
<Link>%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
</ItemGroup>

<!-- Copy the experimental simulators from xplat/qdk_sim_rs build to where we can see and use it. -->
Expand Down
3 changes: 3 additions & 0 deletions src/Simulation/Simulators/QuantumSimulator/NativeImports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public partial class QuantumSimulator
// Preparation\Arbitrary.cs(23,41): error CS0117: 'QuantumSimulator' does not contain a definition for
// 'QSIM_DLL_NAME' [D:\a\1\s\submodules\QuantumLibraries\Standard\src\Standard.csproj]

[DllImport("libomp", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "omp_get_num_threads")]
private static extern int OmpGetNumberOfThreadsNative();

private delegate void IdsCallback(uint id);
[DllImport(QSIM_DLL_NAME, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DumpIds")]
private static extern void sim_QubitsIdsNative(uint id, IdsCallback callback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public partial class QuantumSimulator : CommonNativeSimulator
randomNumberGeneratorSeed,
disableBorrowing)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// We don't need this value, but explicitly calling an OMP function should trigger the load of libomp
// by .NET from the runtimes folder for the current platform, such that the later library load by the
// simulator does not need to know where to search for it.
var threadCount = OmpGetNumberOfThreadsNative();
}

Id = InitNative();
// Make sure that the same seed used by the built-in System.Random
// instance is also used by the native simulator itself.
Expand Down

0 comments on commit e25fa0f

Please sign in to comment.