Skip to content

.NET assemblies used for invoking common executable tools in a separate process.

License

Notifications You must be signed in to change notification settings

Boyko-Karadzhov/External-Invocations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

External-Invocations

.NET assemblies used for invoking common executable tools in a separate process.

Build status Tests are not being ran automatically because of special environmental requirements.

Features

  • API for compiling code using the Visual Studio C/C++ Optimizing Compile;

Requirements

  • Visual Studio 2010 - 2013 (for VisualStudioCommonTools);
  • NVidia CUDA Toolkit (for NvidiaToolkit);

Disclaimer

  • This project does not contain a compiler. It invokes the VC compiler that is present on the system where VisualStudioTools assembly is called.

Installation

To install External-Invocations, run the following command in the Package Manager Console

PM> Install-Package Karadzhov.ExternalInvocations

Usage

Invoking the VC compiler

  1. Make sure your project references the Karadzhov.ExternalInvocations.VisualStudioCommonTools assembly;
  2. Add a using statement for this namespace: Karadzhov.ExternalInvocations.VisualStudioCommonTools;
  3. Create a new instance of the COptimizingCompiler class;
    • You can pass an argument to the constructor specifying the target platform. Amd64 and X86 are supported;
    • If you use the parameterless constructor the COptimizingCompiler class will target the architecture the current process is running in;
  4. Create an instance of the CCompileArguments class;
    • Use the Files property to pass file paths to the compiler (CL Filename Syntax);
    • Choose level of optimization by setting the Optimizations property (available options are None and MaximumOptimizations);
    • Set IsDll to true if you want the compiler to produce a dynamic library;
    • The Output property to instruct the linker about the output file name (/OUT (Output File Name));
  5. Call COptimizingCompiler.Compile with the arguments you have created to invoke the compiler;
    • There is no return value. Karadzhov.ExternalInvocations.VisualStudioCommonTools.CompilationException is thrown if the compilation was not successful.

Sample

This sample compiles a C source file into a DLL using C#.

   var compiler = new COptimizingCompiler();
   var arguments = new CCompileArguments();
   arguments.Files.Add(Path.Combine(samplesPath, "sum.c"));
   arguments.Optimizations = CompileOptimization.MaximumOptimization;
   arguments.IsDll = true;
   arguments.Output = "bin\\sum.dll";

   compiler.Compile(arguments);

Invoking the CUDA compiler

  1. Make sure your project references the Karadzhov.ExternalInvocations.NvidiaToolkit assembly;
  2. Add a using statement for this namespace: Karadzhov.ExternalInvocations.NvidiaToolkit;
  3. Create a new instance of the CudaCompiler class;
  4. Create a new instance of the CudaCompileArguments class;
    • This class inherits from CCompileArguments. Refer the instructions for the VC compiler for details;
    • Set the ComputeCapability property to specify the target GPU compute capability;
    • Set the TargetProcessorArchitecture to specify whether 32 or 64 bit binary should be compiled;
  5. Call CudaCompiler.Compile with the arguments you have created to invoke the compiler;
    • There is no return value. Karadzhov.ExternalInvocations.VisualStudioCommonTools.CompilationException is thrown if the compilation was not successful.

See also

Now that you are compiling DLLs on the fly you can also call them right away by using the Dynamic-Libraries project: Dynamic-Libraries

About

.NET assemblies used for invoking common executable tools in a separate process.

Resources

License

Stars

Watchers

Forks

Packages

No packages published