MCPcopy Create free account
hub / github.com/NVIDIA/cuda-tile / parseHeader

Function parseHeader

lib/Bytecode/Reader/BytecodeReader.cpp:299–328  ·  view source on GitHub ↗

Parses and validates the bytecode header, including the magic number and version.

Source from the content-addressed store, hash-verified

297/// Parses and validates the bytecode header, including the magic number and
298/// version.
299static LogicalResult parseHeader(EncodingReader &reader, MLIRContext &context,
300 BytecodeVersion &version) {
301 // Read and verify the magic number.
302 for (int i = 0, e = std::size(kTileIRBytecodeMagic); i < e; ++i) {
303 uint8_t byte = reader.readLE<uint8_t>();
304 if (byte != kTileIRBytecodeMagic[i])
305 return reader.emitError()
306 << "invalid magic number at position " << i << ", got "
307 << static_cast<int>(byte) << " expected "
308 << static_cast<int>(kTileIRBytecodeMagic[i]);
309 }
310 /// Read and verify the version number.
311 uint8_t verMajor, verMinor;
312 uint16_t tag;
313 if (failed(reader.readLE(verMajor)) || failed(reader.readLE(verMinor)) ||
314 failed(reader.readLE(tag)))
315 return failure();
316 // Check if the version is supported.
317 std::optional<BytecodeVersion> versionInfo =
318 BytecodeVersion::fromVersion(verMajor, verMinor, tag);
319 if (!versionInfo || *versionInfo < BytecodeVersion::kMinSupportedVersion) {
320 return reader.emitError()
321 << "unsupported Tile version " << verMajor << "." << verMinor << "."
322 << tag << ", this reader supports versions ["
323 << BytecodeVersion::kMinSupportedVersion.toString() << " - "
324 << BytecodeVersion::kCurrentVersion.toString() << "]";
325 }
326 version = *versionInfo;
327 return success();
328}
329
330/// Parses the section header from the bytecode.
331static LogicalResult parseSectionHeader(EncodingReader &reader,

Callers 2

getBytecodeSizeMethod · 0.85
readBytecodeMethod · 0.85

Calls 3

emitErrorMethod · 0.80
readLEMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected