현재, 파이썬에서 계산을 위해 GPU 가속을 활용하는 것은 쉽습니다. JSL만으로 이것을 달성할 수 있습니까?
전문가 여러분, 감사합니다!
64비트 win10
다음은 JMP 직원의 MZWald가 여러 코어 사용 및 GPU에 관해 토론한 항목에 대한 최근 답변입니다.
JMP의 일부 플랫폼은 단일 스레드만 사용하므로 스레드가 많아도 가치가 크게 증가하지 않지만, 단일 스레드가 더 빠른 빈도로 실행되면 가치가 증가합니다. JMP의 일부 플랫폼은 여러 스레드를 활용하므로 스레드/코어가 많으면 도움이 됩니다.
JMP Pro 18의 Torch 추가 기능을 사용하면 처음으로 GPU를 사용하여 이미지 분류와 딥러닝을 수행할 수 있으며, 이를 통해 CPU보다 훨씬 빠르게 해당 작업을 처리할 수 있습니다.
import pyopencl as cl
import pyopencl.array as cl_array
import numpy as np
import csv
import os
import time
# Select OpenCL platform and GPU device
platform = cl.get_platforms()[0] # Select the first platform (e.g., AMD)
device = platform.get_devices()[0] # Select the first GPU device (e.g., gfx804)
context = cl.Context([device])
queue = cl.CommandQueue(context)
# Define the GPU computation kernel (squares array elements)
kernel_code = """
__kernel void square(__global float *arr) {
int gid = get_global_id(0);
arr[gid] = arr[gid] * arr[gid];
}
"""
program = cl.Program(context, kernel_code).build()
# Create the CSV file path
csv_path = r"C:\0\results.csv" # Changed to a more common name
# Ensure the directory exists
os.makedirs(os.path.dirname(csv_path), exist_ok=True)
# Run 10,000 computation tasks
n = 10**6 # 1 million data points per computation
num_iterations = 10_000
# Pre-allocate arrays
host_array = np.empty(n, dtype=np.float32)
gpu_array = cl_array.empty(queue, host_array.shape, dtype=host_array.dtype)
# Store results
results = []
# Random number generator
rng = np.random.default_rng()
# Start timing
start_time = time.time()
for i in range(num_iterations):
# Generate random data and fill host_array
host_array[:] = rng.random(n, dtype=np.float32)
# Upload data to GPU
cl.enqueue_copy(queue, gpu_array.data, host_array)
# Compute on the GPU
program.square(queue, gpu_array.shape, None, gpu_array.data)
# Retrieve data from GPU
cl.enqueue_copy(queue, host_array, gpu_array.data)
# Record the first 5 results
results.append([i + 1] + host_array[:5].tolist())
# Progress display
if (i + 1) % 100 == 0:
print(f"Completed {i + 1}/{num_iterations} iterations...")
# Total time statistics
end_time = time.time()
total_time = end_time - start_time
print(f"Total time: {total_time:.2f} seconds")
print(f"Average time per iteration: {total_time / num_iterations:.6f} seconds")
# Write results to CSV in a single operation
with open(csv_path, "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["Iteration", "Result 1", "Result 2", "Result 3", "Result 4", "Result 5"]) # CSV header
writer.writerows(results)
print(f":white_heavy_check_mark:</img> Computation complete, results saved to {csv_path}")파이썬
JSL을 어떻게 할 수 있나요?
현재로서는 그럴 수 없습니다.
Python과 PyCUDA 또는 pyOpenCL을 사용하는 것은 JMP 스크립팅에서 GPU에 액세스하는 유일한 방법입니다. 이전 게시물 중 하나에서 보여준 것처럼 Python Execute()를 사용하여 Python에서 기능을 구현하는 사용자 정의 JSL 함수를 만들 수 있습니다. 이렇게 하면 Python에서 GPU 코드를 작성하면서도 스크립팅의 나머지 부분에 대한 JSL 인터페이스를 제공할 수 있습니다.