Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VkCV Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vulkan2021
VkCV Framework
Merge requests
!79
Draft: Resolve "Compute: First Network"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Draft: Resolve "Compute: First Network"
91-compute-first-network
into
develop
Overview
0
Commits
11
Pipelines
12
Changes
2
Open
Josch Morgenstern
requested to merge
91-compute-first-network
into
develop
3 years ago
Overview
0
Commits
11
Pipelines
12
Changes
2
Expand
Closes
#91
0
0
Merge request reports
Viewing commit
915e0b90
Prev
Next
Show latest version
2 files
+
14
−
10
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
915e0b90
[
#91
] small fixes, still not working
· 915e0b90
Lars Hoerttrich
authored
3 years ago
projects/neural_network/src/main.cpp
0 → 100644
+
89
−
0
Options
#include
<iostream>
#include
<vkcv/Core.hpp>
#include
<GLFW/glfw3.h>
#include
<chrono>
#include
<vkcv/shader/GLSLCompiler.hpp>
int
main
(
int
argc
,
const
char
**
argv
)
{
const
char
*
applicationName
=
"Neural-Network"
;
uint32_t
windowWidth
=
800
;
uint32_t
windowHeight
=
600
;
vkcv
::
Window
window
=
vkcv
::
Window
::
create
(
applicationName
,
windowWidth
,
windowHeight
,
true
);
vkcv
::
Core
core
=
vkcv
::
Core
::
create
(
window
,
applicationName
,
VK_MAKE_VERSION
(
0
,
0
,
1
),
{
vk
::
QueueFlagBits
::
eTransfer
,
vk
::
QueueFlagBits
::
eGraphics
,
vk
::
QueueFlagBits
::
eCompute
},
{
"VK_KHR_swapchain"
}
);
int
input
[
64
]
=
{
0
};
std
::
fill_n
(
input
,
64
,
2
);
vkcv
::
Buffer
<
int
>
inputBuffer
=
core
.
createBuffer
<
int
>
(
vkcv
::
BufferType
::
STORAGE
,
64
,
vkcv
::
BufferMemoryType
::
HOST_VISIBLE
);
inputBuffer
.
fill
(
input
);
vkcv
::
PassConfig
computePassDefinition
({});
vkcv
::
PassHandle
computePass
=
core
.
createPass
(
computePassDefinition
);
if
(
!
computePass
)
{
std
::
cout
<<
"Error. Could not create renderpass. Exiting."
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
// shader path
std
::
string
shaderPathCompute
=
"resources/shaders/simpleShader.comp"
;
vkcv
::
shader
::
GLSLCompiler
compiler
;
vkcv
::
ShaderProgram
computeShaderProgram
{};
compiler
.
compile
(
vkcv
::
ShaderStage
::
COMPUTE
,
shaderPathCompute
,
[
&
](
vkcv
::
ShaderStage
shaderStage
,
const
std
::
filesystem
::
path
&
path
)
{
computeShaderProgram
.
addShader
(
shaderStage
,
path
);
});
vkcv
::
DescriptorSetHandle
computeDescriptorSet
=
core
.
createDescriptorSet
(
computeShaderProgram
.
getReflectedDescriptors
()[
0
]);
vkcv
::
PipelineHandle
computePipeline
=
core
.
createComputePipeline
(
computeShaderProgram
,
{
core
.
getDescriptorSet
(
computeDescriptorSet
).
layout
});
vkcv
::
DescriptorWrites
computeWrites
;
computeWrites
.
storageBufferWrites
=
{
vkcv
::
BufferDescriptorWrite
(
0
,
inputBuffer
.
getHandle
())
};
core
.
writeDescriptorSet
(
computeDescriptorSet
,
computeWrites
);
if
(
!
computePipeline
)
{
std
::
cout
<<
"Error. Could not create compute pipeline. Exiting."
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
for
(
int
i
=
0
;
i
<
3
;
i
++
){
auto
cmdStream
=
core
.
createCommandStream
(
vkcv
::
QueueType
::
Compute
);
uint32_t
computeDispatchCount
[
3
]
=
{
64
,
1
,
1
};
vkcv
::
PushConstants
pushConstantsCompute
(
sizeof
(
int
));
pushConstantsCompute
.
appendDrawcall
(
1
);
core
.
recordComputeDispatchToCmdStream
(
cmdStream
,
computePipeline
,
computeDispatchCount
,
{
vkcv
::
DescriptorSetUsage
(
0
,
core
.
getDescriptorSet
(
computeDescriptorSet
).
vulkanHandle
)
},
pushConstantsCompute
);
int
output
[
64
]
=
{
0
};
std
::
fill_n
(
output
,
64
,
-
1
);
core
.
recordReadBuffer
(
cmdStream
,
inputBuffer
.
getHandle
(),
&
output
);
core
.
submitCommandStream
(
cmdStream
);
std
::
cout
<<
"["
;
for
(
int
i
=
0
;
i
<
64
;
i
++
)
{
std
::
cout
<<
output
[
i
]
<<
", "
;
}
std
::
cout
<<
"]"
<<
std
::
endl
;
}
return
0
;
}
Loading