From 15600335cd5e6ac36952b071913cfb9934b63cd4 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 26 Apr 2017 15:05:07 -0600 Subject: [PATCH] gpu: kill a lot of useless ifdefs We just have to guard how we set the mem type, we don't have to guard any check for MEM_CUDA_MALLOC inside CONFIG_CUDA ifdefs. Additionally, fix up some bad style. Fixes: 03553853 ("GPUDirect RDMA support") Signed-off-by: Jens Axboe --- init.c | 3 +++ io_u.c | 9 ++------- memory.c | 15 +++++++-------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/init.c b/init.c index 9aa452da..52a5f030 100644 --- a/init.c +++ b/init.c @@ -1070,6 +1070,9 @@ static void init_flags(struct thread_data *td) if (o->verify_async || o->io_submit_mode == IO_MODE_OFFLOAD) td->flags |= TD_F_NEED_LOCK; + + if (o->mem_type == MEM_CUDA_MALLOC) + td->flags &= ~TD_F_SCRAMBLE_BUFFERS; } static int setup_random_seeds(struct thread_data *td) diff --git a/io_u.c b/io_u.c index 39d68d1f..fd631198 100644 --- a/io_u.c +++ b/io_u.c @@ -1654,10 +1654,6 @@ struct io_u *get_io_u(struct thread_data *td) populate_verify_io_u(td, io_u); do_scramble = 0; } -#ifdef CONFIG_CUDA - if (td->o.mem_type == MEM_CUDA_MALLOC) - do_scramble = 0; -#endif } else if (io_u->ddir == DDIR_READ) { /* * Reset the buf_filled parameters so next time if the @@ -2049,9 +2045,8 @@ void fill_io_buffer(struct thread_data *td, void *buf, unsigned int min_write, { struct thread_options *o = &td->o; -#ifdef CONFIG_CUDA - if (o->mem_type == MEM_CUDA_MALLOC) return; -#endif + if (o->mem_type == MEM_CUDA_MALLOC) + return; if (o->compress_percentage || o->dedupe_percentage) { unsigned int perc = td->o.compress_percentage; diff --git a/memory.c b/memory.c index fe657225..22a7f5dd 100644 --- a/memory.c +++ b/memory.c @@ -207,10 +207,9 @@ static void free_mem_malloc(struct thread_data *td) free(td->orig_buffer); } -#ifdef CONFIG_CUDA - static int alloc_mem_cudamalloc(struct thread_data *td, size_t total_mem) { +#ifdef CONFIG_CUDA CUresult ret; char name[128]; @@ -264,17 +263,21 @@ static int alloc_mem_cudamalloc(struct thread_data *td, size_t total_mem) dprint(FD_MEM, "cudaMalloc %llu %p\n", \ (unsigned long long) total_mem, td->orig_buffer); return 0; +#else + return -EINVAL; +#endif } static void free_mem_cudamalloc(struct thread_data *td) { - if ((void *) td->dev_mem_ptr != NULL) +#ifdef CONFIG_CUDA + if (td->dev_mem_ptr != NULL) cuMemFree(td->dev_mem_ptr); if (cuCtxDestroy(td->cu_ctx) != CUDA_SUCCESS) log_err("fio: failed to destroy cuda context\n"); -} #endif +} /* * Set up the buffer area we need for io. @@ -315,10 +318,8 @@ int allocate_io_mem(struct thread_data *td) else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAPSHARED) ret = alloc_mem_mmap(td, total_mem); -#ifdef CONFIG_CUDA else if (td->o.mem_type == MEM_CUDA_MALLOC) ret = alloc_mem_cudamalloc(td, total_mem); -#endif else { log_err("fio: bad mem type: %d\n", td->o.mem_type); ret = 1; @@ -348,10 +349,8 @@ void free_io_mem(struct thread_data *td) else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAPSHARED) free_mem_mmap(td, total_mem); -#ifdef CONFIG_CUDA else if (td->o.mem_type == MEM_CUDA_MALLOC) free_mem_cudamalloc(td); -#endif else log_err("Bad memory type %u\n", td->o.mem_type); -- 2.25.1