-
Notifications
You must be signed in to change notification settings - Fork 5
add windows support #9
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -647,13 +647,42 @@ def _LoadMtmlLibrary(): | |
| try: | ||
| # ensure the library still isn't loaded | ||
| if mtmlLib == None: | ||
| try: | ||
| # assume linux | ||
| mtmlLib = CDLL("libmtml.so") | ||
| except OSError as ose: | ||
| _mtmlCheckReturn(MTML_ERROR_FUNCTION_NOT_FOUND) | ||
| # Platform-specific library loading | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest that we need to split up the windows and linux loader logic. Maybe refactoring the loader into smaller, well-defined helper functions with clearer responsibilities. |
||
| platform = sys.platform | ||
|
|
||
| if platform.startswith("win32") or platform.startswith("cygwin"): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We prefer using: |
||
| # Windows platform | ||
| lib_names = ["mtml.dll", "libmtml.dll"] | ||
| lib_loader = WinDLL | ||
| else: | ||
| # Linux/Unix platform | ||
| lib_names = ["libmtml.so"] | ||
| lib_loader = CDLL | ||
|
|
||
| # Try loading the library with different names | ||
| last_error = None | ||
| for lib_name in lib_names: | ||
| try: | ||
| mtmlLib = lib_loader(lib_name) | ||
| break | ||
| except OSError as ose: | ||
| last_error = ose | ||
| continue | ||
|
|
||
| # If all attempts failed, try with full path to mtml/mtml.dll | ||
| if mtmlLib is None and (platform.startswith("win32") or platform.startswith("cygwin")): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as |
||
| try: | ||
| import os | ||
| dll_path = os.path.join(os.path.dirname(__file__), "mtml", "mtml.dll") | ||
| mtmlLib = WinDLL(dll_path) | ||
| except OSError as ose: | ||
| last_error = ose | ||
|
|
||
| if mtmlLib == None: | ||
| _mtmlCheckReturn(MTML_ERROR_FUNCTION_NOT_FOUND) | ||
| error_msg = f"Failed to load MTML library. Tried: {', '.join(lib_names)}" | ||
| if last_error: | ||
| error_msg += f"\nLast error: {last_error}" | ||
| raise OSError(error_msg) | ||
| finally: | ||
| # lock is always freed | ||
| libLoadLock.release() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| from pymtml import * | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe no need to add this test file. It is the same as test_pymtml.py
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xinye0123 You can run the tests under https://github.com/MooreThreads/mthreads-ml-py/tree/main/examples to verify that everything works properly on Windows. |
||
|
|
||
| #init | ||
| mtmlLibraryInit() | ||
|
|
||
| #get device count | ||
| device_count = mtmlLibraryCountDevice() | ||
| print(f"Found {device_count} GPU(s)") | ||
|
|
||
| #query devices | ||
| for i in range(device_count): | ||
| device = mtmlLibraryInitDeviceByIndex(i) | ||
|
|
||
| #Basic info | ||
| name = mtmlDeviceGetName(device) | ||
| uuid = mtmlDeviceGetUUID(device) | ||
| print(f"Device {i}: {name} (UUID: {uuid})") | ||
|
|
||
| #Memory info | ||
| with mtmlMemoryContext(device) as mem_ctx: | ||
| total = mtmlMemoryGetTotal(mem_ctx) | ||
| used = mtmlMemoryGetUsed(mem_ctx) | ||
| print(f" Memory: {used / (1024**3):.2f} GB used / {total / (1024**3):.2f} GB total") | ||
|
|
||
| #GPU1 utilization | ||
| with mtmlGpuContext(device) as gpu_ctx: | ||
| utilization = mtmlGpuGetUtilization(gpu_ctx) | ||
| temp = mtmlGpuGetTemperature(gpu_ctx) | ||
| print(f" GPU Utilization: {utilization}%, Temperature: {temp}°C") | ||
|
|
||
| #cleanup | ||
| mtmlLibraryShutDown() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Windows, there is no ldconfig mechanism like Linux, please add the checking command like:
where mtml.dll