From e91fc2ddaa74dd2c46ce93c9e92020d66c037c8e Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 24 Feb 2016 16:58:32 +0800 Subject: add CuContext/MContext --- nerv/lib/matrix/mmatrix.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'nerv/lib/matrix/mmatrix.c') diff --git a/nerv/lib/matrix/mmatrix.c b/nerv/lib/matrix/mmatrix.c index 3125ab6..f1cbc75 100644 --- a/nerv/lib/matrix/mmatrix.c +++ b/nerv/lib/matrix/mmatrix.c @@ -1,6 +1,8 @@ #define NERV_GENERIC_MMATRIX +#define MATRIX_CONTEXT MContext #include #include "../common.h" +#include "mmatrix.h" #define MATRIX_USE_FLOAT #define host_matrix_(NAME) host_matrix_float_##NAME @@ -10,9 +12,40 @@ #include "generic/elem_type.h" #include "generic/mmatrix.c" -Matrix *nerv_matrix_(perm_gen)(int ncol, Status *status) { +void nerv_host_context_print_profile(MContext *context) { + HashMap *profile = context->profile; + size_t i; + fprintf(stderr, "*** [nerv mmatrix profile] **\n"); + for (i = 0; i < profile->size; i++) + { + HashNode *ptr; + for (ptr = profile->bucket[i]; ptr; ptr = ptr->next) + { + fprintf(stderr, "%s:\t%.6f\n", ptr->key, *(float *)ptr->val); + } + } +} + +void nerv_host_context_clear_profile(MContext *context) { + nerv_hashmap_clear(context->profile); +} + +MContext *nerv_host_context_create(Status *status) { + MContext *context = (MContext *)malloc(sizeof(MContext)); + context->profile = nerv_hashmap_create(PROFILE_HASHMAP_SIZE, bkdr_hash, strcmp); + NERV_SET_STATUS(status, NERV_NORMAL, 0); + return context; +} + +void nerv_host_context_destroy(MContext *context, Status *status) { + nerv_hashmap_destroy(context->profile); + free(context); + NERV_SET_STATUS(status, NERV_NORMAL, 0); +} + +Matrix *nerv_matrix_(perm_gen)(int ncol, MContext *context, Status *status) { int i; - Matrix *self = nerv_matrix_(create)(1, ncol, status); + Matrix *self = nerv_matrix_(create)(1, ncol, context, status); if (status->err_code != NERV_NORMAL) return NULL; float *prow = MATRIX_ELEM_PTR_F(self); -- cgit v1.2.3