Esempio n. 1
0
header.write('// Automatically generated file, DO NOT EDIT!\n')
header.write('#include "caffe/common.hpp"\n')
header.write('#include "caffe/layer.hpp"\n')
header.write('#include "caffe/layer_factory.hpp"\n')
header.write('#include "caffe/proto/caffe.pb.h"\n')

# Inline helper function for creating layers
header.write('namespace caffe {\n')

header.write('inline shared_ptr<LayerBase> CreateLayer(LayerParameter layer_param) {\n')
header.write('switch(layer_param.bottom_data_type()) {\n')

var_types = list(proto_types.keys())

for i in range(0, len(var_types)):
    if var_types[i] in list(variant_enable_flags.keys()):
        header.write('#if defined(' + variant_enable_flags[var_types[i]] + ')\n')
    header.write('case ' + proto_types[var_types[i]] + ': {\n')
    header.write('switch(layer_param.compute_data_type()) {\n')
    for j in range(0, len(var_types)):
        if var_types[j] in list(variant_enable_flags.keys()):
            header.write('#if defined(' + variant_enable_flags[var_types[j]] + ')\n')
        header.write('case ' + proto_types[var_types[j]] + ': {\n')
        header.write('switch(layer_param.top_data_type()) {\n')
        for k in range(0, len(var_types)):
            if var_types[k] in list(variant_enable_flags.keys()):
                header.write('#if defined(' + variant_enable_flags[var_types[k]] + ')\n')
            header.write('case ' + proto_types[var_types[k]] + ': {\n')
            header.write('return LayerRegistry<' + var_types[i]  + ', ' + var_types[j] + ', ' + var_types[k] + '>::CreateLayer(layer_param);\n')
            header.write('}\n')  # case
            if var_types[k] in list(variant_enable_flags.keys()):
Esempio n. 2
0
        header.write('\n')
    else:
        header.write('\\\n')

header.write('#define POINTER_VARIANT_TYPES\\\n')
for i in range(0, len(pointer_variant_types)):
    header.write('  (' + pointer_variant_types[i] + ')')
    if (i == len(pointer_variant_types) - 1):
        header.write('\n')
    else:
        header.write('\\\n')

# 1 template class instantiation
for var_type_1 in variant_types:
    flags = []
    if var_type_1 in variant_enable_flags.keys():
        flag = variant_enable_flags[var_type_1]
        if not flag in flags:
            flags.append(flag)
    header.write('#define INSTANTIATE_CLASS_' + var_type_1 + '(CLASSNAME)\\\n')
    header.write('  template class CLASSNAME<' + var_type_1 + '>;\n')
    header.write('#define EXTERN_CLASS_' + var_type_1 + '(CLASSNAME)\\\n')
    header.write('  extern template class CLASSNAME<' + var_type_1 + '>;\n')
    header.write('#define INSTANTIATE_FUNC_' + var_type_1 + '(FUNCNAME)\\\n')
    header.write('  template decltype(FUNCNAME<' + var_type_1 +
                 '>) FUNCNAME<' + var_type_1 + '>;\n')
    header.write('#define INSTANTIATE_CLASST_FUNC_' + var_type_1 +
                 '(CLASSNAME, FUNCNAME)\\\n')
    header.write('  template pmf_sig_t<decltype(&CLASSNAME<' + var_type_1 +
                 '>::FUNCNAME)> CLASSNAME<' + var_type_1 + '>::FUNCNAME;\n')
    header.write('#define INSTANTIATE_CLASS_FUNCT_' + var_type_1 +
Esempio n. 3
0
    path = sys.argv[1]

header = open(path + '/test_macros.hpp', 'w')

var_types = list(proto_types.keys())

header.write('namespace caffe {\n')

header.write('template<typename TypeParam> class CPUDevice;\n')
header.write('template<typename TypeParam> class GPUDevice;\n')

# TestDtypes
header.write('typedef ::testing::Types<\n')
li = 0
for i in range(0, len(var_types)):
    if var_types[i] in variant_enable_flags.keys():
        header.write('#if defined(' + variant_enable_flags[var_types[i]] + ')\n')
    if not li == 0:
        header.write(',')
    header.write(var_types[i] + '\n')
    li += 1
    if var_types[i] in variant_enable_flags.keys():
        header.write('#endif\n')
header.write('> TestDtypes;\n')

header.write('typedef ::testing::Types<\n')
li = 0
for i in range(0, len(var_types)):
    if var_types[i] in float_types:
        if var_types[i] in variant_enable_flags.keys():
            header.write('#if defined(' + variant_enable_flags[var_types[i]] + ')\n')
Esempio n. 4
0
header.write('#include "caffe/common.hpp"\n')
header.write('#include "caffe/blob.hpp"\n')
header.write('#include "caffe/proto/caffe.pb.h"\n')

# Inline helper function for creating layers
header.write('namespace caffe {\n')

header.write(
    'inline shared_ptr<BlobBase> CreateBlob(Device* dev, DataType data_type) {\n'
)
header.write('switch(data_type) {\n')

var_types = list(proto_types.keys())

for i in range(0, len(var_types)):
    if var_types[i] in list(variant_enable_flags.keys()):
        header.write('#if defined(' + variant_enable_flags[var_types[i]] +
                     ')\n')
    header.write('case ' + proto_types[var_types[i]] + ': {\n')
    header.write('return make_shared<Blob<' + var_types[i] + '> >(dev);\n')
    header.write('}\n')  # case
    if var_types[i] in list(variant_enable_flags.keys()):
        header.write('#endif\n')
header.write(
    'default: { LOG(FATAL) << "Data types not enabled or supported"; }\n')
header.write('}\n')  # switch
header.write('return nullptr;\n')
header.write('}\n')  # CreateLayer

header.write('}  // namespace caffe\n')