|
24 | 24 | #include <acl_support.h> |
25 | 25 | #include <acl_svm.h> |
26 | 26 | #include <acl_util.h> |
| 27 | +#include <acl_kernel.h> |
27 | 28 | #include <check_copy_overlap.h> |
28 | 29 |
|
29 | 30 | #ifdef __GNUC__ |
@@ -405,6 +406,122 @@ int acl_bind_buffer_to_device(cl_device_id device, cl_mem mem) { |
405 | 406 | return 1; |
406 | 407 | } |
407 | 408 |
|
| 409 | +ACL_EXPORT |
| 410 | +// CL_API_ENTRY cl_int clEnqueueReadGlobalVariableINTEL() { |
| 411 | +CL_API_ENTRY cl_int clEnqueueReadGlobalVariableINTEL( |
| 412 | + cl_command_queue command_queue, |
| 413 | + cl_program program, |
| 414 | + const char* name, |
| 415 | + cl_bool blocking_write, |
| 416 | + size_t size, |
| 417 | + size_t offset, |
| 418 | + void* ptr, |
| 419 | + cl_uint num_events_in_wait_list, |
| 420 | + const cl_event* event_wait_list, |
| 421 | + cl_event* event, |
| 422 | + const void* dev_global_ptr) { |
| 423 | + |
| 424 | + // TODO: get dev_global_ptr from autodiscovery instead later |
| 425 | + // return 0; |
| 426 | + return clEnqueueWriteGlobalVariableINTEL( |
| 427 | + command_queue, program, name, blocking_write, |
| 428 | + size, offset, ptr, num_events_in_wait_list, |
| 429 | + event_wait_list, event, dev_global_ptr); |
| 430 | +} |
| 431 | + |
| 432 | +ACL_EXPORT |
| 433 | +CL_API_ENTRY cl_int clEnqueueWriteGlobalVariableINTEL( |
| 434 | + cl_command_queue command_queue, |
| 435 | + cl_program program, |
| 436 | + const char* name, |
| 437 | + cl_bool blocking_write, |
| 438 | + size_t size, |
| 439 | + size_t offset, |
| 440 | + const void* ptr, |
| 441 | + cl_uint num_events_in_wait_list, |
| 442 | + const cl_event* event_wait_list, |
| 443 | + cl_event* event, |
| 444 | + const void* dev_global_ptr) { |
| 445 | + cl_int status; |
| 446 | + |
| 447 | + cl_kernel kernel = clCreateKernelIntelFPGA(program, name, &status); |
| 448 | + if (status != CL_SUCCESS) { |
| 449 | + return status; |
| 450 | + } |
| 451 | + |
| 452 | + // do we support ptr being a buffer instead of usm pointer? it seems to be the case on spec (only usm host pointer) |
| 453 | + // Given kernel arg must be a deivce usm pointer: When ptr is a host/shared usm pointer, this function is expected to copy it to device first? yes (currently discussing whether kernel arg accept host usm instead) |
| 454 | + void* src_dev_ptr = clDeviceMemAllocINTEL(command_queue->context, command_queue->device, NULL, size, 1, &status); |
| 455 | + if (status != CL_SUCCESS) { |
| 456 | + return status; |
| 457 | + } |
| 458 | + |
| 459 | + // This copy operation have to be blocking |
| 460 | + // cl_event to_dev_event = 0; |
| 461 | + status = clEnqueueMemcpyINTEL(command_queue, CL_TRUE, src_dev_ptr, ptr, size, 0, NULL, NULL); |
| 462 | + if (status != CL_SUCCESS) { |
| 463 | + return status; |
| 464 | + } |
| 465 | + // if (to_dev_event->execution_status != CL_COMPLETE) { |
| 466 | + // return CL_INVALID_OPERATION; |
| 467 | + // } |
| 468 | + |
| 469 | + status = clSetKernelArgMemPointerINTEL(kernel, 0, src_dev_ptr); |
| 470 | + if (status != CL_SUCCESS) { |
| 471 | + return status; |
| 472 | + } |
| 473 | + // should kernel header contain offset or not? no |
| 474 | + // offset is always byte offset? yes |
| 475 | + // Assuming below returns same thing as `clDeviceMemAllocINTEL`, where exactly is dev global ptr being read from? |
| 476 | + // What format is the read dev global, is it a pointer just like the return value of `clDeviceMemAllocINTEL` or is it something else? (its an unsigned value indicating address) |
| 477 | + // TODO: When passing dev global pointer directly to clSetKernelArgMemPointerINTEL, make sure REMOVE_VALID_CHECKS is defined. |
| 478 | + // Otherwise this ptr is not existing in context -> cause checks to fail |
| 479 | + // TODO: get dev_global_address from autodiscovery instead later |
| 480 | + // dev_addr_t dev_global_address = kernel->dev_bin->get_devdef().autodiscovery_def.? |
| 481 | + uintptr_t dev_global_address = 0x4000000; |
| 482 | + void* dev_global_ptr2 = (void*)(dev_global_address + offset * 8); // 1 unit of offset is 8 bits |
| 483 | + status = set_kernel_arg_mem_pointer_without_checks(kernel, 1, dev_global_ptr2); |
| 484 | + // status = clSetKernelArgMemPointerINTEL(kernel, 1, dev_global_ptr2); |
| 485 | + if (status != CL_SUCCESS) { |
| 486 | + return status; |
| 487 | + } |
| 488 | + status = clSetKernelArg(kernel, 2, sizeof(size_t), (const void *)(&size)); |
| 489 | + if (status != CL_SUCCESS) { |
| 490 | + return status; |
| 491 | + } |
| 492 | + |
| 493 | + status = clEnqueueTask(command_queue, kernel, num_events_in_wait_list, event_wait_list, event); |
| 494 | + if (status != CL_SUCCESS) { |
| 495 | + return status; |
| 496 | + } |
| 497 | + |
| 498 | + acl_lock(); |
| 499 | + // If nothing's blocking, then complete right away |
| 500 | + acl_idle_update(command_queue->context); |
| 501 | + acl_unlock(); |
| 502 | + |
| 503 | + if (blocking_write) { |
| 504 | + status = clWaitForEvents(1, event); |
| 505 | + } |
| 506 | + |
| 507 | + if (blocking_write && status == CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST) { |
| 508 | + return status; |
| 509 | + } |
| 510 | + |
| 511 | + // Free allocated device memory |
| 512 | + status = clMemFreeINTEL(command_queue->context, src_dev_ptr); |
| 513 | + if (status != CL_SUCCESS) { |
| 514 | + return status; |
| 515 | + } |
| 516 | + status = clReleaseKernel(kernel); |
| 517 | + if (status != CL_SUCCESS) { |
| 518 | + return status; |
| 519 | + } |
| 520 | + |
| 521 | + return CL_SUCCESS; |
| 522 | +} |
| 523 | + |
| 524 | + |
408 | 525 | ACL_EXPORT |
409 | 526 | CL_API_ENTRY cl_mem clCreateBufferWithPropertiesINTEL( |
410 | 527 | cl_context context, const cl_mem_properties_intel *properties, |
|
0 commit comments