Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8723987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:44:10+00:00 2026-06-13T07:44:10+00:00

I want to create context for specific device on my platform. But I am

  • 0

I want to create context for specific device on my platform. But I am getting an error.

Code:

import pyopencl as cl
platform = cl.get_platforms()
devices = platform[0].get_devices(cl.device_type.GPU)
ctx = cl.Context(devices[0])

The error i am getting:

Traceback (most recent call last):
  File "D:\Programming\Programs_OpenCL_Python\Matrix Multiplication\3\main3.py", line 16, in <module>
    ctx = cl.Context(devices[0])
AttributeError: 'Device' object has no attribute '__iter__'

The program compiles and executes without any errors and warnings if i use:

ctx = cl.create_some_context()

But I will have to manually select the device type every-time I execute the program using this function.
I can set the following environmental variable

PYOPENCL_CTX='0'

Using this I will not be able to create contexts for different devices available based on the requirement. It will be by default set to device 0 for all the contexts that I create.

Can someone please help me with this problem.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:44:11+00:00Added an answer on June 13, 2026 at 7:44 am

    According to the PyOpenCL documentation, Context takes a list of devices, not a specific device.

    If you change your context creation code to this:

    platform = cl.get_platforms()
    my_gpu_devices = platform[0].get_devices(device_type=cl.device_type.GPU)
    ctx = cl.Context(devices=my_gpu_devices)
    

    It should work. If you really want to limit the choice to only one device, you can manipulate the my_gpu_devices list, for instance:

    my_gpu_devices = [platform[0].get_devices(device_type=cl.device_type.GPU)[0]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a button in c# with no content but just a
I want to rename an context private file created with openFileOutput() but I don't
page--node--edit.tpl.php works just fine when you want to create a specific template for editing
I want to display the compass(Image View) on device at a specific location.I tried
I am trying to create a file using powershell in a specific user context.
I want to create an event content type with one field Dates contains a
I want to be able to create a file from the Content Provider, however
i want create multiple search where statement $where_search is a multiple condition from post
I want create wordpress website into which I want create user management... That means
I want to create the app modular and would like to create multiple EDMX,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.