Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
0c4b5917
Commit
0c4b5917
authored
5 years ago
by
gaurides
Committed by
Scott Cyphers
5 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Codegen support for Dropout (#3075)
* Codegen support for Dropout * Different implementation
parent
90ca4d87
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
2 deletions
+52
-2
cpu_emitter.cpp
src/ngraph/runtime/cpu/cpu_emitter.cpp
+50
-1
cpu_kernels.hpp
src/ngraph/runtime/cpu/cpu_kernels.hpp
+2
-1
No files found.
src/ngraph/runtime/cpu/cpu_emitter.cpp
View file @
0c4b5917
...
...
@@ -4011,7 +4011,56 @@ namespace ngraph
template
<>
void
CPU_Emitter
::
EMITTER_DECL
(
ngraph
::
op
::
Dropout
)
{
throw
ngraph_error
(
"Not yet implemented"
);
auto
dropout
=
static_cast
<
const
ngraph
::
op
::
Dropout
*>
(
node
);
size_t
ncr
=
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_num_cores
();
writer
.
block_begin
();
writer
<<
"bool training = static_cast<bool>("
<<
args
[
1
].
get_name
()
<<
"[0]);
\n
"
;
writer
<<
"bool use_seed = "
<<
to_string
(
dropout
->
get_use_seed
())
<<
";
\n
"
;
writer
<<
"int32_t seed = use_seed ? "
<<
to_string
(
dropout
->
get_seed
())
<<
" : rand();
\n
"
;
writer
<<
"double keep_prob = static_cast<double>("
<<
args
[
4
].
get_name
()
<<
"[0]);
\n
"
;
writer
<<
"size_t count = "
<<
args
[
0
].
get_size
()
<<
";
\n
"
;
writer
<<
"size_t nthr = "
<<
to_string
(
ncr
)
<<
";
\n
"
;
//writer << "size_t nthr = " << to_string(ngraph::runtime::cpu::executor::GetCPUExecutor().get_num_cores()) << ";\n";
writer
<<
"size_t chunk_size = (count + nthr - 1) / nthr;
\n
"
;
writer
<<
"std::vector<std::minstd_rand> vmsr(nthr);
\n
"
;
writer
<<
"for (size_t i = 0; i < nthr; i++)
\n
\
{
\n
\
std::minstd_rand msr;
\n
\
msr.seed(seed+i);
\n
\
vmsr[i] = msr;
\n
\
}
\n
"
;
writer
<<
"double dropout_prob = 1 - keep_prob;
\n
"
;
writer
<<
"std::uniform_real_distribution<> gen(0, 1);
\n
"
;
writer
<<
"#pragma omp parallel num_threads(nthr)
\n
"
;
writer
<<
"{
\n
"
;
writer
<<
"size_t tid = omp_get_thread_num();
\n
"
;
writer
<<
"std::minstd_rand msr;
\n
msr.seed(seed+tid);
\n
"
;
writer
<<
"size_t idx_start = tid * chunk_size;
\n
"
;
writer
<<
"size_t idx_end = std::min(idx_start + chunk_size, count);
\n
"
;
writer
<<
"for (size_t i = idx_start; i < idx_end; i++)
\n
"
;
writer
<<
"{
\n
"
;
writer
<<
" //out[i] = training ? static_cast<T>(bd(gen)) : "
"static_cast<float>(1);
\n
"
;
writer
<<
" //out0[i] = training ? input[i] : static_cast<float>(1);
\n
"
;
writer
<<
" if (static_cast<float>(gen(msr)) < dropout_prob)
\n
"
;
writer
<<
" {
\n
"
;
writer
<<
" "
<<
out
[
0
].
get_name
()
<<
"[i] = 0;
\n
"
;
writer
<<
" "
<<
out
[
1
].
get_name
()
<<
"[i] = 0;
\n
"
;
writer
<<
" }
\n
"
;
writer
<<
" else
\n
"
;
writer
<<
" {
\n
"
;
writer
<<
" "
<<
out
[
1
].
get_name
()
<<
"[i] = 1;
\n
"
;
writer
<<
" "
<<
out
[
0
].
get_name
()
<<
"[i] = "
<<
args
[
0
].
get_name
()
<<
"[i] / static_cast<float>(keep_prob);
\n
"
;
writer
<<
" }
\n
"
;
writer
<<
"}
\n
"
;
// for loop ends
writer
<<
"}
\n
"
;
//#pragma ends
writer
.
block_end
();
}
template
<>
...
...
This diff is collapsed.
Click to expand it.
src/ngraph/runtime/cpu/cpu_kernels.hpp
View file @
0c4b5917
...
...
@@ -270,7 +270,8 @@ namespace ngraph
size_t
nelems
,
bool
training
,
const
double
value
,
const
std
::
vector
<
std
::
minstd_rand
>&
vmsr
);
const
std
::
vector
<
std
::
minstd_rand
>&
vmsr
,
const
bool
use_seed
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment