Skip to content

Issue: New way on lemonade cli to select which Rocm architecture to use - #2236

Closed
GabrielReusRodriguez wants to merge 10 commits into
lemonade-sdk:mainfrom
GabrielReusRodriguez:rocmArch
Closed

Issue: New way on lemonade cli to select which Rocm architecture to use #2236
GabrielReusRodriguez wants to merge 10 commits into
lemonade-sdk:mainfrom
GabrielReusRodriguez:rocmArch

Conversation

@GabrielReusRodriguez

Copy link
Copy Markdown
Contributor

Installing lemonade on ubuntu, I saw that when you have iGPU and eGPU and you install the llamacpp:rocm backend , it always installs the gfx1150 version of therock. I tryed with HSA_OVERRIDE_GFX_VERSION environment var but it was impossible. I think it is because lemonade loops on devices and uses first GPU found, usually the igpu.

I added a new option on lemonade cli that lists all the rocm architectures avaible (gfxXXXX) with lemonade rocm-arch and so you can set your prefered archituecture with lemonade rocm-arch set gfx1201 .

You can also add "auto" or empty string to execute as always.

I tested on my machines and I think it works! I think it could be usefull .

Examples:
image

image image you can also set "auto" image

It is a config.json var so you can also set via lemonade config set instruction.

:)

@github-actions github-actions Bot added area::cli lemonade CLI client (src/cpp/cli) engine::llamacpp llama.cpp backend (LlamaCppServer); GPU/CPU LLM inference (Vulkan, ROCm, Metal) runtime::rocm AMD ROCm runtime enhancement New feature or request labels Jun 14, 2026
@jeremyfowers
jeremyfowers requested a review from superm1 June 14, 2026 17:00

@superm1 superm1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general comment; I think this actually is a concept that should be up-leveled. We should allow "GPU" selection for individual devices. For example if I have two 9700's they're an identical arch, how else would I pick between them?

Comment on lines +13 to +25
// In this function we tranform the rocm archictecture from numeric format to gfx format.
std::string ROCmArchUtils::rocm_arch_numeric_to_gfx(const std::string& numeric_arch) {
try {
// We convert the string with numeric version to long long number
long long num = std::stoll(numeric_arch);

// We get the differents components of version.
long long major = num / 10000;
long long minor = (num / 100) % 100;
long long stepping = num % 100;

// We build the gfx version with the previous components.
return "gfx" + std::to_string(major) + std::to_string(minor) + std::to_string(stepping);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is already very similar code elsewhere, can you please instead split that to a helper?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,
I see that there is some code in system_info.cpp file that does the same:

image

My proposal would be to create 2 helper functions on system_info.cpp:

std::string transform_isakfd_to_gfx(const std::string& isa) {
if (!isa.empty() &&
std::all_of(isa.begin(), isa.end(), ::isdigit)) {
int v;
try {
v = std::stoi(isa);
} catch (const std::exception& e) {
throw std::runtime_error(
"Failed to parse gfx_target_version '" + isa + "': " + e.what());
}
int major = v / 10000;
int minor = (v / 100) % 100;
int step = v % 100;

    char buf[16];
    std::snprintf(buf, sizeof(buf), "gfx%d%x%x", major, minor, step);
    return std::string(buf);
} else {
    return "";
}

}

and

std::string get_gfx_from_device_name(const std::string device_name) {
std::string device_lower = device_name;
std::transform(device_lower.begin(), device_lower.end(), device_lower.begin(), ::tolower);

std::smatch gfx_match;
// Match 3- or 4-digit gfx tokens; the trailing nibble can be hex (e.g. gfx90a).
if (std::regex_search(device_lower, gfx_match, std::regex(R"((gfx[0-9a-f]{3,4}))"))) {
    return gfx_match[1].str();
}
return "";

}

So I can reuse that functions and apply in the original std::string identify_rocm_arch_from_name(const std::string& device_name)
.

Are the function names correct? is the driver version of rocm all numbers an isa ? example : 120001

I think it is better to do wrapper funtions in ROCmArchUtils calling the previous ones to avoid the #include "lemon/system_info.h" in lemonade_client.cpp.

I try it... :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you stick to ROCm ISA selection play with function names and see what feels appropriate. But yes we're always detecting ISA from the kfd sysfs.

Make sure you look at my other comment about upleveling this though.

}


} // namespace lemon No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing newline

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change done

static std::vector<ROCmDeviceInfo> rocm_arch_get_active_devices(const json& json_devices);
};

} // namespace lemon No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing newline

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change done

@GabrielReusRodriguez

Copy link
Copy Markdown
Contributor Author

As a general comment; I think this actually is a concept that should be up-leveled. We should allow "GPU" selection for individual devices. For example if I have two 9700's they're an identical arch, how else would I pick between them?

That's a good challenge :). I just started getting into the lemonade code but I'll see if I can think of anything that might be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area::cli lemonade CLI client (src/cpp/cli) engine::llamacpp llama.cpp backend (LlamaCppServer); GPU/CPU LLM inference (Vulkan, ROCm, Metal) enhancement New feature or request runtime::rocm AMD ROCm runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants