"examples/git@developer.sourcefind.cn:OpenDAS/colossalai.git" did not exist on "36c4bb2893e73022b1060bd6ad5c0685869e5465"
Commit 6de372c3 authored by Benjamin Thomas Graham's avatar Benjamin Thomas Graham
Browse files

add batch information to getSpatialLocations

parent 96addd52
...@@ -63,9 +63,7 @@ extern "C" void scn_D_(setInputSpatialLocations)(void **m, ...@@ -63,9 +63,7 @@ extern "C" void scn_D_(setInputSpatialLocations)(void **m,
assert((locations->size[1] == Dimension or assert((locations->size[1] == Dimension or
locations->size[1] == 1 + Dimension) and locations->size[1] == 1 + Dimension) and
"locations.size(0) must be either Dimension or Dimension+1"); "locations.size(0) must be either Dimension or Dimension+1");
SCN_INITIALIZE_AND_REFERENCE(Metadata<Dimension>, m) SCN_INITIALIZE_AND_REFERENCE(Metadata<Dimension>, m)
Point<Dimension> p; Point<Dimension> p;
auto &nActive = *_m.inputNActive; auto &nActive = *_m.inputNActive;
auto nPlanes = vecs->size[1]; auto nPlanes = vecs->size[1];
...@@ -73,7 +71,8 @@ extern "C" void scn_D_(setInputSpatialLocations)(void **m, ...@@ -73,7 +71,8 @@ extern "C" void scn_D_(setInputSpatialLocations)(void **m,
auto v = THFloatTensor_data(vecs); auto v = THFloatTensor_data(vecs);
if (locations->size[1] == Dimension) { if (locations->size[1] == Dimension) {
assert(_m.inputSG); // add points to current sample // add points to current sample
assert(_m.inputSG);
auto &mp = _m.inputSG->mp; auto &mp = _m.inputSG->mp;
for (uInt idx = 0; idx < locations->size[0]; ++idx) { for (uInt idx = 0; idx < locations->size[0]; ++idx) {
for (int d = 0; d < Dimension; ++d) for (int d = 0; d < Dimension; ++d)
...@@ -101,9 +100,9 @@ extern "C" void scn_D_(setInputSpatialLocations)(void **m, ...@@ -101,9 +100,9 @@ extern "C" void scn_D_(setInputSpatialLocations)(void **m,
} }
} }
extern "C" void scn_D_(getSpatialLocations)(void **m, extern "C" void scn_D_(getSpatialLocations)(void **m, THLongTensor *spatialSize,
THLongTensor *spatialSize, THLongTensor *locations,
THLongTensor *locations) { THLongTensor *batchIdxs) {
SCN_INITIALIZE_AND_REFERENCE(Metadata<Dimension>, m) SCN_INITIALIZE_AND_REFERENCE(Metadata<Dimension>, m)
uInt nActive = _m.getNActive(spatialSize); uInt nActive = _m.getNActive(spatialSize);
auto &SGs = _m.getSparseGrid(spatialSize); auto &SGs = _m.getSparseGrid(spatialSize);
...@@ -125,9 +124,9 @@ extern "C" void scn_D_(getSpatialLocations)(void **m, ...@@ -125,9 +124,9 @@ extern "C" void scn_D_(getSpatialLocations)(void **m,
} }
} }
extern "C" void extern "C" void
scn_D_(createMetadataForDenseToSparse)(void **m, THLongTensor *spatialSize_, scn_D_(createMetadataForDenseToSparse)(void **m, THLongTensor *spatialSize_,
THLongTensor *pad_, THLongTensor *pad_, THLongTensor *nz_,
THLongTensor *nz_, long batchSize) { long batchSize) {
SCN_INITIALIZE_AND_REFERENCE(Metadata<Dimension>, m) SCN_INITIALIZE_AND_REFERENCE(Metadata<Dimension>, m)
_m.setInputSpatialSize(spatialSize_); _m.setInputSpatialSize(spatialSize_);
_m.inputSGs->resize(batchSize); _m.inputSGs->resize(batchSize);
......
This diff is collapsed.
This diff is collapsed.
...@@ -33,7 +33,25 @@ class InputBatch(SparseConvNetTensor): ...@@ -33,7 +33,25 @@ class InputBatch(SparseConvNetTensor):
self.metadata.ffi, self.features, location, vector, overwrite) self.metadata.ffi, self.features, location, vector, overwrite)
def setLocations(self, locations, vectors, overwrite=False): def setLocations(self, locations, vectors, overwrite=False):
l =locations.narrow(1,0,self.dimension) """
To set n locations in d dimensions, locations can be
- A size (n,d) LongTensor, giving d-dimensional coordinates -- points
are added to the current sample, or
- A size (n,d+1) LongTensor; the extra column specifies the sample
number (within the minibatch of samples).
Example with d=3 and n=2:
Set
locations = LongTensor([[1,2,3],
[4,5,6]])
to add points to the current sample at (1,2,3) and (4,5,6).
Set
locations = LongTensor([[1,2,3,7],
[4,5,6,9]])
to add point (1,2,3) to sample 7, and (4,5,6) to sample 9 (0-indexed).
"""
l = locations.narrow(1,0,self.dimension)
assert l.min() >= 0 and (self.spatial_size.expand_as(l) - l).min() > 0 assert l.min() >= 0 and (self.spatial_size.expand_as(l) - l).min() > 0
dim_fn(self.dimension, 'setInputSpatialLocations')( dim_fn(self.dimension, 'setInputSpatialLocations')(
self.metadata.ffi, self.features, locations, vectors, overwrite) self.metadata.ffi, self.features, locations, vectors, overwrite)
......
...@@ -25,35 +25,33 @@ return function (sparseconvnet) ...@@ -25,35 +25,33 @@ return function (sparseconvnet)
end end
cdef = [[ cdef = [[
void scn_ptrCopyA(long *dst, void **src); void scn_ptrCopyA(long *dst, void **src);
void scn_ptrCopyB(void **dst, long *src); void scn_ptrCopyB(void **dst, long *src);
double scn_ruleBookBits(); double scn_ruleBookBits();
void scn_2_drawCurve(void **m, THFloatTensor *features, THFloatTensor *stroke); void scn_2_drawCurve(void **m, THFloatTensor *features, THFloatTensor *stroke);
]] ]]
if fc then fc:write(cdef) end if fc then fc:write(cdef) end
ffi.cdef(cdef) ffi.cdef(cdef)
sparseconvnet.ruleBookBits=F['scn_ruleBookBits']() sparseconvnet.ruleBookBits=F['scn_ruleBookBits']()
cdef = [[ cdef = [[
double scn_DIMENSION_addSampleFromThresholdedTensor( double scn_DIMENSION_addSampleFromThresholdedTensor(
void **m, THFloatTensor *features_, THFloatTensor *tensor_, void **m, THFloatTensor *features_, THFloatTensor *tensor_,
THLongTensor *offset_, THLongTensor *spatialSize_, float threshold); THLongTensor *offset_, THLongTensor *spatialSize_, float threshold);
void scn_DIMENSION_batchAddSample(void **m); void scn_DIMENSION_batchAddSample(void **m);
void scn_DIMENSION_createMetadataForDenseToSparse( void scn_DIMENSION_createMetadataForDenseToSparse(
void **m, THLongTensor *spatialSize_, THLongTensor *pad, THLongTensor *nz, void **m, THLongTensor *spatialSize_, THLongTensor *pad, THLongTensor *nz,
long batchSize); long batchSize);
void scn_DIMENSION_freeMetadata(void **metadata); void scn_DIMENSION_freeMetadata(void **metadata);
void scn_DIMENSION_generateRuleBooks3s2(void **m); void scn_DIMENSION_generateRuleBooks3s2(void **m);
void scn_DIMENSION_generateRuleBooks2s2(void **m); void scn_DIMENSION_generateRuleBooks2s2(void **m);
void scn_DIMENSION_setInputSpatialSize(void **m, THLongTensor *spatialSize); void scn_DIMENSION_setInputSpatialSize(void **m, THLongTensor *spatialSize);
void scn_DIMENSION_setInputSpatialLocation(void **m, void scn_DIMENSION_setInputSpatialLocation(void **m, THFloatTensor *features,
THFloatTensor *features, THLongTensor *location, THFloatTensor *vec, THLongTensor *location, THFloatTensor *vec, bool overwrite);
bool overwrite); void scn_DIMENSION_setInputSpatialLocations(void **m, THFloatTensor *features,
void scn_5_getSpatialLocations(void **m, THLongTensor *locations, THFloatTensor *vecs, bool overwrite);
THLongTensor *spatialSize, THLongTensor *locations); void scn_DIMENSION_getSpatialLocations(void **m, THLongTensor *spatialSize,
void scn_DIMENSION_setInputSpatialLocations(void **m, THLongTensor *locations);
THFloatTensor *features, THLongTensor *locations, THFloatTensor *vecs,
bool overwrite);
]] ]]
for DIMENSION = 1,10 do for DIMENSION = 1,10 do
...@@ -66,60 +64,60 @@ return function (sparseconvnet) ...@@ -66,60 +64,60 @@ return function (sparseconvnet)
--type GPU half, float, double; int_cpu and int_gpu --type GPU half, float, double; int_cpu and int_gpu
cdef = [[ cdef = [[
void scn_ARCH_REAL_AffineReluTrivialConvolution_updateOutput( void scn_ARCH_REAL_AffineReluTrivialConvolution_updateOutput(
THTensor *input_features, THTensor *output_features, THTensor *input_features, THTensor *output_features,
THTensor *affineWeight, THTensor *affineBias, THTensor *convWeight); THTensor *affineWeight, THTensor *affineBias, THTensor *convWeight);
void scn_ARCH_REAL_AffineReluTrivialConvolution_backward( void scn_ARCH_REAL_AffineReluTrivialConvolution_backward(
THTensor *input_features, THTensor *d_input_features, THTensor *input_features, THTensor *d_input_features,
THTensor *d_output_features, THTensor *affineWeight, THTensor *d_output_features, THTensor *affineWeight,
THTensor *d_affineWeight, THTensor *affineBias, THTensor *d_affineBias, THTensor *d_affineWeight, THTensor *affineBias, THTensor *d_affineBias,
THTensor *convWeight, THTensor *d_convWeight, bool additiveGrad); THTensor *convWeight, THTensor *d_convWeight, bool additiveGrad);
// BatchwiseMultiplicativeDropout // BatchwiseMultiplicativeDropout
void scn_ARCH_REAL_BatchwiseMultiplicativeDropout_updateOutput( void scn_ARCH_REAL_BatchwiseMultiplicativeDropout_updateOutput(
THTensor *input_features, THTensor *output_features, THTensor *input_features, THTensor *output_features,
THTensor *noise, long nPlanes, long input_stride, long output_stride, THTensor *noise, long nPlanes, long input_stride, long output_stride,
float alpha); float alpha);
void scn_ARCH_REAL_BatchwiseMultiplicativeDropout_updateGradInput( void scn_ARCH_REAL_BatchwiseMultiplicativeDropout_updateGradInput(
THTensor *input_features, THTensor *d_input_features, THTensor *input_features, THTensor *d_input_features,
THTensor *d_output_features, THTensor *noise, long nPlanes, THTensor *d_output_features, THTensor *noise, long nPlanes,
long input_stride, long output_stride, float alpha); long input_stride, long output_stride, float alpha);
// BatchNormalization // BatchNormalization
void scn_ARCH_REAL_BatchNormalization_updateOutput( void scn_ARCH_REAL_BatchNormalization_updateOutput(
THTensor *input_features, THTensor *output_features, THTensor *input_features, THTensor *output_features,
THTensor *saveMean, THTensor *saveInvStd, THTensor *runningMean, THTensor *saveMean, THTensor *saveInvStd, THTensor *runningMean,
THTensor *runningVar, THTensor *weight, THTensor *bias, REAL eps, THTensor *runningVar, THTensor *weight, THTensor *bias, REAL eps,
REAL momentum, bool train, REAL leakiness); REAL momentum, bool train, REAL leakiness);
void scn_ARCH_REAL_BatchNormalization_backward( void scn_ARCH_REAL_BatchNormalization_backward(
THTensor *input_features, THTensor *d_input_features, THTensor *input_features, THTensor *d_input_features,
THTensor *output_features, THTensor *d_output_features, THTensor *saveMean, THTensor *output_features, THTensor *d_output_features, THTensor *saveMean,
THTensor *saveInvStd, THTensor *runningMean, THTensor *runningVar, THTensor *saveInvStd, THTensor *runningMean, THTensor *runningVar,
THTensor *weight, THTensor *bias, THTensor *d_weight, THTensor *d_bias, THTensor *weight, THTensor *bias, THTensor *d_weight, THTensor *d_bias,
REAL leakiness); REAL leakiness);
// BatchNormalizationInTensor // BatchNormalizationInTensor
void scn_ARCH_REAL_BatchNormalizationInTensor_updateOutput( void scn_ARCH_REAL_BatchNormalizationInTensor_updateOutput(
THTensor *input_features, THTensor *output_features, THTensor *input_features, THTensor *output_features,
THTensor *saveMean, THTensor *saveInvStd, THTensor *runningMean, THTensor *saveMean, THTensor *saveInvStd, THTensor *runningMean,
THTensor *runningVar, THTensor *weight, THTensor *bias, REAL eps, THTensor *runningVar, THTensor *weight, THTensor *bias, REAL eps,
REAL momentum, bool train, REAL leakiness); REAL momentum, bool train, REAL leakiness);
// LeakyReLU // LeakyReLU
void scn_ARCH_REAL_LeakyReLU_updateOutput( void scn_ARCH_REAL_LeakyReLU_updateOutput(
THTensor *input_features, THTensor *output_features, long n, THTensor *input_features, THTensor *output_features, long n,
float alpha); float alpha);
void scn_ARCH_REAL_LeakyReLU_updateGradInput( void scn_ARCH_REAL_LeakyReLU_updateGradInput(
THTensor *input_features, THTensor *d_input_features, THTensor *input_features, THTensor *d_input_features,
THTensor *d_output_features, long n, float alpha); THTensor *d_output_features, long n, float alpha);
// NetworkInNetwork // NetworkInNetwork
double scn_ARCH_REAL_NetworkInNetwork_updateOutput( double scn_ARCH_REAL_NetworkInNetwork_updateOutput(
THTensor *input_features, THTensor *output_features, THTensor *input_features, THTensor *output_features,
THTensor *weight, THTensor *bias); THTensor *weight, THTensor *bias);
void scn_ARCH_REAL_NetworkInNetwork_updateGradInput( void scn_ARCH_REAL_NetworkInNetwork_updateGradInput(
THTensor *d_input_features, THTensor *d_output_features, THTensor *d_input_features, THTensor *d_output_features,
THTensor *weight); THTensor *weight);
void scn_ARCH_REAL_NetworkInNetwork_accGradParameters( void scn_ARCH_REAL_NetworkInNetwork_accGradParameters(
THTensor *input_features, THTensor *d_output_features, THTensor *input_features, THTensor *d_output_features,
THTensor *d_weight, THTensor *d_bias); THTensor *d_weight, THTensor *d_bias);
]] ]]
...@@ -149,79 +147,79 @@ return function (sparseconvnet) ...@@ -149,79 +147,79 @@ return function (sparseconvnet)
end end
cdef = [[ cdef = [[
// ActivePooling // ActivePooling
void scn_ARCH_REAL_DIMENSIONActivePooling_updateOutput( void scn_ARCH_REAL_DIMENSIONActivePooling_updateOutput(
THLongTensor *inputSize, void **m, THTensor *input_features, THLongTensor *inputSize, void **m, THTensor *input_features,
THTensor *output_features, THITensor *rulesBuffer, bool average); THTensor *output_features, THITensor *rulesBuffer, bool average);
void scn_ARCH_REAL_DIMENSIONActivePooling_updateGradInput( void scn_ARCH_REAL_DIMENSIONActivePooling_updateGradInput(
THLongTensor *inputSize, void **m, THLongTensor *inputSize, void **m,
THTensor *d_input_features, THTensor *d_output_features, THTensor *d_input_features, THTensor *d_output_features,
THITensor *rulesBuffer, bool average); THITensor *rulesBuffer, bool average);
// Average Pooling // Average Pooling
void scn_ARCH_REAL_DIMENSIONAveragePooling_updateOutput( void scn_ARCH_REAL_DIMENSIONAveragePooling_updateOutput(
THLongTensor *inputSize, THLongTensor *outputSize, THLongTensor *inputSize, THLongTensor *outputSize,
THLongTensor *poolSize, THLongTensor *poolStride, void **m, THLongTensor *poolSize, THLongTensor *poolStride, void **m,
THTensor *input_features, THTensor *output_features, long nFeaturesToDrop, THTensor *input_features, THTensor *output_features, long nFeaturesToDrop,
THITensor *rulesBuffer); THITensor *rulesBuffer);
void scn_ARCH_REAL_DIMENSIONAveragePooling_updateGradInput( void scn_ARCH_REAL_DIMENSIONAveragePooling_updateGradInput(
THLongTensor * inputSize, THLongTensor * outputSize, THLongTensor * inputSize, THLongTensor * outputSize,
THLongTensor * poolSize, THLongTensor * poolStride, void **m, THLongTensor * poolSize, THLongTensor * poolStride, void **m,
THTensor *input_features, THTensor *d_input_features, THTensor *input_features, THTensor *d_input_features,
THTensor *d_output_features, long nFeaturesToDrop, THTensor *d_output_features, long nFeaturesToDrop,
THITensor *rulesBuffer); THITensor *rulesBuffer);
double scn_ARCH_REAL_DIMENSIONConvolution_updateOutput( double scn_ARCH_REAL_DIMENSIONConvolution_updateOutput(
THLongTensor *inputSize, THLongTensor *outputSize, THLongTensor *inputSize, THLongTensor *outputSize,
THLongTensor *filterSize, THLongTensor *filterStride, void **m, THLongTensor *filterSize, THLongTensor *filterStride, void **m,
THTensor *input_features, THTensor *output_features, THTensor *weight, THTensor *input_features, THTensor *output_features, THTensor *weight,
THTensor *bias, long filterVolume, THITensor *rulesBuffer); THTensor *bias, long filterVolume, THITensor *rulesBuffer);
void scn_ARCH_REAL_DIMENSIONConvolution_backward( void scn_ARCH_REAL_DIMENSIONConvolution_backward(
THLongTensor *inputSize, THLongTensor *outputSize, THLongTensor *inputSize, THLongTensor *outputSize,
THLongTensor *filterSize, THLongTensor *filterStride, void **m, THLongTensor *filterSize, THLongTensor *filterStride, void **m,
THTensor *input_features, THTensor *d_input_features, THTensor *input_features, THTensor *d_input_features,
THTensor *d_output_features, THTensor *weight, THTensor *d_weight, THTensor *d_output_features, THTensor *weight, THTensor *d_weight,
THTensor *d_bias, long filterVolume, THITensor *rulesBuffer); THTensor *d_bias, long filterVolume, THITensor *rulesBuffer);
double scn_ARCH_REAL_DIMENSIONDeconvolution_updateOutput( double scn_ARCH_REAL_DIMENSIONDeconvolution_updateOutput(
THLongTensor *inputSize, THLongTensor *outputSize, THLongTensor *inputSize, THLongTensor *outputSize,
THLongTensor *filterSize, THLongTensor *filterStride, void **m, THLongTensor *filterSize, THLongTensor *filterStride, void **m,
THTensor *input_features, THTensor *output_features, THTensor *weight, THTensor *input_features, THTensor *output_features, THTensor *weight,
THTensor *bias, long filterVolume, THITensor *rulesBuffer); THTensor *bias, long filterVolume, THITensor *rulesBuffer);
void scn_ARCH_REAL_DIMENSIONDeconvolution_backward( void scn_ARCH_REAL_DIMENSIONDeconvolution_backward(
THLongTensor *inputSize, THLongTensor *outputSize, THLongTensor *inputSize, THLongTensor *outputSize,
THLongTensor *filterSize, THLongTensor *filterStride, void **m, THLongTensor *filterSize, THLongTensor *filterStride, void **m,
THTensor *input_features, THTensor *d_input_features, THTensor *input_features, THTensor *d_input_features,
THTensor *d_output_features, THTensor *weight, THTensor *d_weight, THTensor *d_output_features, THTensor *weight, THTensor *d_weight,
THTensor *d_bias, long filterVolume, THITensor *rulesBuffer); THTensor *d_bias, long filterVolume, THITensor *rulesBuffer);
// Max Pooling // Max Pooling
void scn_ARCH_REAL_DIMENSIONMaxPooling_updateOutput( void scn_ARCH_REAL_DIMENSIONMaxPooling_updateOutput(
THLongTensor *inputSize, THLongTensor *outputSize, THLongTensor *inputSize, THLongTensor *outputSize,
THLongTensor *poolSize, THLongTensor *poolStride, void **m, THLongTensor *poolSize, THLongTensor *poolStride, void **m,
THTensor *input_features, THTensor *output_features, long nFeaturesToDrop, THTensor *input_features, THTensor *output_features, long nFeaturesToDrop,
THITensor *rulesBuffer); THITensor *rulesBuffer);
void scn_ARCH_REAL_DIMENSIONMaxPooling_updateGradInput( void scn_ARCH_REAL_DIMENSIONMaxPooling_updateGradInput(
THLongTensor * inputSize, THLongTensor * outputSize, THLongTensor * inputSize, THLongTensor * outputSize,
THLongTensor * poolSize, THLongTensor * poolStride, void **m, THLongTensor * poolSize, THLongTensor * poolStride, void **m,
THTensor *input_features, THTensor *d_input_features, THTensor *input_features, THTensor *d_input_features,
THTensor *output_features, THTensor *d_output_features, THTensor *output_features, THTensor *d_output_features,
long nFeaturesToDrop, THITensor *rulesBuffer); long nFeaturesToDrop, THITensor *rulesBuffer);
// SparseToDense // SparseToDense
void scn_ARCH_REAL_DIMENSIONSparseToDense_updateOutput( void scn_ARCH_REAL_DIMENSIONSparseToDense_updateOutput(
THLongTensor *inputSize, void **m, THTensor *input_features, THLongTensor *inputSize, void **m, THTensor *input_features,
THTensor *output_features, THITensor *rulesBuffer); THTensor *output_features, THITensor *rulesBuffer);
void scn_ARCH_REAL_DIMENSIONSparseToDense_updateGradInput( void scn_ARCH_REAL_DIMENSIONSparseToDense_updateGradInput(
THLongTensor *inputSize, void **m, THTensor *input_features, THLongTensor *inputSize, void **m, THTensor *input_features,
THTensor *d_input_features, THTensor *d_output_features, THTensor *d_input_features, THTensor *d_output_features,
THITensor *rulesBuffer); THITensor *rulesBuffer);
double scn_ARCH_REAL_DIMENSIONValidConvolution_updateOutput( double scn_ARCH_REAL_DIMENSIONValidConvolution_updateOutput(
THLongTensor *inputSize, THLongTensor *filterSize, void **m, THLongTensor *inputSize, THLongTensor *filterSize, void **m,
THTensor *input_features, THTensor *output_features, THTensor *weight, THTensor *input_features, THTensor *output_features, THTensor *weight,
THTensor *bias, long filterVolume, THITensor *rulesBuffer); THTensor *bias, long filterVolume, THITensor *rulesBuffer);
void scn_ARCH_REAL_DIMENSIONValidConvolution_backward( void scn_ARCH_REAL_DIMENSIONValidConvolution_backward(
THLongTensor *inputSize, THLongTensor *filterSize, void **m, THLongTensor *inputSize, THLongTensor *filterSize, void **m,
THTensor *input_features, THTensor *d_input_features, THTensor *input_features, THTensor *d_input_features,
THTensor *d_output_features, THTensor *weight, THTensor *d_weight, THTensor *d_output_features, THTensor *weight, THTensor *d_weight,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment