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

improving the error handling for NPU check #141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions tutorial/hello_world/hello_world.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -123,12 +123,19 @@
" command = r'pnputil /enum-devices /bus PCI /deviceids '\n",
" process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
" stdout, stderr = process.communicate()\n",
" # Check for supported Hardware IDs\n",
" # Decode with error handling\n",
" apu_type = ''\n",
" if 'PCI\\\\VEN_1022&DEV_1502&REV_00' in stdout.decode(): apu_type = 'PHX/HPT'\n",
" if 'PCI\\\\VEN_1022&DEV_17F0&REV_00' in stdout.decode(): apu_type = 'STX'\n",
" if 'PCI\\\\VEN_1022&DEV_17F0&REV_10' in stdout.decode(): apu_type = 'STX'\n",
" if 'PCI\\\\VEN_1022&DEV_17F0&REV_11' in stdout.decode(): apu_type = 'STX'\n",
" try: \n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This was added in 1.2 since the environment variables weren't correctly set for PHX devices. In 1.3, this has been fixed. I would recommend removing this code to simplify the getting started example.

" stdout = stdout.decode('utf-8', errors='ignore') \n",
" except Exception as e: \n",
" # Log error message and return an empty string \n",
" print(f\"An error occurred while decoding output: {e}\") \n",
" return apu_type\n",
" # Check for supported Hardware IDs\n",
" if 'PCI\\\\VEN_1022&DEV_1502&REV_00' in stdout: apu_type = 'PHX/HPT' \n",
" if 'PCI\\\\VEN_1022&DEV_17F0&REV_00' in stdout: apu_type = 'STX' \n",
" if 'PCI\\\\VEN_1022&DEV_17F0&REV_10' in stdout: apu_type = 'STX' \n",
" if 'PCI\\\\VEN_1022&DEV_17F0&REV_11' in stdout: apu_type = 'STX' \n",
" return apu_type\n",
"\n",
"apu_type = get_apu_info()\n",
Expand Down
15 changes: 11 additions & 4 deletions tutorial/hello_world/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,19 @@ def forward(self, x):
command = r'pnputil /enum-devices /bus PCI /deviceids '
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()

# Decode with error handling
try:
stdout = stdout.decode('utf-8', errors='ignore')
except Exception as e:
# Log error message and return an empty string
print(f"An error occurred while decoding output: {e}")
# Check for supported Hardware IDs
apu_type = ''
if 'PCI\\VEN_1022&DEV_1502&REV_00' in stdout.decode(): apu_type = 'PHX/HPT'
if 'PCI\\VEN_1022&DEV_17F0&REV_00' in stdout.decode(): apu_type = 'STX'
if 'PCI\\VEN_1022&DEV_17F0&REV_10' in stdout.decode(): apu_type = 'STX'
if 'PCI\\VEN_1022&DEV_17F0&REV_11' in stdout.decode(): apu_type = 'STX'
if 'PCI\\VEN_1022&DEV_1502&REV_00' in stdout: apu_type = 'PHX/HPT'
if 'PCI\\VEN_1022&DEV_17F0&REV_00' in stdout: apu_type = 'STX'
if 'PCI\\VEN_1022&DEV_17F0&REV_10' in stdout: apu_type = 'STX'
if 'PCI\\VEN_1022&DEV_17F0&REV_11' in stdout: apu_type = 'STX'

print(f"APU Type: {apu_type}")

Expand Down