mirror of
https://github.com/vortexgpgpu/vortex.git
synced 2025-04-24 22:07:41 -04:00
position-independent kernel fix
This commit is contained in:
parent
2488e4736c
commit
15dc9afe93
20 changed files with 497 additions and 720 deletions
|
@ -6,7 +6,7 @@
|
|||
|
||||
void kernel_body(int task_id, kernel_arg_t* __UNIFORM__ arg) {
|
||||
int cid = vx_core_id();
|
||||
int* src_ptr = (int*)arg->src_addr;
|
||||
char* src_ptr = (char*)arg->src_addr;
|
||||
char value = 'A' + src_ptr[task_id];
|
||||
vx_printf("cid=%d: task=%d, value=%c\n", cid, task_id, value);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ const char* kernel_file = "kernel.bin";
|
|||
uint32_t count = 4;
|
||||
|
||||
vx_device_h device = nullptr;
|
||||
std::vector<uint8_t> staging_buf;
|
||||
uint64_t kernel_prog_addr;
|
||||
uint64_t kernel_args_addr;
|
||||
kernel_arg_t kernel_arg = {};
|
||||
|
@ -74,45 +73,46 @@ int main(int argc, char *argv[]) {
|
|||
std::cout << "open device connection" << std::endl;
|
||||
RT_CHECK(vx_dev_open(&device));
|
||||
|
||||
uint64_t num_warps, num_threads;
|
||||
uint64_t num_cores, num_warps, num_threads;
|
||||
RT_CHECK(vx_dev_caps(device, VX_CAPS_NUM_CORES, &num_cores));
|
||||
RT_CHECK(vx_dev_caps(device, VX_CAPS_NUM_WARPS, &num_warps));
|
||||
RT_CHECK(vx_dev_caps(device, VX_CAPS_NUM_THREADS, &num_threads));
|
||||
|
||||
uint32_t num_points = count;
|
||||
uint32_t buf_size = count * sizeof(int32_t);
|
||||
uint32_t num_tasks = num_cores * num_warps * num_threads;
|
||||
uint32_t num_points = count * num_tasks;
|
||||
uint32_t buf_size = num_points * sizeof(char);
|
||||
|
||||
std::cout << "number of points: " << count << std::endl;
|
||||
std::cout << "number of points: " << num_points << std::endl;
|
||||
std::cout << "buffer size: " << buf_size << " bytes" << std::endl;
|
||||
|
||||
// upload program
|
||||
std::cout << "upload program" << std::endl;
|
||||
RT_CHECK(vx_upload_kernel_file(device, kernel_file, &kernel_prog_addr));
|
||||
kernel_arg.num_points = num_points;
|
||||
|
||||
// allocate device memory
|
||||
std::cout << "allocate device memory" << std::endl;
|
||||
RT_CHECK(vx_mem_alloc(device, buf_size, &kernel_arg.src_addr));
|
||||
|
||||
kernel_arg.num_points = num_points;
|
||||
|
||||
std::cout << "dev_src=0x" << std::hex << kernel_arg.src_addr << std::endl;
|
||||
|
||||
// allocate staging buffer
|
||||
std::cout << "allocate staging buffer" << std::endl;
|
||||
staging_buf.resize(buf_size);
|
||||
// allocate host buffers
|
||||
std::cout << "allocate host buffers" << std::endl;
|
||||
std::vector<char> h_src(num_points);
|
||||
|
||||
// generate input data
|
||||
for (uint32_t i = 0; i < num_points; ++i) {
|
||||
h_src[i] = (char)i;
|
||||
}
|
||||
|
||||
// upload source buffer0
|
||||
std::cout << "upload source buffer" << std::endl;
|
||||
RT_CHECK(vx_copy_to_dev(device, kernel_arg.src_addr, h_src.data(), buf_size));
|
||||
|
||||
// upload program
|
||||
std::cout << "upload program" << std::endl;
|
||||
RT_CHECK(vx_upload_file(device, kernel_file, &kernel_prog_addr));
|
||||
|
||||
// upload kernel argument
|
||||
std::cout << "upload kernel argument" << std::endl;
|
||||
RT_CHECK(vx_upload_bytes(device, &kernel_arg, sizeof(kernel_arg_t), &kernel_args_addr));
|
||||
|
||||
// upload source buffer0
|
||||
{
|
||||
std::cout << "upload source buffer" << std::endl;
|
||||
auto buf_ptr = (int32_t*)staging_buf.data();
|
||||
for (uint32_t i = 0; i < num_points; ++i) {
|
||||
buf_ptr[i] = i;
|
||||
}
|
||||
RT_CHECK(vx_copy_to_dev(device, kernel_arg.src_addr, staging_buf.data(), buf_size));
|
||||
}
|
||||
|
||||
// start device
|
||||
std::cout << "start device" << std::endl;
|
||||
|
@ -122,8 +122,6 @@ int main(int argc, char *argv[]) {
|
|||
std::cout << "wait for completion" << std::endl;
|
||||
RT_CHECK(vx_ready_wait(device, VX_MAX_TIMEOUT));
|
||||
|
||||
return 0;
|
||||
|
||||
// cleanup
|
||||
std::cout << "cleanup" << std::endl;
|
||||
cleanup();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue