0

I am trying to use my R9 280 GPU with pyopencl but i cant get it to work as my python and pyopencl knowledge is a bit on the dry side. I wonder anyone help me out or at least direct me to the right direction. Below simple python script reads upload.txt to memory and and tries to match randomly created numbers after using basic multiply function. Basicly i cannot write a kernel for this to work. As you see it is only opening the job for gpu and needs a kernel to work on reading the file, checking randomly created numbers and writing the match to a file. Thanks in advance.

#! /usr/bin/env python
import random
import pyopencl as cl
from os import environ, system
def Multiply(x,y):
   return 4*y/x

environ["PYOPENCL_CTX"]="0"
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)

run = True  
target = open("upload.txt", 'rb')
readit = target.read()
while run: 
r = 8;
p = random.randrange(1,5000);
q = Multiply(r,p);
z = str(q);
print z;
if z in readit:
    file = open('found.txt', 'ab')
    file.write(str(z))
    file.close()
    print "Found ",z
    run = False
ico
  • 13
  • 3

1 Answers1

1

I don't have comment privileges, but please see the following

import random
import pyopencl as cl
from os import environ, system

def Multiply(x,y):
   return 4*y/x

environ["PYOPENCL_CTX"]="0"
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)

# run = True  -- no need for this
with open("upload.txt", 'rb') as target:        # pythonic & safe way of opening files
    readit = target.read()

while True: 
    r = 8;
    p = random.randrange(1,5000);
    q = Multiply(r,p);
    z = str(q);
    print z;
    if z in readit:
        with open('found.txt', 'ab') as File:  # can't use file as variable name, hence the caps
            File.write(z)
            print("Found ", z)
        break

I can not help you anymore until you be specific about your question - please tell more about the error/glitches you are getting & what output do you expect

Edit: Since you are dealing with graphics processing & stuff, data source files may become extremely large - for which I suggest using lazy (buffered) read, see this for a very simple implementation

Community
  • 1
  • 1
RinkyPinku
  • 410
  • 3
  • 20
  • Basicly i cannot write a kernel for this to work. As you see it is only opening the job for gpu and needs a kernel to work on reading the file, checking randomly created numbers and writing the match to a file. – ico Jan 20 '15 at 00:35
  • @ico thanks but please copy paste this your comment in question box, also how is `queue` & `upload.txt` connected? Did you write `queue` in the file or what? – RinkyPinku Jan 20 '15 at 00:56
  • No connection between queue and upload.txt as upload.txt is full of random numbers like 50, 67, 590 etc. – ico Jan 20 '15 at 01:03