---
title: "Unmasking ChatGPT’s “capabilities”"
url: https://michalasobczak.pl/en/posts/demaskowanie-mozliwosci-chatgpt.html
author: "Michał Sobczak"
description: "Introduction Today, as an exception, this post is in Polish and is about ChatGPT. I went to some trouble and tried out its programming “capabilities”, as I had heard about such an option. My favourite topic lately is OpenCL, so…. ME: so write me an OpenCL kernel for sorting floating-point numbers I got bubble sort…."
published: 2023-02-06T09:56:02.000Z
updated: 2024-08-29T08:23:03.000Z
language: en
categories: ["AI/ML"]
tags: ["AI/ML", "LLM"]
license: CC BY-NC-ND 4.0 (https://creativecommons.org/licenses/by-nc-nd/4.0/)
---
# Unmasking ChatGPT’s “capabilities”

## Introduction

Today, as an exception, this post is in Polish and is about ChatGPT. I went to some trouble and tried out its programming “capabilities”, as I had heard about such an option. My favourite topic lately is **OpenCL**, so….

ME: so write me an OpenCL kernel for sorting floating-point numbers

I got **bubble** sort…. and on floats, no less. To be fair, I did not ask for doubles, so I cannot complain. But seriously, bubble sort, on a GPU, in OpenCL?

```cpp
__kernel void sort(__global float *data, int length) {
    int i = get_global_id(0);
    int j = get_global_id(1);

    if (i < length && j < length) {
        if (data[i] > data[j]) {
            float temp = data[i];
            data[i] = data[j];
            data[j] = temp;
        }
    }
}
```

## Conversation

I tried to talk to the chat about it, to find out why it suggested this and whether, after a few **hints**, it might **revise** its answers into something more relevant to the question asked:

ME: but sorting in global space will not work, because the other instances of this kernel will be running on the GPU at the same time, which will lead to incorrect results; your answer is wrong, you are not taking into account the context of this execution.

Chat: I apologise, that is true. Sorting in global space is incorrect, because many instances of this kernel may be running simultaneously on the GPU and this may lead to incorrect results. To avoid this problem, you should use a different sorting algorithm that allows sorting within a single instance, or split the sorting into many smaller sequences and sort them separately.

ME: so which algorithm do you suggest for sorting data using an OpenCL kernel

Chat: There are many sorting algorithms that can be used in OpenCL kernels. The most popular…

And instead of getting a proposal tailored to OpenCL, I got a **generic textbook answer** about algorithms not suited to concurrent programming.

ME: in my opinion that is the wrong answer, because it will be bitonic sort and radix sort, and possibly shift sort

Chat: Bitonic sort and radix sort are popular sorting algorithms used in OpenCL. Shift sort is less popular, but can be used in some situations. It all depends on the requirements and the requirements of the given application.

ME: so please write me an example OpenCL kernel for shift sort.

And I did get something that resembles shift sort, but **with a global barrier**.

```cpp
__kernel void shiftSort(__global float *inputArray, int arrayLength) {
    int globalId = get_global_id(0);
    int stride = 1;

    while (stride < arrayLength) {
        int index = globalId * stride * 2;

        if (index + stride < arrayLength) {
            if (inputArray[index] > inputArray[index + stride]) {
                float temp = inputArray[index];
                inputArray[index] = inputArray[index + stride];
                inputArray[index + stride] = temp;
            }
        }

        stride *= 2;
        barrier(CLK_GLOBAL_MEM_FENCE);
    }
}
```

ME: why did you put a barrier on global memory?

Chat: The global memory barrier is used in the above OpenCL kernel to ensure synchronisation between all threads. During shift sort, each thread sorts its part of the input data and at the same time depends on the sorting results of threads from other parts of the data. The global memory barrier guarantees that all threads finish sorting their data and are ready for the next sorting step before sorting continues. This ensures the correctness of the sorting result and avoids problems related to invalid memory access.

ME: but doesn’t the global barrier apply only to a single work group of N threads?

Chat: Yes, the global barrier works on a single work group and synchronises the threads in that group, but it does not affect other work groups in the same kernel. In OpenCL, global memory barriers are used to synchronise threads within a work group and prevent race conditions when many threads access and modify the same data.

## Conclusions

**And this is where my adventure with this program ended**, because any attempt to clarify anything resulted either in an error or in the same answers. To sum up the facts: we have a very capable tool here that has been fed an enormous amount of information – I can hardly even imagine the quantities involved. The knowledge of this mechanism ends in 2021 and it has no live connection to the internet. When asked whether it uses CUDA for its work, it answered in the affirmative.

Running the model this fast requires huge amounts of RAM and a very large number of compute cores to process the input and generate responses. It sounds like a **gigantic infrastructure based on a distributed system** and thousands of GPU cards processing the whole batch. The question is when it will become paid – once it starts answering well, or once people become addicted to it?
