Skip to content

Conversation

GameParrot
Copy link
Contributor

No description provided.

@ChristopherHX
Copy link
Member

You are using an invalid method signature.
See https://github.com/pytorch/cpuinfo/blob/512e9d0258212d6759729330b445fa41f4fa0a49/src/api.c#L167.

If you replace a non void function with a void function, then you are producing undefined behavior. In your test the value might be 0, but it could also be any other random uint32_t.

@ChristopherHX
Copy link
Member

const struct cpuinfo_package* cpuinfo_get_package(uint32_t index) {
	if CPUINFO_UNLIKELY(!cpuinfo_is_initialized) {
		cpuinfo_log_fatal("cpuinfo_get_%s called before cpuinfo is initialized", "package");
	}
	if CPUINFO_UNLIKELY(index >= cpuinfo_packages_count) {
		return NULL;
	}
	return &cpuinfo_packages[index];
}

You can replace cpuinfo_package with void and return NULL or nullptr, but I like correct signatures.

Ah
You are working around symtoms

	if CPUINFO_UNLIKELY(!cpuinfo_is_initialized) {
		cpuinfo_log_fatal("cpuinfo_get_%s called before cpuinfo is initialized", "package");
	}

This message is logged in your log file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants