Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to get the tensorrt version & platform by the single engine file ? #3073

Closed
OYCN opened this issue Jun 19, 2023 · 15 comments
Closed
Assignees
Labels
triaged Issue has been triaged by maintainers

Comments

@OYCN
Copy link

OYCN commented Jun 19, 2023

greetings!

In our project, we will keep different tensorrt versions on different platforms.

TensorRT will raise an error with "Serialize Version" when I deserialize an engine file with the wrong tensorrt version. Also I found the "Serialize Version" is in the 9th byte in the engine file. By the "Serialize Version", we can't identify the verbose version in the corresponding tensorrt version.

Is there some way we can get the engine file version or platform and don't need to deserialize ?

@zerollzeng
Copy link
Collaborator

IIRC we encode the TRT version into the engine file in the fiirst few bytes, does read it work for you? cc @nvpohanh

@zerollzeng zerollzeng self-assigned this Jun 19, 2023
@zerollzeng zerollzeng added the triaged Issue has been triaged by maintainers label Jun 19, 2023
@nvpohanh
Copy link
Collaborator

nvpohanh commented Jun 20, 2023

We currently does not have an API to do so. Would that be useful? If it would, we can consider adding an API for that

@OYCN
Copy link
Author

OYCN commented Jun 20, 2023

@zerollzeng @nvpohanh Thanks for your reply. 😄

Does the "TRT version encoded in the first few bytes" means "Serialized Engine Version" ? Is there a map between them and the TensorRT version ? 🤔

After testing, I found a map but not sure if it's robust. And it seems like just a minor level verison.

{
"8.5.3.1": 232,
"8.4.3.1": 213,
"8.2.1.8": 205
}

We currently do not have an API to do so. Would that be useful? If it would, we can consider adding an API for that

In my case, my original goal was to read the engine file in binary and judge the version without the trt library. But he doesn't seem to be able to implement patch level version checks (using "Serialized Engine Version"). 😿

@oxana-nvidia
Copy link
Collaborator

In the next version we've added an option to trtexec to get creation version without deserializing the engine. It works for engines created with TRT 8.6 and forward.

simplified related code:

    auto const blob = static_cast<uint8_t*>(env.engine.getBlob().data);
    sample::gLogInfo << "Plan was created with TensorRT version " << static_cast<int32_t>(blob[24])
        << "." << static_cast<int32_t>(blob[25]) << "." << static_cast<int32_t>(blob[26])
        << "." << static_cast<int32_t>(blob[27]) << std::endl;

@OYCN
Copy link
Author

OYCN commented Jun 27, 2023

@oxana-nvidia Thank you for providing a solution. I'm looking forward to its implementation ~

I will close this issue ~

@onurtore
Copy link

onurtore commented Oct 26, 2023

| IIRC we encode the TRT version into the engine file in the fiirst few bytes, does read it work for you?

@zerollzeng do you know which type of casting you guys like to use while reading first few bytes (32b, 16b, 8b)

  FILE* fp;
  fp = fopen(engine_path.c_str(), "r");
  int i = 0;
  while (i < 100)
  {
    fseek(fp, i * sizeof(uint8_t), SEEK_SET);
    uint8_t a;
    fread(&a, sizeof(uint8_t), 1, fp);
    std::cout << "i is: " << static_cast<int32_t>(a)<< std::endl;
    i = i + 1;
  }

This unfortunately does not give me anything, although I can see trt at the start as ascii

@zerollzeng
Copy link
Collaborator

#3073 (comment) Have you try this?

@onurtore
Copy link

onurtore commented Nov 3, 2023

No that requires minimum of 8.6 (I can not use that version), so I came up with my own stupid way, which doesn't work weird because I read uint8_t and then cast it to int32_t, which I believe same with the reference you gave.

@zerollzeng
Copy link
Collaborator

Okay, this is subject to change until we provide the API.

@jpfleischer
Copy link

In the next version we've added an option to trtexec to get creation version without deserializing the engine. It works for engines created with TRT 8.6 and forward.

simplified related code:

    auto const blob = static_cast<uint8_t*>(env.engine.getBlob().data);
    sample::gLogInfo << "Plan was created with TensorRT version " << static_cast<int32_t>(blob[24])
        << "." << static_cast<int32_t>(blob[25]) << "." << static_cast<int32_t>(blob[26])
        << "." << static_cast<int32_t>(blob[27]) << std::endl;

please give the exact trtexec command to find the version of a trt file

@OYCN
Copy link
Author

OYCN commented Dec 23, 2023

please give the exact trtexec command to find the version of a trt file

Hi @jpfleischer

It just reads the engine file generated by TRT as binary after version 8.6. You can use these bash commands to print the specified bytes:

dd if=/path/to/trt_file bs=1 skip=23 count=4 2>/dev/null | od -An -t u1 -v

@oxana-nvidia
Copy link
Collaborator

the trtexec option is called --getPlanVersionOnly. It was added to trtexec since in TRT 9.0 version. So the full command will be something like:

trtexec --loadEngine=engine.trt --getPlanVersionOnly

please use trtexec help to see more information.

@fr0zenrain
Copy link

Nvida's hardware is really awesome, and its software design is a piece of shit, with no regard for compatibility.

@onurtore
Copy link

Nvida's hardware is really awesome, and its software design is a piece of shit, with no regard for compatibility.

But don't forget buying their stocks :D At least they might pay your next meal :D

@zerollzeng
Copy link
Collaborator

Sorry about the inconvenience and we are trying to improve it, but unfortunately it's hard to maintain a "good compatibility" due to the fast changing world :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged Issue has been triaged by maintainers
Projects
None yet
Development

No branches or pull requests

7 participants