forked from halide/Halide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request halide#376 from halide/gpu_device_selection
Gpu device selection
- Loading branch information
Showing
8 changed files
with
137 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Runtime settings for opencl and cuda device selection | ||
#include "HalideRuntime.h" | ||
#include "scoped_spin_lock.h" | ||
|
||
extern "C" { | ||
|
||
extern char *strncpy(char *dst, const char *src, size_t n); | ||
extern int atoi(const char *); | ||
extern char *getenv(const char *); | ||
|
||
WEAK char halide_ocl_platform_name[256]; | ||
WEAK int halide_ocl_platform_name_lock = 0; | ||
WEAK bool halide_ocl_platform_name_initialized = false; | ||
WEAK void halide_set_ocl_platform_name(const char *n) { | ||
if (n) { | ||
strncpy(halide_ocl_platform_name, n, 255); | ||
} else { | ||
halide_ocl_platform_name[0] = 0; | ||
} | ||
halide_ocl_platform_name_initialized = true; | ||
} | ||
|
||
WEAK const char *halide_get_ocl_platform_name(void *user_context) { | ||
ScopedSpinLock lock(&halide_ocl_platform_name_lock); | ||
if (!halide_ocl_platform_name_initialized) { | ||
const char *name = getenv("HL_OCL_PLATFORM_NAME"); | ||
halide_set_ocl_platform_name(name); | ||
} | ||
return halide_ocl_platform_name; | ||
} | ||
|
||
WEAK char halide_ocl_device_type[256]; | ||
WEAK int halide_ocl_device_type_lock = 0; | ||
WEAK bool halide_ocl_device_type_initialized = false; | ||
WEAK void halide_set_ocl_device_type(const char *n) { | ||
if (n) { | ||
strncpy(halide_ocl_device_type, n, 255); | ||
} else { | ||
halide_ocl_device_type[0] = 0; | ||
} | ||
halide_ocl_device_type_initialized = true; | ||
} | ||
|
||
WEAK const char *halide_get_ocl_device_type(void *user_context) { | ||
ScopedSpinLock lock(&halide_ocl_device_type_lock); | ||
if (!halide_ocl_device_type_initialized) { | ||
const char *name = getenv("HL_OCL_DEVICE_TYPE"); | ||
halide_set_ocl_device_type(name); | ||
} | ||
return halide_ocl_device_type; | ||
} | ||
|
||
WEAK int halide_gpu_device = 0; | ||
WEAK int halide_gpu_device_lock = 0; | ||
WEAK bool halide_gpu_device_initialized = false; | ||
WEAK void halide_set_gpu_device(int d) { | ||
halide_gpu_device = d; | ||
halide_gpu_device_initialized = true; | ||
} | ||
WEAK int halide_get_gpu_device(void *user_context) { | ||
ScopedSpinLock lock(&halide_gpu_device_lock); | ||
if (!halide_gpu_device_initialized) { | ||
const char *var = getenv("HL_GPU_DEVICE"); | ||
if (var) { | ||
halide_gpu_device = atoi(var); | ||
} else { | ||
halide_gpu_device = -1; | ||
} | ||
halide_gpu_device_initialized = true; | ||
} | ||
return halide_gpu_device; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters