MCPcopy Create free account
hub / github.com/RenderKit/oidn / parseTZA

Function parseTZA

core/tza.cpp:27–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25 }
26
27 std::shared_ptr<TensorMap> parseTZA(const void* buffer, size_t size)
28 {
29 const char* input = static_cast<const char*>(buffer);
30 const char* const bufferEnd = input + size;
31
32 // Parse the magic value
33 const int magic = read<uint16_t>(input, bufferEnd);
34 if (magic != 0x41D7)
35 throw Exception(Error::InvalidOperation, "invalid or corrupted weights blob");
36
37 // Parse the version
38 const int majorVersion = read<uint8_t>(input, bufferEnd);
39 const int minorVersion = read<uint8_t>(input, bufferEnd);
40 UNUSED(minorVersion);
41 if (majorVersion != 2)
42 throw Exception(Error::InvalidOperation, "unsupported weights blob version");
43
44 // Parse the table offset and jump to the table
45 const uint64_t tableOffset = read<uint64_t>(input, bufferEnd);
46 input = static_cast<const char*>(buffer) + tableOffset;
47
48 // Parse the number of tensors
49 const size_t numTensors = read<uint32_t>(input, bufferEnd);
50
51 // Parse the tensors
52 std::shared_ptr<TensorMap> tensorMap = std::make_shared<TensorMap>();
53 for (size_t i = 0; i < numTensors; ++i)
54 {
55 TensorDesc tensorDesc;
56
57 // Parse the name
58 const size_t nameLen = read<uint16_t>(input, bufferEnd);
59 checkBounds(input, bufferEnd, nameLen);
60 std::string name(input, nameLen);
61 input += nameLen;
62
63 // Parse the number of dimensions
64 const int ndims = read<uint8_t>(input, bufferEnd);
65
66 // Parse the shape of the tensor
67 tensorDesc.dims.resize(ndims);
68 for (int j = 0; j < ndims; ++j)
69 tensorDesc.dims[j] = read<uint32_t>(input, bufferEnd);
70 tensorDesc.paddedDims = tensorDesc.dims;
71
72 // Parse the layout of the tensor
73 checkBounds(input, bufferEnd, ndims);
74 std::string layout = std::string(input, input + ndims);
75 if (layout == "x")
76 tensorDesc.layout = TensorLayout::x;
77 else if (layout == "oihw")
78 tensorDesc.layout = TensorLayout::oihw;
79 else
80 throw Exception(Error::InvalidOperation, "invalid tensor layout");
81 input += ndims;
82
83 // Parse the data type of the tensor
84 const char dataType = read<char>(input, bufferEnd);

Callers 1

initMethod · 0.85

Calls 3

ExceptionFunction · 0.85
checkBoundsFunction · 0.85
getByteSizeMethod · 0.45

Tested by

no test coverage detected