Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
SparseConvNet
Commits
2c4ed608
Commit
2c4ed608
authored
Jun 20, 2018
by
Benjamin Thomas Graham
Browse files
Goodbye THNN. Hello ATen!
parent
6d4475db
Changes
145
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
974 additions
and
932 deletions
+974
-932
sparseconvnet/SCN/Metadata/32bits.h
sparseconvnet/SCN/Metadata/32bits.h
+68
-0
sparseconvnet/SCN/Metadata/64bits.h
sparseconvnet/SCN/Metadata/64bits.h
+68
-0
sparseconvnet/SCN/Metadata/ActivePoolingRules.h
sparseconvnet/SCN/Metadata/ActivePoolingRules.h
+3
-4
sparseconvnet/SCN/Metadata/ConvolutionRules.h
sparseconvnet/SCN/Metadata/ConvolutionRules.h
+34
-33
sparseconvnet/SCN/Metadata/FullConvolutionRules.h
sparseconvnet/SCN/Metadata/FullConvolutionRules.h
+18
-20
sparseconvnet/SCN/Metadata/IOLayersRules.h
sparseconvnet/SCN/Metadata/IOLayersRules.h
+34
-36
sparseconvnet/SCN/Metadata/Metadata.cpp
sparseconvnet/SCN/Metadata/Metadata.cpp
+513
-0
sparseconvnet/SCN/Metadata/Metadata.h
sparseconvnet/SCN/Metadata/Metadata.h
+144
-0
sparseconvnet/SCN/Metadata/RandomizedStrideRules.h
sparseconvnet/SCN/Metadata/RandomizedStrideRules.h
+59
-57
sparseconvnet/SCN/Metadata/RectangularRegions.h
sparseconvnet/SCN/Metadata/RectangularRegions.h
+13
-13
sparseconvnet/SCN/Metadata/SubmanifoldConvolutionRules.h
sparseconvnet/SCN/Metadata/SubmanifoldConvolutionRules.h
+20
-21
sparseconvnet/SCN/__init__.py
sparseconvnet/SCN/__init__.py
+0
-15
sparseconvnet/SCN/generic/CPU/ActivePooling.cpp
sparseconvnet/SCN/generic/CPU/ActivePooling.cpp
+0
-45
sparseconvnet/SCN/generic/CPU/AffineReluTrivialConvolution.cpp
...econvnet/SCN/generic/CPU/AffineReluTrivialConvolution.cpp
+0
-42
sparseconvnet/SCN/generic/CPU/AveragePooling.cpp
sparseconvnet/SCN/generic/CPU/AveragePooling.cpp
+0
-60
sparseconvnet/SCN/generic/CPU/BatchNormalization.cpp
sparseconvnet/SCN/generic/CPU/BatchNormalization.cpp
+0
-79
sparseconvnet/SCN/generic/CPU/BatchwiseMultiplicativeDropout.cpp
...onvnet/SCN/generic/CPU/BatchwiseMultiplicativeDropout.cpp
+0
-42
sparseconvnet/SCN/generic/CPU/Convolution.cpp
sparseconvnet/SCN/generic/CPU/Convolution.cpp
+0
-243
sparseconvnet/SCN/generic/CPU/Convolution.h
sparseconvnet/SCN/generic/CPU/Convolution.h
+0
-155
sparseconvnet/SCN/generic/CPU/Deconvolution.cpp
sparseconvnet/SCN/generic/CPU/Deconvolution.cpp
+0
-67
No files found.
sparseconvnet/SCN/
generic
/32bits.h
→
sparseconvnet/SCN/
Metadata
/32bits.h
View file @
2c4ed608
...
...
@@ -5,66 +5,58 @@
// LICENSE file in the root directory of this source tree.
#include <array>
#include <tuple>
// Using 32 bit integers for coordinates and memory calculations.
// They could be replaced with 64 bit integers.
// Advantages of 64 bit:
// - support for nFeatures * nActiveSites > 2^32 per hidden layer per batch
// Disadvantages:
// - larger, and therefore slower, data copies from CPU -> GPU
// - more device memory needed to store sparseconvnet 'rulebooks'
// - not really needed until GPUs have >> 32GB RAM
using
Int
=
int32_t
;
using
uInt
=
uint32_t
;
// Max value = uInt_MAX used to denote 'non-existent'
const
uInt
uInt_MAX
=
4294967295
;
// 2^32-1
const
uInt
Int_MAX
=
2147483647
;
// 2^31-1
// Point<dimension> is a point in the d-dimensional integer lattice
// (i.e. square-grid/cubic-grid, ...)
template
<
u
Int
dimension
>
using
Point
=
std
::
array
<
Int
,
dimension
>
;
template
<
Int
dimension
>
using
Point
=
std
::
array
<
Int
,
dimension
>
;
template
<
uInt
dimension
>
Point
<
dimension
>
LongTensorToPoint
(
THLongTensor
*
t
)
{
template
<
Int
dimension
>
Point
<
dimension
>
LongTensorToPoint
(
/*long*/
at
::
Tensor
&
t
)
{
Point
<
dimension
>
p
;
long
*
td
=
THLongTensor_data
(
t
);
for
(
i
nt
i
=
0
;
i
<
dimension
;
i
++
)
long
*
td
=
t
.
data
<
long
>
(
);
for
(
I
nt
i
=
0
;
i
<
dimension
;
i
++
)
p
[
i
]
=
td
[
i
];
return
p
;
}
template
<
uInt
dimension
>
Point
<
2
*
dimension
>
TwoLongTensorsToPoint
(
THLongTensor
*
t0
,
THLongTensor
*
t1
)
{
template
<
Int
dimension
>
Point
<
2
*
dimension
>
TwoLongTensorsToPoint
(
/*long*/
at
::
Tensor
&
t0
,
/*long*/
at
::
Tensor
&
t1
)
{
Point
<
2
*
dimension
>
p
;
long
*
td
;
td
=
THLongTensor_data
(
t0
);
for
(
i
nt
i
=
0
;
i
<
dimension
;
i
++
)
td
=
t0
.
data
<
long
>
(
);
for
(
I
nt
i
=
0
;
i
<
dimension
;
i
++
)
p
[
i
]
=
td
[
i
];
td
=
THLongTensor_data
(
t1
);
for
(
i
nt
i
=
0
;
i
<
dimension
;
i
++
)
td
=
t1
.
data
<
long
>
(
);
for
(
I
nt
i
=
0
;
i
<
dimension
;
i
++
)
p
[
i
+
dimension
]
=
td
[
i
];
return
p
;
}
template
<
uInt
dimension
>
Point
<
3
*
dimension
>
ThreeLongTensorsToPoint
(
THLongTensor
*
t0
,
THLongTensor
*
t1
,
THLongTensor
*
t2
)
{
template
<
Int
dimension
>
Point
<
3
*
dimension
>
ThreeLongTensorsToPoint
(
/*long*/
at
::
Tensor
&
t0
,
/*long*/
at
::
Tensor
&
t1
,
/*long*/
at
::
Tensor
&
t2
)
{
Point
<
3
*
dimension
>
p
;
long
*
td
;
td
=
THLongTensor_data
(
t0
);
for
(
i
nt
i
=
0
;
i
<
dimension
;
i
++
)
td
=
t0
.
data
<
long
>
(
);
for
(
I
nt
i
=
0
;
i
<
dimension
;
i
++
)
p
[
i
]
=
td
[
i
];
td
=
THLongTensor_data
(
t1
);
for
(
i
nt
i
=
0
;
i
<
dimension
;
i
++
)
td
=
t1
.
data
<
long
>
(
);
for
(
I
nt
i
=
0
;
i
<
dimension
;
i
++
)
p
[
i
+
dimension
]
=
td
[
i
];
td
=
THLongTensor_data
(
t2
);
for
(
i
nt
i
=
0
;
i
<
dimension
;
i
++
)
td
=
t2
.
data
<
long
>
(
);
for
(
I
nt
i
=
0
;
i
<
dimension
;
i
++
)
p
[
i
+
2
*
dimension
]
=
td
[
i
];
return
p
;
}
// FNV Hash function for Point<dimension>
template
<
u
Int
dimension
>
struct
IntArrayHash
{
template
<
Int
dimension
>
struct
IntArrayHash
{
std
::
size_t
operator
()(
Point
<
dimension
>
const
&
p
)
const
{
u
Int
hash
=
16777619
;
Int
hash
=
16777619
;
for
(
auto
x
:
p
)
{
hash
*=
2166136261
;
hash
^=
x
;
...
...
@@ -73,5 +65,4 @@ template <uInt dimension> struct IntArrayHash {
}
};
#define THCITensor THCudaIntTensor
#define THCITensor_(NAME) TH_CONCAT_3(THCITensor, _, NAME)
#define at_kINT at::kInt
sparseconvnet/SCN/
generic
/64bits.h
→
sparseconvnet/SCN/
Metadata
/64bits.h
View file @
2c4ed608
...
...
@@ -5,66 +5,58 @@
// LICENSE file in the root directory of this source tree.
#include <array>
#include <tuple>
// Using 32 bit integers for coordinates and memory calculations.
// They could be replaced with 64 bit integers.
// Advantages of 64 bit:
// - support for nFeatures * nActiveSites > 2^32 per hidden layer per batch
// Disadvantages:
// - larger, and therefore slower, data copies from CPU -> GPU
// - more device memory needed to store sparseconvnet 'rulebooks'
// - not really needed until GPUs have >> 32GB RAM
// Using 64 bit integers for coordinates and memory calculations.
using
Int
=
int64_t
;
using
uInt
=
uint64_t
;
// Max value = uInt_MAX used to denote 'non-existent'
const
uInt
uInt_MAX
=
18446744073709551615
;
// 2^64-1
const
uInt
Int_MAX
=
9223372036854775807
;
// 2^63-1
// Point<dimension> is a point in the d-dimensional integer lattice
// (i.e. square-grid/cubic-grid, ...)
template
<
u
Int
dimension
>
using
Point
=
std
::
array
<
Int
,
dimension
>
;
template
<
Int
dimension
>
using
Point
=
std
::
array
<
Int
,
dimension
>
;
template
<
uInt
dimension
>
Point
<
dimension
>
LongTensorToPoint
(
THLongTensor
*
t
)
{
template
<
Int
dimension
>
Point
<
dimension
>
LongTensorToPoint
(
/*long*/
at
::
Tensor
&
t
)
{
Point
<
dimension
>
p
;
long
*
td
=
THLongTensor_data
(
t
);
for
(
i
nt
i
=
0
;
i
<
dimension
;
i
++
)
long
*
td
=
t
.
data
<
long
>
(
);
for
(
I
nt
i
=
0
;
i
<
dimension
;
i
++
)
p
[
i
]
=
td
[
i
];
return
p
;
}
template
<
uInt
dimension
>
Point
<
2
*
dimension
>
TwoLongTensorsToPoint
(
THLongTensor
*
t0
,
THLongTensor
*
t1
)
{
template
<
Int
dimension
>
Point
<
2
*
dimension
>
TwoLongTensorsToPoint
(
/*long*/
at
::
Tensor
&
t0
,
/*long*/
at
::
Tensor
&
t1
)
{
Point
<
2
*
dimension
>
p
;
long
*
td
;
td
=
THLongTensor_data
(
t0
);
for
(
i
nt
i
=
0
;
i
<
dimension
;
i
++
)
td
=
t0
.
data
<
long
>
(
);
for
(
I
nt
i
=
0
;
i
<
dimension
;
i
++
)
p
[
i
]
=
td
[
i
];
td
=
THLongTensor_data
(
t1
);
for
(
i
nt
i
=
0
;
i
<
dimension
;
i
++
)
td
=
t1
.
data
<
long
>
(
);
for
(
I
nt
i
=
0
;
i
<
dimension
;
i
++
)
p
[
i
+
dimension
]
=
td
[
i
];
return
p
;
}
template
<
uInt
dimension
>
Point
<
3
*
dimension
>
ThreeLongTensorsToPoint
(
THLongTensor
*
t0
,
THLongTensor
*
t1
,
THLongTensor
*
t2
)
{
template
<
Int
dimension
>
Point
<
3
*
dimension
>
ThreeLongTensorsToPoint
(
/*long*/
at
::
Tensor
&
t0
,
/*long*/
at
::
Tensor
&
t1
,
/*long*/
at
::
Tensor
&
t2
)
{
Point
<
3
*
dimension
>
p
;
long
*
td
;
td
=
THLongTensor_data
(
t0
);
for
(
i
nt
i
=
0
;
i
<
dimension
;
i
++
)
td
=
t0
.
data
<
long
>
(
);
for
(
I
nt
i
=
0
;
i
<
dimension
;
i
++
)
p
[
i
]
=
td
[
i
];
td
=
THLongTensor_data
(
t1
);
for
(
i
nt
i
=
0
;
i
<
dimension
;
i
++
)
td
=
t1
.
data
<
long
>
(
);
for
(
I
nt
i
=
0
;
i
<
dimension
;
i
++
)
p
[
i
+
dimension
]
=
td
[
i
];
td
=
THLongTensor_data
(
t2
);
for
(
i
nt
i
=
0
;
i
<
dimension
;
i
++
)
td
=
t2
.
data
<
long
>
(
);
for
(
I
nt
i
=
0
;
i
<
dimension
;
i
++
)
p
[
i
+
2
*
dimension
]
=
td
[
i
];
return
p
;
}
// FNV Hash function for Point<dimension>
template
<
u
Int
dimension
>
struct
IntArrayHash
{
template
<
Int
dimension
>
struct
IntArrayHash
{
std
::
size_t
operator
()(
Point
<
dimension
>
const
&
p
)
const
{
u
Int
hash
=
14695981039346656037
;
Int
hash
=
-
3750763034362895579
;
//
14695981039346656037;
for
(
auto
x
:
p
)
{
hash
*=
1099511628211
;
hash
^=
x
;
...
...
@@ -73,5 +65,4 @@ template <uInt dimension> struct IntArrayHash {
}
};
#define THCITensor THCudaLongTensor
#define THCITensor_(NAME) TH_CONCAT_3(THCITensor, _, NAME)
#define at_kINT at::kLong
sparseconvnet/SCN/
generic/Geometry
/ActivePoolingRules.h
→
sparseconvnet/SCN/
Metadata
/ActivePoolingRules.h
View file @
2c4ed608
...
...
@@ -6,7 +6,6 @@
#ifndef ACTIVEPOOLING_H
#define ACTIVEPOOLING_H
#include "../SparseConvNet.h"
// Return the maximum number of active sites in the batch
// rules has size 1.
...
...
@@ -14,14 +13,14 @@
// First column is number of active sites for that sample (<= maxActive)
// Remaining maxActive columns give the active sites, zero padded.
template
<
u
Int
dimension
>
template
<
Int
dimension
>
void
activePoolingRules
(
SparseGrids
<
dimension
>
&
SGs
,
RuleBook
&
rules
)
{
rules
.
clear
();
rules
.
resize
(
2
);
auto
&
r
=
rules
[
0
];
u
Int
maxActive
=
0
;
Int
maxActive
=
0
;
for
(
auto
&
sg
:
SGs
)
maxActive
=
std
::
max
(
maxActive
,
(
u
Int
)
sg
.
mp
.
size
());
maxActive
=
std
::
max
(
maxActive
,
(
Int
)
sg
.
mp
.
size
());
for
(
auto
&
sg
:
SGs
)
{
r
.
push_back
(
sg
.
mp
.
size
());
for
(
auto
&
iter
:
sg
.
mp
)
...
...
sparseconvnet/SCN/
generic/Geometry
/ConvolutionRules.h
→
sparseconvnet/SCN/
Metadata
/ConvolutionRules.h
View file @
2c4ed608
...
...
@@ -8,7 +8,7 @@
#define CONVOLUTIONRULES_H
#include "RectangularRegions.h"
template
<
u
Int
dimension
>
template
<
Int
dimension
>
void
Convolution_InputSgToRulesAndOutputSg
(
SparseGrid
<
dimension
>
&
inputGrid
,
SparseGrid
<
dimension
>
&
outputGrid
,
RuleBook
&
rules
,
long
*
size
,
...
...
@@ -17,10 +17,11 @@ void Convolution_InputSgToRulesAndOutputSg(SparseGrid<dimension> &inputGrid,
rules
.
resize
(
volume
<
dimension
>
(
size
));
for
(
auto
const
&
inIter
:
inputGrid
.
mp
)
{
for
(
auto
j
:
OutputRegionCalculator
<
dimension
>
(
inIter
.
first
,
size
,
stride
,
outputSpatialSize
))
{
auto
outRegion
=
OutputRegionCalculator
<
dimension
>
(
inIter
.
first
,
size
,
stride
,
outputSpatialSize
);
for
(
auto
j
:
outRegion
)
{
auto
inRegion
=
InputRegionCalculator
<
dimension
>
(
j
,
size
,
stride
);
u
Int
rulesOffset
=
inRegion
.
offset
(
inIter
.
first
);
Int
rulesOffset
=
inRegion
.
offset
(
inIter
.
first
);
auto
outIter
=
outputGrid
.
mp
.
find
(
j
);
if
(
outIter
==
outputGrid
.
mp
.
end
())
{
outIter
=
...
...
@@ -32,8 +33,8 @@ void Convolution_InputSgToRulesAndOutputSg(SparseGrid<dimension> &inputGrid,
}
}
template
<
u
Int
dimension
>
u
Int
Convolution_InputSgsToRulesAndOutputSgs
(
SparseGrids
<
dimension
>
&
input_SGs
,
template
<
Int
dimension
>
Int
Convolution_InputSgsToRulesAndOutputSgs
(
SparseGrids
<
dimension
>
&
input_SGs
,
SparseGrids
<
dimension
>
&
output_SGs
,
RuleBook
&
rules
,
long
*
filterSize
,
long
*
filterStride
,
...
...
@@ -41,10 +42,10 @@ uInt Convolution_InputSgsToRulesAndOutputSgs(SparseGrids<dimension> &input_SGs,
long
*
output_spatialSize
)
{
rules
.
clear
();
output_SGs
.
clear
();
u
Int
batchSize
=
input_SGs
.
size
();
Int
batchSize
=
input_SGs
.
size
();
output_SGs
.
resize
(
batchSize
);
u
Int
output_nActive
=
0
;
for
(
u
Int
i
=
0
;
i
<
batchSize
;
i
++
)
{
Int
output_nActive
=
0
;
for
(
Int
i
=
0
;
i
<
batchSize
;
i
++
)
{
auto
&
iSG
=
input_SGs
[
i
];
auto
&
oSG
=
output_SGs
[
i
];
oSG
.
ctr
=
output_nActive
;
...
...
@@ -57,43 +58,43 @@ uInt Convolution_InputSgsToRulesAndOutputSgs(SparseGrids<dimension> &input_SGs,
return
output_nActive
;
}
template
<
u
Int
dimension
>
u
Int
Convolution_InputSgsToRulesAndOutputSgs_OMP
(
template
<
Int
dimension
>
Int
Convolution_InputSgsToRulesAndOutputSgs_OMP
(
SparseGrids
<
dimension
>
&
input_SGs
,
SparseGrids
<
dimension
>
&
output_SGs
,
RuleBook
&
rules
,
long
*
filterSize
,
long
*
filterStride
,
long
*
input_spatialSize
,
long
*
output_spatialSize
)
{
rules
.
clear
();
rules
.
resize
(
volume
<
dimension
>
(
filterSize
));
output_SGs
.
clear
();
u
Int
batchSize
=
input_SGs
.
size
();
Int
batchSize
=
input_SGs
.
size
();
output_SGs
.
resize
(
batchSize
);
std
::
vector
<
RuleBook
>
rbs
(
batchSize
);
{
u
Int
i
;
Int
i
;
#pragma omp parallel for private(i)
for
(
i
=
0
;
i
<
batchSize
;
i
++
)
Convolution_InputSgToRulesAndOutputSg
<
dimension
>
(
input_SGs
[
i
],
output_SGs
[
i
],
rbs
[
i
],
filterSize
,
filterStride
,
input_spatialSize
,
output_spatialSize
);
}
u
Int
output_nActive
=
0
;
for
(
u
Int
i
=
0
;
i
<
batchSize
;
i
++
)
{
Int
output_nActive
=
0
;
for
(
Int
i
=
0
;
i
<
batchSize
;
i
++
)
{
// Parallel assignment:
// output_nActive <- output_nActive+output_SGs[i].ctr
// output_SGs[i].ctr <- output_nActive
u
Int
tmp
=
output_nActive
;
Int
tmp
=
output_nActive
;
output_nActive
+=
output_SGs
[
i
].
ctr
;
output_SGs
[
i
].
ctr
=
tmp
;
}
{
u
Int
i
;
Int
i
;
#pragma omp parallel for private(i)
for
(
i
=
0
;
i
<
rules
.
size
();
i
++
)
{
for
(
i
=
0
;
i
<
(
Int
)
rules
.
size
();
i
++
)
{
auto
&
R
=
rules
[
i
];
for
(
u
Int
j
=
0
;
j
<
batchSize
;
j
++
)
{
for
(
Int
j
=
0
;
j
<
batchSize
;
j
++
)
{
auto
&
r
=
rbs
[
j
][
i
];
auto
offset
=
output_SGs
[
j
].
ctr
;
for
(
u
Int
k
=
0
;
k
<
r
.
size
();)
{
for
(
Int
k
=
0
;
k
<
(
Int
)
r
.
size
();)
{
R
.
push_back
(
r
[
k
++
]);
R
.
push_back
(
r
[
k
++
]
+
offset
);
}
...
...
@@ -105,19 +106,19 @@ uInt Convolution_InputSgsToRulesAndOutputSgs_OMP(
// for each active site, list of (inputFeatureNumber,batchIdx, spatialOffset)
// triples
template
<
u
Int
dimension
>
template
<
Int
dimension
>
void
SparseToDense_InputSgsToRulesAndOutputSgs
(
SparseGrids
<
dimension
>
&
input_SGs
,
RuleBook
&
rules
,
long
*
spatialSize
)
{
u
Int
batchSize
=
input_SGs
.
size
();
Int
batchSize
=
input_SGs
.
size
();
rules
.
clear
();
rules
.
resize
(
batchSize
);
Point
<
dimension
>
lb
,
ub
;