Skip to content

Commit f626218

Browse files
philipNoonanfmassa
authored andcommitted
Enabling exporting symbols on windows (#1035)
* Enabling exporting symbols on windows Small fix to allow for the built library to be used in windows #728 * added macro to allow for exported symbols on windows * added macro to allow for exported symbols on windows * removed cmake command * added dllimport using torchvision_EXPORTS preprocessor
1 parent c94a158 commit f626218

File tree

10 files changed

+71
-48
lines changed

10 files changed

+71
-48
lines changed

torchvision/csrc/models/alexnet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#define ALEXNET_H
33

44
#include <torch/torch.h>
5+
#include "general.h"
56

67
namespace vision {
78
namespace models {
89
// AlexNet model architecture from the
910
// "One weird trick..." <https://arxiv.org/abs/1404.5997> paper.
10-
struct AlexNetImpl : torch::nn::Module {
11+
struct VISION_API AlexNetImpl : torch::nn::Module {
1112
torch::nn::Sequential features{nullptr}, classifier{nullptr};
1213

1314
AlexNetImpl(int64_t num_classes = 1000);

torchvision/csrc/models/densenet.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define DENSENET_H
33

44
#include <torch/torch.h>
5+
#include "general.h"
56

67
namespace vision {
78
namespace models {
@@ -18,7 +19,7 @@ namespace models {
1819
// bn_size (int) - multiplicative factor for number of bottle neck layers
1920
// (i.e. bn_size * k features in the bottleneck layer)
2021
// drop_rate (float) - dropout rate after each dense layer
21-
struct DenseNetImpl : torch::nn::Module {
22+
struct VISION_API DenseNetImpl : torch::nn::Module {
2223
torch::nn::Sequential features{nullptr};
2324
torch::nn::Linear classifier{nullptr};
2425

@@ -33,7 +34,7 @@ struct DenseNetImpl : torch::nn::Module {
3334
torch::Tensor forward(torch::Tensor x);
3435
};
3536

36-
struct DenseNet121Impl : DenseNetImpl {
37+
struct VISION_API DenseNet121Impl : DenseNetImpl {
3738
DenseNet121Impl(
3839
int64_t num_classes = 1000,
3940
int64_t growth_rate = 32,
@@ -43,7 +44,7 @@ struct DenseNet121Impl : DenseNetImpl {
4344
double drop_rate = 0);
4445
};
4546

46-
struct DenseNet169Impl : DenseNetImpl {
47+
struct VISION_API DenseNet169Impl : DenseNetImpl {
4748
DenseNet169Impl(
4849
int64_t num_classes = 1000,
4950
int64_t growth_rate = 32,
@@ -53,7 +54,7 @@ struct DenseNet169Impl : DenseNetImpl {
5354
double drop_rate = 0);
5455
};
5556

56-
struct DenseNet201Impl : DenseNetImpl {
57+
struct VISION_API DenseNet201Impl : DenseNetImpl {
5758
DenseNet201Impl(
5859
int64_t num_classes = 1000,
5960
int64_t growth_rate = 32,
@@ -63,7 +64,7 @@ struct DenseNet201Impl : DenseNetImpl {
6364
double drop_rate = 0);
6465
};
6566

66-
struct DenseNet161Impl : DenseNetImpl {
67+
struct VISION_API DenseNet161Impl : DenseNetImpl {
6768
DenseNet161Impl(
6869
int64_t num_classes = 1000,
6970
int64_t growth_rate = 48,

torchvision/csrc/models/general.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef VISION_GENERAL_H
2+
#define VISION_GENERAL_H
3+
4+
#ifdef _WIN32
5+
#if defined(torchvision_EXPORTS)
6+
#define VISION_API __declspec(dllexport)
7+
#else
8+
#define VISION_API __declspec(dllimport)
9+
#endif
10+
#else
11+
#define VISION_API
12+
#endif
13+
14+
#endif // VISION_GENERAL_H

torchvision/csrc/models/googlenet.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#define GOOGLENET_H
33

44
#include <torch/torch.h>
5+
#include "general.h"
56

67
namespace vision {
78
namespace models {
89

910
namespace _googlenetimpl {
10-
struct BasicConv2dImpl : torch::nn::Module {
11+
struct VISION_API BasicConv2dImpl : torch::nn::Module {
1112
torch::nn::Conv2d conv{nullptr};
1213
torch::nn::BatchNorm bn{nullptr};
1314

@@ -18,7 +19,7 @@ struct BasicConv2dImpl : torch::nn::Module {
1819

1920
TORCH_MODULE(BasicConv2d);
2021

21-
struct InceptionImpl : torch::nn::Module {
22+
struct VISION_API InceptionImpl : torch::nn::Module {
2223
BasicConv2d branch1{nullptr};
2324
torch::nn::Sequential branch2, branch3, branch4;
2425

@@ -36,7 +37,7 @@ struct InceptionImpl : torch::nn::Module {
3637

3738
TORCH_MODULE(Inception);
3839

39-
struct InceptionAuxImpl : torch::nn::Module {
40+
struct VISION_API InceptionAuxImpl : torch::nn::Module {
4041
BasicConv2d conv{nullptr};
4142
torch::nn::Linear fc1{nullptr}, fc2{nullptr};
4243

@@ -49,13 +50,13 @@ TORCH_MODULE(InceptionAux);
4950

5051
} // namespace _googlenetimpl
5152

52-
struct GoogLeNetOutput {
53+
struct VISION_API GoogLeNetOutput {
5354
torch::Tensor output;
5455
torch::Tensor aux1;
5556
torch::Tensor aux2;
5657
};
5758

58-
struct GoogLeNetImpl : torch::nn::Module {
59+
struct VISION_API GoogLeNetImpl : torch::nn::Module {
5960
bool aux_logits, transform_input;
6061

6162
_googlenetimpl::BasicConv2d conv1{nullptr}, conv2{nullptr}, conv3{nullptr};

torchvision/csrc/models/inception.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#define INCEPTION_H
33

44
#include <torch/torch.h>
5+
#include "general.h"
56

67
namespace vision {
78
namespace models {
89
namespace _inceptionimpl {
9-
struct BasicConv2dImpl : torch::nn::Module {
10+
struct VISION_API BasicConv2dImpl : torch::nn::Module {
1011
torch::nn::Conv2d conv{nullptr};
1112
torch::nn::BatchNorm bn{nullptr};
1213

@@ -17,7 +18,7 @@ struct BasicConv2dImpl : torch::nn::Module {
1718

1819
TORCH_MODULE(BasicConv2d);
1920

20-
struct InceptionAImpl : torch::nn::Module {
21+
struct VISION_API InceptionAImpl : torch::nn::Module {
2122
BasicConv2d branch1x1, branch5x5_1, branch5x5_2, branch3x3dbl_1,
2223
branch3x3dbl_2, branch3x3dbl_3, branch_pool;
2324

@@ -26,15 +27,15 @@ struct InceptionAImpl : torch::nn::Module {
2627
torch::Tensor forward(torch::Tensor x);
2728
};
2829

29-
struct InceptionBImpl : torch::nn::Module {
30+
struct VISION_API InceptionBImpl : torch::nn::Module {
3031
BasicConv2d branch3x3, branch3x3dbl_1, branch3x3dbl_2, branch3x3dbl_3;
3132

3233
InceptionBImpl(int64_t in_channels);
3334

3435
torch::Tensor forward(torch::Tensor x);
3536
};
3637

37-
struct InceptionCImpl : torch::nn::Module {
38+
struct VISION_API InceptionCImpl : torch::nn::Module {
3839
BasicConv2d branch1x1{nullptr}, branch7x7_1{nullptr}, branch7x7_2{nullptr},
3940
branch7x7_3{nullptr}, branch7x7dbl_1{nullptr}, branch7x7dbl_2{nullptr},
4041
branch7x7dbl_3{nullptr}, branch7x7dbl_4{nullptr}, branch7x7dbl_5{nullptr},
@@ -45,7 +46,7 @@ struct InceptionCImpl : torch::nn::Module {
4546
torch::Tensor forward(torch::Tensor x);
4647
};
4748

48-
struct InceptionDImpl : torch::nn::Module {
49+
struct VISION_API InceptionDImpl : torch::nn::Module {
4950
BasicConv2d branch3x3_1, branch3x3_2, branch7x7x3_1, branch7x7x3_2,
5051
branch7x7x3_3, branch7x7x3_4;
5152

@@ -54,7 +55,7 @@ struct InceptionDImpl : torch::nn::Module {
5455
torch::Tensor forward(torch::Tensor x);
5556
};
5657

57-
struct InceptionEImpl : torch::nn::Module {
58+
struct VISION_API InceptionEImpl : torch::nn::Module {
5859
BasicConv2d branch1x1, branch3x3_1, branch3x3_2a, branch3x3_2b,
5960
branch3x3dbl_1, branch3x3dbl_2, branch3x3dbl_3a, branch3x3dbl_3b,
6061
branch_pool;
@@ -64,7 +65,7 @@ struct InceptionEImpl : torch::nn::Module {
6465
torch::Tensor forward(torch::Tensor x);
6566
};
6667

67-
struct InceptionAuxImpl : torch::nn::Module {
68+
struct VISION_API InceptionAuxImpl : torch::nn::Module {
6869
BasicConv2d conv0;
6970
BasicConv2d conv1;
7071
torch::nn::Linear fc;
@@ -83,15 +84,15 @@ TORCH_MODULE(InceptionAux);
8384

8485
} // namespace _inceptionimpl
8586

86-
struct InceptionV3Output {
87+
struct VISION_API InceptionV3Output {
8788
torch::Tensor output;
8889
torch::Tensor aux;
8990
};
9091

9192
// Inception v3 model architecture from
9293
//"Rethinking the Inception Architecture for Computer Vision"
9394
//<http://arxiv.org/abs/1512.00567>
94-
struct InceptionV3Impl : torch::nn::Module {
95+
struct VISION_API InceptionV3Impl : torch::nn::Module {
9596
bool aux_logits, transform_input;
9697

9798
_inceptionimpl::BasicConv2d Conv2d_1a_3x3{nullptr}, Conv2d_2a_3x3{nullptr},

torchvision/csrc/models/mobilenet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#define MOBILENET_H
33

44
#include <torch/torch.h>
5+
#include "general.h"
56

67
namespace vision {
78
namespace models {
8-
struct MobileNetV2Impl : torch::nn::Module {
9+
struct VISION_API MobileNetV2Impl : torch::nn::Module {
910
int64_t last_channel;
1011
torch::nn::Sequential features, classifier;
1112

torchvision/csrc/models/resnet.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define RESNET_H
33

44
#include <torch/torch.h>
5+
#include "general.h"
56

67
namespace vision {
78
namespace models {
@@ -19,7 +20,7 @@ torch::nn::Conv2d conv3x3(
1920
// 1x1 convolution
2021
torch::nn::Conv2d conv1x1(int64_t in, int64_t out, int64_t stride = 1);
2122

22-
struct BasicBlock : torch::nn::Module {
23+
struct VISION_API BasicBlock : torch::nn::Module {
2324
template <typename Block>
2425
friend struct vision::models::ResNetImpl;
2526

@@ -42,7 +43,7 @@ struct BasicBlock : torch::nn::Module {
4243
torch::Tensor forward(torch::Tensor x);
4344
};
4445

45-
struct Bottleneck : torch::nn::Module {
46+
struct VISION_API Bottleneck : torch::nn::Module {
4647
template <typename Block>
4748
friend struct vision::models::ResNetImpl;
4849

@@ -184,40 +185,40 @@ torch::Tensor ResNetImpl<Block>::forward(torch::Tensor x) {
184185
return x;
185186
}
186187

187-
struct ResNet18Impl : ResNetImpl<_resnetimpl::BasicBlock> {
188+
struct VISION_API ResNet18Impl : ResNetImpl<_resnetimpl::BasicBlock> {
188189
ResNet18Impl(int64_t num_classes = 1000, bool zero_init_residual = false);
189190
};
190191

191-
struct ResNet34Impl : ResNetImpl<_resnetimpl::BasicBlock> {
192+
struct VISION_API ResNet34Impl : ResNetImpl<_resnetimpl::BasicBlock> {
192193
ResNet34Impl(int64_t num_classes = 1000, bool zero_init_residual = false);
193194
};
194195

195-
struct ResNet50Impl : ResNetImpl<_resnetimpl::Bottleneck> {
196+
struct VISION_API ResNet50Impl : ResNetImpl<_resnetimpl::Bottleneck> {
196197
ResNet50Impl(int64_t num_classes = 1000, bool zero_init_residual = false);
197198
};
198199

199-
struct ResNet101Impl : ResNetImpl<_resnetimpl::Bottleneck> {
200+
struct VISION_API ResNet101Impl : ResNetImpl<_resnetimpl::Bottleneck> {
200201
ResNet101Impl(int64_t num_classes = 1000, bool zero_init_residual = false);
201202
};
202203

203-
struct ResNet152Impl : ResNetImpl<_resnetimpl::Bottleneck> {
204+
struct VISION_API ResNet152Impl : ResNetImpl<_resnetimpl::Bottleneck> {
204205
ResNet152Impl(int64_t num_classes = 1000, bool zero_init_residual = false);
205206
};
206207

207-
struct ResNext50_32x4dImpl : ResNetImpl<_resnetimpl::Bottleneck> {
208+
struct VISION_API ResNext50_32x4dImpl : ResNetImpl<_resnetimpl::Bottleneck> {
208209
ResNext50_32x4dImpl(
209210
int64_t num_classes = 1000,
210211
bool zero_init_residual = false);
211212
};
212213

213-
struct ResNext101_32x8dImpl : ResNetImpl<_resnetimpl::Bottleneck> {
214+
struct VISION_API ResNext101_32x8dImpl : ResNetImpl<_resnetimpl::Bottleneck> {
214215
ResNext101_32x8dImpl(
215216
int64_t num_classes = 1000,
216217
bool zero_init_residual = false);
217218
};
218219

219220
template <typename Block>
220-
struct ResNet : torch::nn::ModuleHolder<ResNetImpl<Block>> {
221+
struct VISION_API ResNet : torch::nn::ModuleHolder<ResNetImpl<Block>> {
221222
using torch::nn::ModuleHolder<ResNetImpl<Block>>::ModuleHolder;
222223
};
223224

torchvision/csrc/models/shufflenetv2.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#define SHUFFLENETV2_H
33

44
#include <torch/torch.h>
5+
#include "general.h"
56

67
namespace vision {
78
namespace models {
89

9-
struct ShuffleNetV2Impl : torch::nn::Module {
10+
struct VISION_API ShuffleNetV2Impl : torch::nn::Module {
1011
std::vector<int64_t> _stage_out_channels;
1112
torch::nn::Sequential conv1{nullptr}, stage2, stage3, stage4, conv5{nullptr};
1213
torch::nn::Linear fc{nullptr};
@@ -19,19 +20,19 @@ struct ShuffleNetV2Impl : torch::nn::Module {
1920
torch::Tensor forward(torch::Tensor x);
2021
};
2122

22-
struct ShuffleNetV2_x0_5Impl : ShuffleNetV2Impl {
23+
struct VISION_API ShuffleNetV2_x0_5Impl : ShuffleNetV2Impl {
2324
ShuffleNetV2_x0_5Impl(int64_t num_classes = 1000);
2425
};
2526

26-
struct ShuffleNetV2_x1_0Impl : ShuffleNetV2Impl {
27+
struct VISION_API ShuffleNetV2_x1_0Impl : ShuffleNetV2Impl {
2728
ShuffleNetV2_x1_0Impl(int64_t num_classes = 1000);
2829
};
2930

30-
struct ShuffleNetV2_x1_5Impl : ShuffleNetV2Impl {
31+
struct VISION_API ShuffleNetV2_x1_5Impl : ShuffleNetV2Impl {
3132
ShuffleNetV2_x1_5Impl(int64_t num_classes = 1000);
3233
};
3334

34-
struct ShuffleNetV2_x2_0Impl : ShuffleNetV2Impl {
35+
struct VISION_API ShuffleNetV2_x2_0Impl : ShuffleNetV2Impl {
3536
ShuffleNetV2_x2_0Impl(int64_t num_classes = 1000);
3637
};
3738

torchvision/csrc/models/squeezenet.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#define SQUEEZENET_H
33

44
#include <torch/torch.h>
5+
#include "general.h"
56

67
namespace vision {
78
namespace models {
8-
struct SqueezeNetImpl : torch::nn::Module {
9+
struct VISION_API SqueezeNetImpl : torch::nn::Module {
910
int64_t num_classes;
1011
torch::nn::Sequential features{nullptr}, classifier{nullptr};
1112

@@ -17,15 +18,15 @@ struct SqueezeNetImpl : torch::nn::Module {
1718
// SqueezeNet model architecture from the "SqueezeNet: AlexNet-level
1819
// accuracy with 50x fewer parameters and <0.5MB model size"
1920
// <https://arxiv.org/abs/1602.07360> paper.
20-
struct SqueezeNet1_0Impl : SqueezeNetImpl {
21+
struct VISION_API SqueezeNet1_0Impl : SqueezeNetImpl {
2122
SqueezeNet1_0Impl(int64_t num_classes = 1000);
2223
};
2324

2425
// SqueezeNet 1.1 model from the official SqueezeNet repo
2526
// <https://github.com/DeepScale/SqueezeNet/tree/master/SqueezeNet_v1.1>.
2627
// SqueezeNet 1.1 has 2.4x less computation and slightly fewer parameters
2728
// than SqueezeNet 1.0, without sacrificing accuracy.
28-
struct SqueezeNet1_1Impl : SqueezeNetImpl {
29+
struct VISION_API SqueezeNet1_1Impl : SqueezeNetImpl {
2930
SqueezeNet1_1Impl(int64_t num_classes = 1000);
3031
};
3132

0 commit comments

Comments
 (0)