Skip to content

Return correct value in memory limit getter functions#223

Merged
davidkoski merged 2 commits intoml-explore:mainfrom
louen:val/fixmemorylimit
Apr 14, 2025
Merged

Return correct value in memory limit getter functions#223
davidkoski merged 2 commits intoml-explore:mainfrom
louen:val/fixmemorylimit

Conversation

@louen
Copy link
Contributor

@louen louen commented Apr 11, 2025

This PR covers two small bugs in the GPU memory limit related functions

When calling cacheLimit without having previously set any limit, the function would incorrectly report erroneous values (it would report whatever was the current cache value).
The logic has been fixed to report the actual value.

When calling memoryLimit, the value would not get saved to the cached variable, prompting the code to call the C function every time.

Finally the link to the metal doc has been updated.

Copy link
Member

@awni awni left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!!

@louen
Copy link
Contributor Author

louen commented Apr 11, 2025

Added public qualifier to DeviceInfo (otherwise it defaults to internal and is not readable to client code.

Comment on lines +291 to +294
public let architecture: String
public let maxBufferSize: Int
public let maxRecommendedWorkingSetSize: UInt64
public let memorySize: Int
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious about that. The internet says these should be public by default. Any idea why they need the public keyword here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the swift-book | Default Access Levels:

All entities in your code (with a few specific exceptions, as described later in this chapter) have a default access level of internal if you don’t specify an explicit access level yourself. As a result, in many cases you don’t need to specify an explicit access level in your code.

And later on in Custom Types

If you define a type’s access level as internal or public (or use the default access level of internal without specifying an access level explicitly), the default access level of the type’s members will be internal.

So in this case the structure is public but, outside of the MLX-swift module itself all its members (implicitly declared as internal) are not accessible.

@davidkoski davidkoski merged commit 43157db into ml-explore:main Apr 14, 2025
3 checks passed
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.

3 participants