+ rte_free(ptr);
+
+ printf("\n=======> TEST: PASSED\n");
+ return 0;
+
+error:
+
+ rte_gpu_mem_unregister(gpu_id, ptr);
+ rte_free(ptr);
+ printf("\n=======> TEST: FAILED\n");
+ return -1;
+}
+
+static int
+gpu_mem_cpu_map(uint16_t gpu_id)
+{
+ void *ptr_gpu = NULL;
+ void *ptr_cpu = NULL;
+ size_t buf_bytes = 1024;
+ unsigned int align = 4096;
+ int ret;
+
+ printf("\n=======> TEST: Map GPU memory for CPU visibility\n\n");
+
+ /* Alloc memory on GPU 0 with 4kB alignment */
+ ptr_gpu = rte_gpu_mem_alloc(gpu_id, buf_bytes, align);
+ if (ptr_gpu == NULL) {
+ fprintf(stderr, "rte_gpu_mem_alloc GPU memory returned error\n");
+ goto error;
+ }
+ printf("GPU memory allocated at 0x%p size is %zd bytes\n",
+ ptr_gpu, buf_bytes);
+
+ ptr_cpu = rte_gpu_mem_cpu_map(gpu_id, buf_bytes, ptr_gpu);
+ if (ptr_cpu == NULL) {
+ fprintf(stderr, "rte_gpu_mem_cpu_map returned error\n");
+ goto error;
+ }
+ printf("GPU memory CPU mapped at 0x%p\n", ptr_cpu);
+
+ ((uint8_t *)ptr_cpu)[0] = 0x4;
+ ((uint8_t *)ptr_cpu)[1] = 0x5;
+ ((uint8_t *)ptr_cpu)[2] = 0x6;
+
+ printf("GPU memory first 3 bytes set from CPU: %x %x %x\n",
+ ((uint8_t *)ptr_cpu)[0],
+ ((uint8_t *)ptr_cpu)[1],
+ ((uint8_t *)ptr_cpu)[2]);
+
+ ret = rte_gpu_mem_cpu_unmap(gpu_id, ptr_gpu);
+ if (ret < 0) {
+ fprintf(stderr, "rte_gpu_mem_cpu_unmap returned error %d\n", ret);
+ goto error;
+ }
+ printf("GPU memory CPU unmapped, 0x%p not valid anymore\n", ptr_cpu);
+
+ ret = rte_gpu_mem_free(gpu_id, ptr_gpu);
+ if (ret < 0) {
+ fprintf(stderr, "rte_gpu_mem_free returned error %d\n", ret);
+ goto error;
+ }
+ printf("GPU memory 0x%p freed\n", ptr_gpu);
+
+ printf("\n=======> TEST: PASSED\n");
+ return 0;
+
+error:
+
+ rte_gpu_mem_cpu_unmap(gpu_id, ptr_gpu);
+ rte_gpu_mem_free(gpu_id, ptr_gpu);
+
+ printf("\n=======> TEST: FAILED\n");
+ return -1;
+}
+
+static int
+create_update_comm_flag(uint16_t gpu_id)
+{
+ struct rte_gpu_comm_flag devflag;
+ int ret = 0;
+ uint32_t set_val;
+ uint32_t get_val;
+
+ printf("\n=======> TEST: Communication flag\n\n");
+
+ ret = rte_gpu_comm_create_flag(gpu_id, &devflag, RTE_GPU_COMM_FLAG_CPU);
+ if (ret < 0) {
+ fprintf(stderr, "rte_gpu_comm_create_flag returned error %d\n", ret);
+ goto error;
+ }
+
+ set_val = 25;
+ ret = rte_gpu_comm_set_flag(&devflag, set_val);
+ if (ret < 0) {
+ fprintf(stderr, "rte_gpu_comm_set_flag returned error %d\n", ret);
+ goto error;
+ }
+
+ ret = rte_gpu_comm_get_flag_value(&devflag, &get_val);
+ if (ret < 0) {
+ fprintf(stderr, "rte_gpu_comm_get_flag_value returned error %d\n", ret);
+ goto error;
+ }
+
+ printf("Communication flag value at 0x%p was set to %d and current value is %d\n",
+ devflag.ptr, set_val, get_val);
+
+ set_val = 38;
+ ret = rte_gpu_comm_set_flag(&devflag, set_val);
+ if (ret < 0) {
+ fprintf(stderr, "rte_gpu_comm_set_flag returned error %d\n", ret);
+ goto error;
+ }
+
+ ret = rte_gpu_comm_get_flag_value(&devflag, &get_val);
+ if (ret < 0) {
+ fprintf(stderr, "rte_gpu_comm_get_flag_value returned error %d\n", ret);
+ goto error;
+ }
+
+ printf("Communication flag value at 0x%p was set to %d and current value is %d\n",
+ devflag.ptr, set_val, get_val);
+
+ ret = rte_gpu_comm_destroy_flag(&devflag);
+ if (ret < 0) {
+ fprintf(stderr, "rte_gpu_comm_destroy_flags returned error %d\n", ret);
+ goto error;
+ }
+
+ printf("\n=======> TEST: PASSED\n");