From 0f5cee2f6b5ec2687476eee671d62cb94b9a7661 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Wed, 24 Oct 2018 13:45:58 -0700 Subject: [PATCH] Convert some docstrings from char* to char[] (#13062) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/13062 Gold (the linker) isn't able to gc unreferenced string constants, but converting these to arrays puts them in their own data sections and reduces (Android) binary size as a result. I'm told even in server builds, this reduces binary size by a few dozen bytes and speeds up startup by a few hundred ns. :-P Reviewed By: Yangqing Differential Revision: D10510808 fbshipit-source-id: 247ba9574e7a9b6a8204d33052994b08c401c197 --- caffe2/operators/conv_op.cc | 2 +- caffe2/operators/elementwise_ops_schema.cc | 28 +++++++++++----------- caffe2/operators/pool_op.cc | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/caffe2/operators/conv_op.cc b/caffe2/operators/conv_op.cc index 86069eaa7a39f..bbde395689d0a 100644 --- a/caffe2/operators/conv_op.cc +++ b/caffe2/operators/conv_op.cc @@ -4,7 +4,7 @@ namespace caffe2 { -const char* kConvDoc = R"DOC( +const char kConvDoc[] = R"DOC( The Conv2D operator computes a 2D convolution operation over an input blob $(X)$, with a filter blob $(filter)$ and a bias blob $(bias)$, and outputs a single output blob $(Y)$. Although there are several options for order, the convention is that the input $(X)$ is a blob of shape $(N,C_{in},H_{in},W_{in})$ and the output $(Y)$ is a blob of shape $(N,C_{out},H_{out},W_{out})$. Here, $N$ is the batch size, $C$ is the number of channels, $H$ is the spatial height, and $W$ is the spatial width. For example, if your input data was a batch of five, 100x120pixel RGB images, $X$ would have shape $(5,3,120,100)$. The $filter$ input blob may contain multiple filters and has shape $(M, C_{in}, K_H, K_W)$. Here, $M$ is the number of individual filters contained in the blob, $C_{in}$ is the number of channels of each filter (by convention in 2D convolution it is the same as the number of channels in the input), $K_H$ is the spatial height of the kernel, and $K_W$ is the spatial width of the kernel. The $bias$ blob is a vector of length $M$, where there is one bias for each filter in the $filter$ blob. diff --git a/caffe2/operators/elementwise_ops_schema.cc b/caffe2/operators/elementwise_ops_schema.cc index ec84b9afde576..b6bebaa48be4b 100644 --- a/caffe2/operators/elementwise_ops_schema.cc +++ b/caffe2/operators/elementwise_ops_schema.cc @@ -7,7 +7,7 @@ namespace caffe2 { namespace { -const char* kBroadcastDoc = R"DOC( +const char kBroadcastDoc[] = R"DOC( If necessary the right-hand-side argument will be broadcasted to match the shape of left-hand-side argument. When broadcasting is specified, the second tensor can either be of size 1 (a scalar value), or having its shape as a @@ -31,7 +31,7 @@ Github Links: )DOC"; -const char* kAddExample = R"DOC( +const char kAddExample[] = R"DOC(
Example @@ -77,7 +77,7 @@ print("C:", workspace.FetchBlob("C")) )DOC"; -const char* kSubExample = R"DOC( +const char kSubExample[] = R"DOC(
Example @@ -123,7 +123,7 @@ print("C:", workspace.FetchBlob("C")) )DOC"; -const char* kMulExample = R"DOC( +const char kMulExample[] = R"DOC(
Example @@ -169,7 +169,7 @@ print("C:", workspace.FetchBlob("C")) )DOC"; -const char* kDivExample = R"DOC( +const char kDivExample[] = R"DOC(
Example @@ -357,7 +357,7 @@ For example, the following tensor shapes are supported: "If broadcasting is disabled it should be of the same size.") .Output(0, "C", "Result, has same dimensions and type as B"); -const char* kLTExample = R"DOC( +const char kLTExample[] = R"DOC(
Example @@ -396,7 +396,7 @@ C: [False False True False False True]
)DOC"; -const char* kLEExample = R"DOC( +const char kLEExample[] = R"DOC(
Example @@ -435,7 +435,7 @@ C: [ True False True True True True]
)DOC"; -const char* kGTExample = R"DOC( +const char kGTExample[] = R"DOC(
Example @@ -474,7 +474,7 @@ C: [False True False False False False]
)DOC"; -const char* kGEExample = R"DOC( +const char kGEExample[] = R"DOC(
Example @@ -513,7 +513,7 @@ C: [ True True False True True False]
)DOC"; -const char* kEQExample = R"DOC( +const char kEQExample[] = R"DOC(
Example @@ -550,7 +550,7 @@ C: [ True False False True True False]
)DOC"; -const char* kNEExample = R"DOC( +const char kNEExample[] = R"DOC(
Example @@ -650,7 +650,7 @@ CAFFE2_SCHEMA_FOR_BINARY_COMPARISON_OP(LE, "<=", "less or equal than", kLEExampl CAFFE2_SCHEMA_FOR_BINARY_COMPARISON_OP(GT, ">", "greater than", kGTExample); CAFFE2_SCHEMA_FOR_BINARY_COMPARISON_OP(GE, ">=", "greater or equal than", kGEExample); -const char* kAndExample = R"DOC( +const char kAndExample[] = R"DOC(
Example @@ -698,7 +698,7 @@ print("C:", workspace.FetchBlob("C"))
)DOC"; -const char* kOrExample = R"DOC( +const char kOrExample[] = R"DOC(
Example @@ -746,7 +746,7 @@ print("C:", workspace.FetchBlob("C"))
)DOC"; -const char* kXorExample = R"DOC( +const char kXorExample[] = R"DOC(
Example diff --git a/caffe2/operators/pool_op.cc b/caffe2/operators/pool_op.cc index 8b870f46c4842..84e054f8b712c 100644 --- a/caffe2/operators/pool_op.cc +++ b/caffe2/operators/pool_op.cc @@ -728,7 +728,7 @@ bool PoolOp::RunOnDeviceWithOrderNHWC() { } return true; } -const char* kAveragePoolDoc = R"DOC( +const char kAveragePoolDoc[] = R"DOC( consumes an input blob and applies average pooling across the the blob according to kernel sizes, stride sizes, pad lengths and dilation. Average pooling consists of taking the average value of a subset of the input tensor according to the kernel @@ -797,7 +797,7 @@ print("Y:\n", workspace.FetchBlob("Y")) )DOC"; -const char* kMaxPoolDoc = R"DOC( +const char kMaxPoolDoc[] = R"DOC( consumes an input blob and applies max pooling across the the blob according to kernel sizes, stride sizes, pad lengths and dilation. Max pooling consists of taking the maximum value of a subset of the input tensor according to the kernel