Issues with accessing global IDs in PyOpenCL within 2D arrays are causing errors

I'm completely new to OpenCL and decided to experiment with it using the code provided on a website. I made some changes to the code and am attempting to send a 4x4 matrix filled with all 1s to the kernel and retrieve it back. It may seem like a simple task, but it's important for me to grasp the workings of OpenCL. Here is the input matrix:

 [[ 1.  1.  1.  1.]
 [ 1.  1.  1.  1.]
 [ 1.  1.  1.  1.]
 [ 1.  1.  1.  1.]]

However, the output from the kernel is different from the input as shown below:

[[ 1.  1.  1.  1.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]

This is the complete code that I've been working on:

import pyopencl as cl
from pyopencl import array
import numpy as np

## Step #1. Obtain an OpenCL platform.
platform = cl.get_platforms()[0]

##... (code continues)
    
print(matrix_dot_vector)

The issue I am facing is that the value of int y = get_global_id(1); always seems to be 0, which leads to this discrepancy in results. I can't figure out why this happens, especially since I pass the correct shape to the kernel function. Any ideas on what could be wrong?

Thank you!

Answer â„–1

The first kernel parameter is receiving an incorrect value - it should not be the total size of the matrix. Replace np.int32(matrix.size) with np.int32(matrix.shape[0]).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using selenium to iterate through previous results and accumulate them in a for loop

My code is functioning, but it seems to be accumulating the previous results. Can someone please assist me with this issue? Thank you. url=https://www.bbc.com/news/world news_search = driver.find_elements(By.XPATH, "//div[@class='gs-c-promo gs-t ...

Enhancing the django admin group with an additional field

I am seeking guidance on how to add a single field to a group of fields within a fieldset in DjangoAdmin. Currently, I have the following setup: class SecretarioAdmin(UserAdmin): model=Secretario def get_fieldsets(self, request, obj=None): ...

Guide: Generating a Random Number with Prefix using Python

Can you help me create a list of all potential numbers in the given prefix? import random prefix = "05" print prefix + #List of Potential Numbers Goes Here ...

Tips for finding the difference between two multidimensional arrays in PHP using arrays:

Hello there, I have a question that I need help with. My challenge involves comparing two multidimensional arrays and finding the difference between them. First Array: Array ( [0] => Array ( [0] => 2017-11-01 [1] => ...

Python: Implementing abstract base classes (abc) in Python versions earlier than 2.6

Is there an implementation available for the 'abc' module that is compatible with Python versions older than 2.6? EDIT: Specifically, I am searching for a code snippet that replicates the functionality of ABCMeta and abstractmethod from the &apo ...

How to adjust a dataset to one or two equations using Python

I am working with a dataset obtained from a mechanical indentation test. You can access the dataset through this link: The dataset contains information on the displacement of a spherical probe vs the force recorded during the test. My goal is to fit these ...

Guide on transferring a particular XML element to a separate XML document using Python

I have several xml files similar to the example below:- File Name = Updated input.xml <?xml version="1.0"?> <TestSuite Name="A123"> <Group Name="TestRoot" ExecutionPolicy="AnyDeviceAnyOrder"> < ...

Sending an element to a field or website login using Python and Selenium is not permitted

I recently encountered an issue while trying to log into a website using Selenium scripts with a username and password. It seems that the website (Etsy) has updated its code to hide the username field. I am now facing difficulties sending the username to t ...

Transforming JSON data into an organized dataframe structure

I have some data stored in variables: results = requests.request("POST", url, headers=headers, data=payload).json() results {‘ABC: {’26/03/2021': {‘A’: ‘1234’, ‘B’: ‘5678’}, '29/03/2021': {‘A’: ‘5555â ...

Using only python, launch a local html file on localhost

Currently, I am executing a code on a remote server that periodically creates an "status" HTML file (similar to TensorBoard) and saves it in a directory on the server. To check the status, I download this HTML file whenever needed. However, if I could use ...

Node.js (npm) is still unable to locate python despite setting %PYTHON% beforehand

Trying to get Node.js to work is proving to be more challenging than expected! Despite having two versions of Python on my computer, it seems that Node.js only works with the older version, 2.7. When I encountered an error, it prompted me to set the path ...

Develop a Python binary file incorporating the Selenium webdriver manager

I am trying to convert my Selenium code into an executable file. I have previously used auto-py-to-exe for non-Selenium codes, but I am facing difficulties with this particular project. While searching for a solution, I came across a suggestion provided i ...

Combining Javascript and Django for a powerful web development solution

Having trouble setting up JS on my Django web app, despite reading through the documentation and previous queries. Using the Django dev server with the following file structure: mysite/ __init__.py MySiteDB manage.py settings.py ...

Developing an intricate nesting structure for an object

this is my code snippet: "book" => {b:{o:{o:k:{'end':true} could someone please provide an explanation or a helpful link for this? const ENDS_HERE = '__ENDS_HERE' class Trie { constructor() { this.node = {}; } insert(w ...

Ways to have Python recognize a variable as a grouping (such as a list or set) of strings

Below is a simple code snippet: for link in links: products[link] = get_products(link) In this code, the variable links should ideally be a set of strings. However, there are cases where it is just a single string, causing Python to treat it as indiv ...

Python selenium WebDriver: error with list index exceeding bounds

I am encountering an issue with the code below while trying to scroll down a website using JavaScript enabled. The problem arises when the newHeight value reaches approximately 229275, at this point I receive an "list out of range" error on line browser.fi ...

Using a for loop to divide a list into smaller lists

When I use pathlib.glob() to get a list of files, I encounter an issue where I can only work with the first group of files based on their extension (.1, .2, etc.) before getting empty lists. Although I could easily solve this by adjusting my initial glob, ...

Exploring network traffic using Selenium and PhantomJS

Exploring ways to capture website traffic while browsing using Selenium with python has led me to a dilemma - since most of the traffic is encrypted (https), using a proxy may not be effective. One idea I came up with is running phantomJS with selenium an ...

Why does Python Selenium's browser.find_element_by_class_name sometimes return an error?

Just starting out with Python and currently working through "Automate the Boring Stuff" by Al Swigart. I've created a script to play the popular game "2048" at "". After a few moves, the game will reach its maximum score and display a "Game Over!" me ...

Working with Namespaces in LXML: How to Replace Elements in a String

Is there a way to seamlessly substitute a specific element with a snippet of string while preserving the original namespaces? <!-- language: python --> from lxml import etree replacestring = '''<AP_PTO gml:id="DEAL123456789abc"> ...