Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion paddle/phi/kernels/cpu/segment_pool_grad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ PD_REGISTER_KERNEL(segment_pool_grad,
ALL_LAYOUT,
phi::SegmentPoolGradKernel,
float,
double) {}
double,
int,
int64_t) {}
10 changes: 8 additions & 2 deletions paddle/phi/kernels/cpu/segment_pool_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"

PD_REGISTER_KERNEL(
segment_pool, CPU, ALL_LAYOUT, phi::SegmentPoolKernel, float, double) {}
PD_REGISTER_KERNEL(segment_pool,
CPU,
ALL_LAYOUT,
phi::SegmentPoolKernel,
float,
double,
int,
int64_t) {}
9 changes: 9 additions & 0 deletions paddle/phi/kernels/funcs/segment_pooling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,19 @@ template class SegmentPoolFunctor<CPU, float, int>;
template class SegmentPoolFunctor<CPU, float, int64_t>;
template class SegmentPoolFunctor<CPU, double, int>;
template class SegmentPoolFunctor<CPU, double, int64_t>;
template class SegmentPoolFunctor<CPU, int, int>;
template class SegmentPoolFunctor<CPU, int, int64_t>;
template class SegmentPoolFunctor<CPU, int64_t, int>;
template class SegmentPoolFunctor<CPU, int64_t, int64_t>;

template class SegmentPoolGradFunctor<CPU, float, int>;
template class SegmentPoolGradFunctor<CPU, float, int64_t>;
template class SegmentPoolGradFunctor<CPU, double, int>;
template class SegmentPoolGradFunctor<CPU, double, int64_t>;
template class SegmentPoolGradFunctor<CPU, int, int>;
template class SegmentPoolGradFunctor<CPU, int, int64_t>;
template class SegmentPoolGradFunctor<CPU, int64_t, int>;
template class SegmentPoolGradFunctor<CPU, int64_t, int64_t>;

} // namespace funcs
} // namespace phi
9 changes: 9 additions & 0 deletions paddle/phi/kernels/funcs/segment_pooling.cu
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,19 @@ template class SegmentPoolFunctor<GPU, float, int>;
template class SegmentPoolFunctor<GPU, float, int64_t>;
template class SegmentPoolFunctor<GPU, double, int>;
template class SegmentPoolFunctor<GPU, double, int64_t>;
template class SegmentPoolFunctor<GPU, int, int>;
template class SegmentPoolFunctor<GPU, int, int64_t>;
template class SegmentPoolFunctor<GPU, int64_t, int>;
template class SegmentPoolFunctor<GPU, int64_t, int64_t>;

template class SegmentPoolGradFunctor<GPU, float, int>;
template class SegmentPoolGradFunctor<GPU, float, int64_t>;
template class SegmentPoolGradFunctor<GPU, double, int>;
template class SegmentPoolGradFunctor<GPU, double, int64_t>;
template class SegmentPoolGradFunctor<GPU, int, int>;
template class SegmentPoolGradFunctor<GPU, int, int64_t>;
template class SegmentPoolGradFunctor<GPU, int64_t, int>;
template class SegmentPoolGradFunctor<GPU, int64_t, int64_t>;

} // namespace funcs
} // namespace phi
4 changes: 3 additions & 1 deletion paddle/phi/kernels/gpu/segment_pool_grad_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ PD_REGISTER_KERNEL(segment_pool_grad,
ALL_LAYOUT,
phi::SegmentPoolGradKernel,
float,
double) {}
double,
int,
int64_t) {}
10 changes: 8 additions & 2 deletions paddle/phi/kernels/gpu/segment_pool_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/kernel_registry.h"

PD_REGISTER_KERNEL(
segment_pool, GPU, ALL_LAYOUT, phi::SegmentPoolKernel, float, double) {}
PD_REGISTER_KERNEL(segment_pool,
GPU,
ALL_LAYOUT,
phi::SegmentPoolKernel,
float,
double,
int,
int64_t) {}
20 changes: 12 additions & 8 deletions python/paddle/incubate/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def segment_sum(data, segment_ids, name=None):
where sum is over j such that `segment_ids[j] == i`.

Args:
data (Tensor): A tensor, available data type float32, float64.
data (Tensor): A tensor, available data type float32, float64, int32, int64.
segment_ids (Tensor): A 1-D tensor, which have the same size
with the first dimension of input data.
Available data type is int32, int64.
Expand All @@ -54,7 +54,8 @@ def segment_sum(data, segment_ids, name=None):
out, tmp = _C_ops.segment_pool(data, segment_ids, 'pooltype', "SUM")
return out

check_variable_and_dtype(data, "X", ("float32", "float64"), "segment_pool")
check_variable_and_dtype(data, "X", ("float32", "float64", "int32",
"int64"), "segment_pool")
check_variable_and_dtype(segment_ids, "SegmentIds", ("int32", "int64"),
"segment_pool")

Expand Down Expand Up @@ -82,7 +83,7 @@ def segment_mean(data, segment_ids, name=None):
of all index 'segment_ids[j] == i'.

Args:
data (tensor): a tensor, available data type float32, float64.
data (tensor): a tensor, available data type float32, float64, int32, int64.
segment_ids (tensor): a 1-d tensor, which have the same size
with the first dimension of input data.
available data type is int32, int64.
Expand All @@ -107,7 +108,8 @@ def segment_mean(data, segment_ids, name=None):
out, tmp = _C_ops.segment_pool(data, segment_ids, 'pooltype', "MEAN")
return out

check_variable_and_dtype(data, "X", ("float32", "float64"), "segment_pool")
check_variable_and_dtype(data, "X", ("float32", "float64", "int32",
"int64"), "segment_pool")
check_variable_and_dtype(segment_ids, "SegmentIds", ("int32", "int64"),
"segment_pool")

Expand All @@ -134,7 +136,7 @@ def segment_min(data, segment_ids, name=None):
where min is over j such that `segment_ids[j] == i`.

Args:
data (tensor): a tensor, available data type float32, float64.
data (tensor): a tensor, available data type float32, float64, int32, int64.
segment_ids (tensor): a 1-d tensor, which have the same size
with the first dimension of input data.
available data type is int32, int64.
Expand All @@ -159,7 +161,8 @@ def segment_min(data, segment_ids, name=None):
out, tmp = _C_ops.segment_pool(data, segment_ids, 'pooltype', "MIN")
return out

check_variable_and_dtype(data, "X", ("float32", "float64"), "segment_pool")
check_variable_and_dtype(data, "X", ("float32", "float64", "int32",
"int64"), "segment_pool")
check_variable_and_dtype(segment_ids, "SegmentIds", ("int32", "int64"),
"segment_pool")

Expand All @@ -186,7 +189,7 @@ def segment_max(data, segment_ids, name=None):
where max is over j such that `segment_ids[j] == i`.

Args:
data (tensor): a tensor, available data type float32, float64.
data (tensor): a tensor, available data type float32, float64, int32, int64.
segment_ids (tensor): a 1-d tensor, which have the same size
with the first dimension of input data.
available data type is int32, int64.
Expand All @@ -211,7 +214,8 @@ def segment_max(data, segment_ids, name=None):
out, tmp = _C_ops.segment_pool(data, segment_ids, 'pooltype', "MAX")
return out

check_variable_and_dtype(data, "X", ("float32", "float64"), "segment_pool")
check_variable_and_dtype(data, "X", ("float32", "float64", "int32",
"int64"), "segment_pool")
check_variable_and_dtype(segment_ids, "SegmentIds", ("int32", "int64"),
"segment_pool")

Expand Down