Skip to content

Commit

Permalink
Added graph only test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Mx7f committed Oct 24, 2017
1 parent c8d5a00 commit 14587e8
Show file tree
Hide file tree
Showing 7 changed files with 6,135 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/minimal_graph_only/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
EXECUTABLE = dense
OBJS = build/main.o
SRC = .
include ../../examples/shared/make_template.inc
12 changes: 12 additions & 0 deletions tests/minimal_graph_only/curveFitting.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
N,U = Dim("N",0), Dim("U",1)
funcParams = Unknown("funcParams", opt_float2, {U}, 0)
data = Image("data", opt_float2, {N}, 1)
local G = Graph("G", 2, "d", {N}, 3, "p", {U}, 4)
UsePreconditioner(true)

x,y = data(G.d)(0),data(G.d)(1)
a,b = funcParams(G.p)(0),funcParams(G.p)(1)
Energy(y - (a*cos(b*x) + b*sin(a*x)))

--local zeroIm = ComputedImage("zero",{U}, 0.0)
--Energy(zeroIm(0) * funcParams(0)(0)*funcParams(0)(1))
5,876 changes: 5,876 additions & 0 deletions tests/minimal_graph_only/log.txt

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions tests/minimal_graph_only/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
extern "C" {
#include "Opt.h"
}
#include <cstdlib>
#include <iostream>
#include <cuda_runtime.h>
#include <random>
#include <vector>

#define OPT_DOUBLE_PRECISION 1

#if OPT_DOUBLE_PRECISION
#define OPT_FLOAT double
#define OPT_FLOAT2 double2
#else
#define OPT_FLOAT float
#define OPT_FLOAT2 float2
#endif

void solve(int dataCount, int* startNodes, int* endNodes, OPT_FLOAT* params, OPT_FLOAT* data, std::string name) {
Opt_InitializationParameters param = {};
param.doublePrecision = OPT_DOUBLE_PRECISION;
param.verbosityLevel = 2;
param.collectPerKernelTimingInfo = 1;
//param.threadsPerBlock = 512;
Opt_State* state = Opt_NewState(param);
// load the Opt DSL file containing the cost description
Opt_Problem* problem = Opt_ProblemDefine(state, name.c_str(), "gaussNewtonGPU");
// describe the dimensions of the instance of the problem
unsigned int dims[] = { dataCount, 1 };
Opt_Plan* plan = Opt_ProblemPlan(state, problem, dims);
// run the solver
void* problem_data[] = { params, data, &dataCount, endNodes, startNodes };
Opt_ProblemSolve(state, plan, problem_data);
Opt_PlanFree(state, plan);
Opt_ProblemDelete(state, problem);
}


int main(){

const int dim = 512;
OPT_FLOAT2 generatorParams = { 100.0, 102.0 };
std::vector<OPT_FLOAT2> dataPoints(dim);
OPT_FLOAT a = generatorParams.x;
OPT_FLOAT b = generatorParams.y;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis(-50.0, 50.0);
for (int i = 0; i < dataPoints.size(); ++i) {
OPT_FLOAT x = float(i)*2.0*3.141592653589 / dim;
OPT_FLOAT y = (a*cos(b*x) + b*sin(a*x));
//y = a*x + b;
// Add in noise
//y += dis(gen);
dataPoints[i].x = x;
dataPoints[i].y = y;

}

OPT_FLOAT2 unknownInit = { 99.7f, 101.6f };

OPT_FLOAT *d_data, *d_unknown;
cudaMalloc(&d_data, dim*sizeof(OPT_FLOAT2));
cudaMalloc(&d_unknown, sizeof(OPT_FLOAT2));
cudaMemcpy(d_data, dataPoints.data(), dim*sizeof(OPT_FLOAT2), cudaMemcpyHostToDevice);


int *d_startNodes, *d_endNodes;
cudaMalloc(&d_startNodes, dim*sizeof(int));
cudaMalloc(&d_endNodes, dim*sizeof(int));


std::vector<int> endNodes;
for (int i = 0; i < dim; ++i) { endNodes.push_back(i); }
cudaMemset(d_startNodes, 0, dim*sizeof(int));
cudaMemcpy(d_endNodes, endNodes.data(), dim*sizeof(int), cudaMemcpyHostToDevice);

cudaMemcpy(d_unknown, &unknownInit, sizeof(OPT_FLOAT2), cudaMemcpyHostToDevice);
solve(dim, d_startNodes, d_endNodes, d_unknown, d_data, "curveFitting.t");


OPT_FLOAT2 unknownResult = {};
cudaMemcpy(&unknownResult, d_unknown, sizeof(OPT_FLOAT2), cudaMemcpyDeviceToHost);



std::cout << "Init " << unknownInit.x << ", " << unknownInit.y << std::endl;
std::cout << "Result " << unknownResult.x << ", " << unknownResult.y << std::endl;
std::cout << "Goal " << generatorParams.x << ", " << generatorParams.y << std::endl;

cudaFree(d_data);
cudaFree(d_unknown);
cudaFree(d_startNodes);
cudaFree(d_endNodes);
return 0;
}
22 changes: 22 additions & 0 deletions tests/minimal_graph_only/minimal_graph_only.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minimal_graph_only", "minimal_graph_only.vcxproj", "{849D4320-1C48-420E-BF82-61B69BE28789}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{849D4320-1C48-420E-BF82-61B69BE28789}.Debug|x64.ActiveCfg = Debug|x64
{849D4320-1C48-420E-BF82-61B69BE28789}.Debug|x64.Build.0 = Debug|x64
{849D4320-1C48-420E-BF82-61B69BE28789}.Release|x64.ActiveCfg = Release|x64
{849D4320-1C48-420E-BF82-61B69BE28789}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
120 changes: 120 additions & 0 deletions tests/minimal_graph_only/minimal_graph_only.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{849D4320-1C48-420E-BF82-61B69BE28789}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>minimal_graph_only</RootNamespace>
<ProjectName>minimal_graph_only</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 7.5.props" />
</ImportGroup>
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(CUDA_INC_PATH);$(IncludePath);</IncludePath>
<LibraryPath>$(CUDA_LIB_PATH);$(LibraryPath);</LibraryPath>
<OutDir>$(ProjectDir)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<OpenMPSupport>false</OpenMPSupport>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FloatingPointModel>Fast</FloatingPointModel>
<ExceptionHandling>Sync</ExceptionHandling>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<CudaCompile>
<Include>$(ProjectDir)</Include>
<TargetMachinePlatform>64</TargetMachinePlatform>
<CodeGeneration>compute_30,sm_30;compute_35,sm_35</CodeGeneration>
<MaxRegCount>62</MaxRegCount>
</CudaCompile>
<PreBuildEvent>
<Command>call "..\..\API\common\optMake.bat" "$(ProjectDir)\..\..\..\terra" "..\..\API" "false"
xcopy /Y /D "..\..\API\release\bin\*.dll" "."
xcopy /Y /D "..\..\API\release\lib\*.lib" "."
xcopy /Y /D "..\..\API\release\include\*.h" "."</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PreprocessorDefinitions>NOMINMAX;WIN32;_DEBUG;DEBUG;PROFILE;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
</ClCompile>
<Link>
<AdditionalDependencies>cudart.lib;Opt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PreprocessorDefinitions>NOMINMAX;WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>cudart.lib;Opt.lib;%(AdditionalDependencies)</AdditionalDependencies>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Manifest>
<EnableDPIAwareness>true</EnableDPIAwareness>
</Manifest>
<CudaCompile>
<FastMath>true</FastMath>
<Optimization>O3</Optimization>
</CudaCompile>
</ItemDefinitionGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="curveFitting.t" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 7.5.targets" />
</ImportGroup>
</Project>
4 changes: 4 additions & 0 deletions tests/minimal_graph_only/minimal_graph_only.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

0 comments on commit 14587e8

Please sign in to comment.