0

Using gpu for our function makes it fast as compared to cpu, so I want to run the function using gpu to make it fast in python.

#this function should run in GPU 
def sendRequest(url):
    resp = requests.get(url).text.lower()
    return resp

The above function is sending requests to thousands of URLs and I want it to use GPU power.

GPU I have : nvidia GTX 1660 super 6GB

Ahmad
  • 274
  • 2
  • 15
Aman Rawat
  • 21
  • 1
  • 3
  • 4
    There is a lot of misunderstanding in your assumptions. While GPUs can often speed up computations, I/O over the internet is not one of them. – Michael Szczesny Jan 02 '21 at 07:52
  • 2
    It might be more useful to familiarize yourself with [async request](https://stackoverflow.com/questions/9110593/asynchronous-requests-with-python-requests) to speed up your example. – Michael Szczesny Jan 02 '21 at 07:57

1 Answers1

5

In general running an computation a huge many times in parallel or working on matrices benefit from graphics cards because that is what they are good at doing.

For your use case:

  1. It is not a hard computation
  2. There is not a single matrix involved
  3. Rather, there is internet I/O

From how computers work, the code could not be run on GPU as it cannot send any I/O requests off to any other section of the computer - only your CPU can do that. Even from graphics or CUDA, your CPU schedules a job on the GPU, which performs that required computation and returns it as a result / as a number.

Remember the GPU can only talk with the CPU and not with your memory(can have inputs from here tho), disk or in your case, the Network Card.

Rohan Asokan
  • 634
  • 4
  • 22