Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
one
spconv
Commits
47bea04c
Commit
47bea04c
authored
Jun 09, 2020
by
yanyan
Browse files
Merge branch 'master' into develop
parents
60781119
468b5713
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
21 deletions
+44
-21
src/spconv/spconv_ops.cc
src/spconv/spconv_ops.cc
+44
-21
No files found.
src/spconv/spconv_ops.cc
View file @
47bea04c
...
@@ -170,26 +170,37 @@ torch::Tensor indiceConv(torch::Tensor features, torch::Tensor filters,
...
@@ -170,26 +170,37 @@ torch::Tensor indiceConv(torch::Tensor features, torch::Tensor filters,
auto
numInPlanes
=
features
.
size
(
1
);
auto
numInPlanes
=
features
.
size
(
1
);
auto
numOutPlanes
=
filters
.
size
(
ndim
+
1
);
auto
numOutPlanes
=
filters
.
size
(
ndim
+
1
);
auto
indicePairNumCpu
=
indiceNum
.
to
({
torch
::
kCPU
});
auto
indicePairNumCpu
=
indiceNum
.
to
({
torch
::
kCPU
});
auto
indicePairMaxSizeIter
=
std
::
max_element
(
indicePairNumCpu
.
data_ptr
<
int
>
(),
indicePairNumCpu
.
data_ptr
<
int
>
()
+
kernelVolume
);
int
indicePairMaxOffset
=
indicePairMaxSizeIter
-
indicePairNumCpu
.
data_ptr
<
int
>
();
int
indicePairMaxSize
=
*
indicePairMaxSizeIter
;
auto
options
=
auto
options
=
torch
::
TensorOptions
().
dtype
(
features
.
dtype
()).
device
(
features
.
device
());
torch
::
TensorOptions
().
dtype
(
features
.
dtype
()).
device
(
features
.
device
());
torch
::
Tensor
output
=
torch
::
zeros
({
numActOut
,
numOutPlanes
},
options
);
torch
::
Tensor
output
=
torch
::
zeros
({
numActOut
,
numOutPlanes
},
options
);
torch
::
Tensor
inputBuffer
=
torch
::
empty
({
indicePairMaxSize
,
numInPlanes
},
options
);
torch
::
Tensor
outputBuffer
=
torch
::
empty
({
indicePairMaxSize
,
numOutPlanes
},
options
);
filters
=
filters
.
view
({
-
1
,
numInPlanes
,
numOutPlanes
});
filters
=
filters
.
view
({
-
1
,
numInPlanes
,
numOutPlanes
});
// init for subM
int
indicePairMaxOffset
=
kernelVolume
/
2
;
int
indicePairMaxSize
=
numActOut
;
if
(
subM
)
{
// the center index of subm conv don't need gather and scatter
if
(
subM
)
{
// the center index of subm conv don't need gather and scatter
// add.
// add.
torch
::
mm_out
(
output
,
features
,
filters
[
indicePairMaxOffset
]);
torch
::
mm_out
(
output
,
features
,
filters
[
indicePairMaxOffset
]);
// get indice pair second max size based on subM symmetric property
indicePairMaxSize
=
*
std
::
max_element
(
indicePairNumCpu
.
data_ptr
<
int
>
(),
indicePairNumCpu
.
data_ptr
<
int
>
()
+
indicePairMaxOffset
);
if
(
indicePairMaxSize
==
0
)
{
return
output
;
}
}
else
{
indicePairMaxSize
=
*
std
::
max_element
(
indicePairNumCpu
.
data_ptr
<
int
>
(),
indicePairNumCpu
.
data_ptr
<
int
>
()
+
kernelVolume
);
}
}
torch
::
Tensor
inputBuffer
=
torch
::
empty
({
indicePairMaxSize
,
numInPlanes
},
options
);
torch
::
Tensor
outputBuffer
=
torch
::
empty
({
indicePairMaxSize
,
numOutPlanes
},
options
);
double
totalGatherTime
=
0
;
double
totalGatherTime
=
0
;
double
totalGEMMTime
=
0
;
double
totalGEMMTime
=
0
;
double
totalSAddTime
=
0
;
double
totalSAddTime
=
0
;
...
@@ -408,29 +419,41 @@ indiceConvBackward(torch::Tensor features, torch::Tensor filters,
...
@@ -408,29 +419,41 @@ indiceConvBackward(torch::Tensor features, torch::Tensor filters,
auto
numInPlanes
=
features
.
size
(
1
);
auto
numInPlanes
=
features
.
size
(
1
);
auto
numOutPlanes
=
filters
.
size
(
ndim
+
1
);
auto
numOutPlanes
=
filters
.
size
(
ndim
+
1
);
auto
indicePairNumCpu
=
indiceNum
.
to
({
torch
::
kCPU
});
auto
indicePairNumCpu
=
indiceNum
.
to
({
torch
::
kCPU
});
auto
indicePairMaxSizeIter
=
std
::
max_element
(
indicePairNumCpu
.
data_ptr
<
int
>
(),
indicePairNumCpu
.
data_ptr
<
int
>
()
+
kernelVolume
);
int
indicePairMaxOffset
=
indicePairMaxSizeIter
-
indicePairNumCpu
.
data_ptr
<
int
>
();
int
indicePairMaxSize
=
*
indicePairMaxSizeIter
;
auto
options
=
auto
options
=
torch
::
TensorOptions
().
dtype
(
features
.
dtype
()).
device
(
features
.
device
());
torch
::
TensorOptions
().
dtype
(
features
.
dtype
()).
device
(
features
.
device
());
auto
filterShape
=
filters
.
sizes
();
auto
filterShape
=
filters
.
sizes
();
torch
::
Tensor
inputGrad
=
torch
::
zeros
(
features
.
sizes
(),
options
);
torch
::
Tensor
inputGrad
=
torch
::
zeros
(
features
.
sizes
(),
options
);
torch
::
Tensor
filtersGrad
=
torch
::
empty
(
filterShape
,
options
);
torch
::
Tensor
filtersGrad
=
torch
::
empty
(
filterShape
,
options
);
torch
::
Tensor
inputBuffer
=
torch
::
empty
({
indicePairMaxSize
,
numInPlanes
},
options
);
torch
::
Tensor
outputBuffer
=
torch
::
empty
({
indicePairMaxSize
,
numOutPlanes
},
options
);
filters
=
filters
.
view
({
-
1
,
numInPlanes
,
numOutPlanes
});
filters
=
filters
.
view
({
-
1
,
numInPlanes
,
numOutPlanes
});
filtersGrad
=
filtersGrad
.
view
({
-
1
,
numInPlanes
,
numOutPlanes
});
filtersGrad
=
filtersGrad
.
view
({
-
1
,
numInPlanes
,
numOutPlanes
});
// init for subM
int
indicePairMaxOffset
=
kernelVolume
/
2
;
int
indicePairMaxSize
=
indicePairNumCpu
.
data_ptr
<
int
>
()[
indicePairMaxOffset
];
if
(
subM
)
{
if
(
subM
)
{
auto
filterGradSub
=
filtersGrad
[
indicePairMaxOffset
];
auto
filterGradSub
=
filtersGrad
[
indicePairMaxOffset
];
torch
::
mm_out
(
filterGradSub
,
features
.
t
(),
outGrad
);
torch
::
mm_out
(
filterGradSub
,
features
.
t
(),
outGrad
);
torch
::
mm_out
(
inputGrad
,
outGrad
,
filters
[
indicePairMaxOffset
].
t
());
torch
::
mm_out
(
inputGrad
,
outGrad
,
filters
[
indicePairMaxOffset
].
t
());
// get indice pair second max size based on subM symmetric property
indicePairMaxSize
=
*
std
::
max_element
(
indicePairNumCpu
.
data_ptr
<
int
>
(),
indicePairNumCpu
.
data_ptr
<
int
>
()
+
indicePairMaxOffset
);
if
(
indicePairMaxSize
==
0
)
{
return
{
inputGrad
,
filtersGrad
.
view
(
filterShape
)};
}
}
else
{
indicePairMaxSize
=
*
std
::
max_element
(
indicePairNumCpu
.
data_ptr
<
int
>
(),
indicePairNumCpu
.
data_ptr
<
int
>
()
+
kernelVolume
);
}
}
torch
::
Tensor
inputBuffer
=
torch
::
empty
({
indicePairMaxSize
,
numInPlanes
},
options
);
torch
::
Tensor
outputBuffer
=
torch
::
empty
({
indicePairMaxSize
,
numOutPlanes
},
options
);
for
(
int
i
=
0
;
i
<
kernelVolume
;
++
i
)
{
for
(
int
i
=
0
;
i
<
kernelVolume
;
++
i
)
{
auto
nHot
=
indicePairNumCpu
.
data_ptr
<
int
>
()[
i
];
auto
nHot
=
indicePairNumCpu
.
data_ptr
<
int
>
()[
i
];
if
(
nHot
<=
0
||
(
subM
&&
i
==
indicePairMaxOffset
))
{
if
(
nHot
<=
0
||
(
subM
&&
i
==
indicePairMaxOffset
))
{
...
@@ -603,4 +626,4 @@ indiceConvBackwardBatch(torch::Tensor features, torch::Tensor filters,
...
@@ -603,4 +626,4 @@ indiceConvBackwardBatch(torch::Tensor features, torch::Tensor filters,
return
{
inputGrad
,
filtersGrad
.
view
(
filterShape
)};
return
{
inputGrad
,
filtersGrad
.
view
(
filterShape
)};
}
}
}
// namespace spconv
}
// namespace spconv
\ No newline at end of file
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